提供: Minecraft Modding Wiki
移動先: 案内検索

警告: ログインしていません。編集を行うと、あなたの IP アドレスが公開されます。ログインまたはアカウントを作成すれば、あなたの編集はその利用者名とともに表示されるほか、その他の利点もあります。

この編集を取り消せます。 下記の差分を確認して、本当に取り消していいか検証してください。よろしければ変更を保存して取り消しを完了してください。
最新版 編集中の文章
23行目: 23行目:
 
import net.minecraftforge.fml.common.Mod.EventHandler;
 
import net.minecraftforge.fml.common.Mod.EventHandler;
 
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
 
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
 
 
import dan200.computercraft.api.ComputerCraftAPI;
 
import dan200.computercraft.api.ComputerCraftAPI;
  
40行目: 39行目:
  
 
@EventHandler
 
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
+
public void init(FMLInitializationEvent event) {
 
// Turtle Upgradeの登録
 
// Turtle Upgradeの登録
 
ComputerCraftAPI.registerTurtleUpgrade(new TurtleSample());
 
ComputerCraftAPI.registerTurtleUpgrade(new TurtleSample());
}
 
  
@EventHandler
+
if (event.getSide().isClient()) { // クライアント限定の処理
public void init(FMLInitializationEvent event) {
 
// クライアント限定の処理
 
if (event.getSide().isClient()) {
 
 
// クライアントイベント受信クラスの登録
 
// クライアントイベント受信クラスの登録
 
MinecraftForge.EVENT_BUS.register(new ClientEventHandler());
 
MinecraftForge.EVENT_BUS.register(new ClientEventHandler());
76行目: 71行目:
 
import net.minecraftforge.client.model.IModel;
 
import net.minecraftforge.client.model.IModel;
 
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
 
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
 
import net.minecraftforge.fml.relauncher.SideOnly;
 
  
 
import com.google.common.base.Function;
 
import com.google.common.base.Function;
  
@SideOnly(Side.CLIENT)
 
 
public class ClientEventHandler {
 
public class ClientEventHandler {
  
92行目: 84行目:
 
@SubscribeEvent
 
@SubscribeEvent
 
public void onModelBakeEvent(ModelBakeEvent event) {
 
public void onModelBakeEvent(ModelBakeEvent event) {
// 使用するモデルの場所
 
 
ResourceLocation modelLeft  = new ResourceLocation(SampleUpgradeCore.MOD_ID, "block/turtle_sample_left");
 
ResourceLocation modelLeft  = new ResourceLocation(SampleUpgradeCore.MOD_ID, "block/turtle_sample_left");
 
ResourceLocation modelRight = new ResourceLocation(SampleUpgradeCore.MOD_ID, "block/turtle_sample_right");
 
ResourceLocation modelRight = new ResourceLocation(SampleUpgradeCore.MOD_ID, "block/turtle_sample_right");
158行目: 149行目:
  
 
// Turtle UpgradeのID
 
// Turtle UpgradeのID
private final ResourceLocation upgradeID = new ResourceLocation(SampleUpgradeCore.MOD_ID, "sample_peripheral");
+
private ResourceLocation upgradeID = new ResourceLocation(SampleUpgradeCore.MOD_ID, "sample");
 
// Turtle Upgradeの装着に必要なアイテム。ここではバニラブロックの石(焼石)
 
// Turtle Upgradeの装着に必要なアイテム。ここではバニラブロックの石(焼石)
private final ItemStack upgradeItem = new ItemStack(Blocks.stone);
+
private ItemStack upgradeItem = new ItemStack(Blocks.stone);
  
 
// Turtle UpgradeのモデルのModelResourceLocation.クライアント側でのみ参照される
 
// Turtle UpgradeのモデルのModelResourceLocation.クライアント側でのみ参照される
169行目: 160行目:
  
 
public TurtleSample() {
 
public TurtleSample() {
// クライアント限定の処理
+
if (FMLCommonHandler.instance().getSide().isClient()) { // クライアント限定の処理
if (FMLCommonHandler.instance().getSide().isClient()) {
 
 
String modid = SampleUpgradeCore.MOD_ID;
 
String modid = SampleUpgradeCore.MOD_ID;
// 登録済みモデルのModelResourceLocationを前もってコンストラクタで定義しておく
+
// 前もってgetModelで使用するモデルのModelResourceLocationを用意
 
modelLeft  = new ModelResourceLocation(new ResourceLocation(modid, "block/turtle_sample_left"), "inventory");
 
modelLeft  = new ModelResourceLocation(new ResourceLocation(modid, "block/turtle_sample_left"), "inventory");
 
modelRight = new ModelResourceLocation(new ResourceLocation(modid, "block/turtle_sample_right"), "inventory");
 
modelRight = new ModelResourceLocation(new ResourceLocation(modid, "block/turtle_sample_right"), "inventory");
178行目: 168行目:
 
}
 
}
  
// Turtle UpgradeのIDをResourceLocationで指定
 
// 他のTurtle Upgradeと重複しないようにする
 
 
@Override
 
@Override
 
public ResourceLocation getUpgradeID() {
 
public ResourceLocation getUpgradeID() {
 +
// Turtle UpgradeのIDをResourceLocationで指定
 +
// 他のTurtle Upgradeと重複しないようにする
 
return upgradeID;
 
return upgradeID;
 
}
 
}
  
// Minecraft 1.7.10やそれ以前のワールドからTurtle Upgradeを引き継ぐ場合は、そのTurtle Upgradeと同じIDを返す
 
// 引き継ぐ必要がない場合は-1を返す
 
 
@Override
 
@Override
 
public int getLegacyUpgradeID() {
 
public int getLegacyUpgradeID() {
 +
// Minecraft 1.7.10やそれ以前のワールドからTurtle Upgradeを引き継ぐ場合は、そのTurtle Upgradeと同じIDを返す
 +
// 引き継ぐ必要がない場合は-1を返す
 
return -1;
 
return -1;
 
}
 
}
  
// 装着したTurtleのアイテム名に付加される形容詞を返す(『○○ Turtle』の○○の部分)
 
// 戻り値は(設定されていれば)langファイルによる翻訳を経てゲーム内に表示される
 
 
@Override
 
@Override
 
public String getUnlocalisedAdjective() {
 
public String getUnlocalisedAdjective() {
return "turtle.sample_peripheral.adjective";
+
// Turtle Upgradeを装着したTurtleのアイテム名に付加される形容詞を返す
 +
// この例では"Sample Turtle"になる
 +
return "Sample";
 
}
 
}
  
// Turtle Upgradeの種類の指定
 
 
@Override
 
@Override
 
public TurtleUpgradeType getType() {
 
public TurtleUpgradeType getType() {
 +
// Turtle Upgradeの種類の指定
 
// 周辺機器タイプを指定
 
// 周辺機器タイプを指定
 
return TurtleUpgradeType.Peripheral;
 
return TurtleUpgradeType.Peripheral;
 
}
 
}
  
// Turtle Upgradeの装着に必要なアイテムを返す
 
 
@Override
 
@Override
 
public ItemStack getCraftingItem() {
 
public ItemStack getCraftingItem() {
 +
// Turtle Upgradeの装着に必要なアイテムを返す
 
return upgradeItem;
 
return upgradeItem;
 
}
 
}
  
// 周辺機器クラスのインスタンスを生成して返す
 
 
@Override
 
@Override
 
public IPeripheral createPeripheral(ITurtleAccess turtle, TurtleSide side) {
 
public IPeripheral createPeripheral(ITurtleAccess turtle, TurtleSide side) {
 +
// 周辺機器クラスのインスタンスを生成して返す
 
return new SamplePeripheral(turtle, side);
 
return new SamplePeripheral(turtle, side);
 
}
 
}
  
// ツールタイプTurtle Upgradeの処理
 
 
@Override
 
@Override
 
public TurtleCommandResult useTool(ITurtleAccess turtle, TurtleSide side,
 
public TurtleCommandResult useTool(ITurtleAccess turtle, TurtleSide side,
 
TurtleVerb verb, EnumFacing direction) {
 
TurtleVerb verb, EnumFacing direction) {
 +
// ツールタイプTurtle Upgradeの処理
 
// 周辺機器タイプでは何もしない
 
// 周辺機器タイプでは何もしない
 
return null;
 
return null;
 
}
 
}
  
// Turtle Upgradeのモデルと変形行列のペアを返す
 
// Turtle Upgradeの外見を描画するためクライアント側で毎描画フレーム呼び出される
 
// そのため、Wireless Turtleのような「Turtle Upgradeや周辺機器の状態による描画モデルの変更」も可能
 
 
@Override
 
@Override
 
@SideOnly(Side.CLIENT)
 
@SideOnly(Side.CLIENT)
244行目: 231行目:
 
}
 
}
  
// Tick毎の処理
 
 
@Override
 
@Override
 
public void update(ITurtleAccess turtle, TurtleSide side) {
 
public void update(ITurtleAccess turtle, TurtleSide side) {
// 毎tickこのクラスで定義したTurtle Upgradeの装着数×2(Server側とClient側の分)回呼び出される
+
// Tick毎の処理
// どのTurtle Upgradeに対するupdateなのかはパラメータのturtleとsideで判別可能
 
// またServerとClientのどちら側の呼び出しなのかはturtle.getWorld().isRemoteの値で判別可能
 
 
}
 
}
  
260行目: 244行目:
 
package mods.sample.upgrade;
 
package mods.sample.upgrade;
  
import net.minecraft.util.BlockPos;
 
 
import dan200.computercraft.api.lua.ILuaContext;
 
import dan200.computercraft.api.lua.ILuaContext;
 
import dan200.computercraft.api.lua.LuaException;
 
import dan200.computercraft.api.lua.LuaException;
302行目: 285行目:
 
}
 
}
  
// 装着されたTurtleが起動したとき、またはコマンドでTurtleに装着されたときに呼び出される
 
 
@Override
 
@Override
 
public void attach(IComputerAccess computer) {
 
public void attach(IComputerAccess computer) {
 
+
// 装着されたTurtleが起動したとき、またはコマンドでTurtleに装着されたときに呼び出される
 
}
 
}
  
// 装着されたTurtleが終了したとき、またはコマンドでTurtleから取り外されたときに呼び出される
 
 
@Override
 
@Override
 
public void detach(IComputerAccess computer) {
 
public void detach(IComputerAccess computer) {
 
+
// 装着されたTurtleが終了したとき、またはコマンドでTurtleから取り外されたときに呼び出される
 
}
 
}
  
// 周辺機器が同一のものであるかを比較して返す
 
 
@Override
 
@Override
 
public boolean equals(IPeripheral other) {
 
public boolean equals(IPeripheral other) {
// ここでは、このクラスのインスタンスで同一座標のTurtleの同一方向に装着されている場合にのみtrueを返す
+
// 周辺機器が同一のものであるかを返す
 +
// サンプルでは、このクラスのインスタンスで同一Turtleの同一方向に装着されている場合にのみtrueを返している
 
if ((other != null) && (other instanceof SamplePeripheral)) {
 
if ((other != null) && (other instanceof SamplePeripheral)) {
BlockPos otherPos = ((SamplePeripheral)other).turtleAccess.getPosition();
+
SamplePeripheral other1 = (SamplePeripheral)other;
TurtleSide otherSide = ((SamplePeripheral)other).turtleSide;
+
return (other1.turtleAccess == this.turtleAccess) && (other1.turtleSide == this.turtleSide);
return this.turtleAccess.getPosition().equals(otherPos) && (this.turtleSide == otherSide);
 
 
}
 
}
  
329行目: 309行目:
 
}
 
}
 
</source>
 
</source>
 
==== en_US.lang ====
 
アメリカ英語(デフォルト言語)のlangファイル<br />
 
assets\sampleupgrademod\lang ディレクトリに設置します。
 
<source lang="ini">
 
 
turtle.sample_peripheral.adjective=Sample
 
</source>
 
 
 
=== モデル・テクスチャ ===
 
今回、モデルの形状についてはComputerCraft本体で定義されているものを流用し、テクスチャのみオリジナルなものを使用しています。<br />
 
モデルを定義するJSONの仕様については「[[1.8のバニラJsonの仕様]]」や「[[1.8のブロック追加]]」を参照してください。
 
  
 
==== turtle_sample_left.json ====
 
==== turtle_sample_left.json ====
354行目: 321行目:
 
}
 
}
 
</source>
 
</source>
 +
※今回はComputerCraft本体で定義されている物を流用しています。
  
 
==== turtle_sample_right.json ====
 
==== turtle_sample_right.json ====
366行目: 334行目:
 
}
 
}
 
</source>
 
</source>
 +
※今回はComputerCraft本体で定義されている物を流用しています。
  
 
==== sample_upgrade.png ====
 
==== sample_upgrade.png ====
371行目: 340行目:
 
assets\sampleupgrademod\textures\blocks ディレクトリに設置します。
 
assets\sampleupgrademod\textures\blocks ディレクトリに設置します。
  
※サイズ16x16などの適当なテクスチャ画像を各自で用意してください。
+
※サイズ16x16などの適当なテクスチャファイルを各自で用意してください。

Minecraft Modding Wikiへの投稿はすべて、他の投稿者によって編集、変更、除去される場合があります。 自分が書いたものが他の人に容赦なく編集されるのを望まない場合は、ここに投稿しないでください。
また、投稿するのは、自分で書いたものか、パブリック ドメインまたはそれに類するフリーな資料からの複製であることを約束してください(詳細はMinecraft Modding Wiki:著作権を参照)。 著作権保護されている作品は、許諾なしに投稿しないでください!

このページを編集するには、下記の確認用の質問に回答してください (詳細):

取り消し 編集の仕方 (新しいウィンドウで開きます)

このページで使用されているテンプレート: