提供: Minecraft Modding Wiki
この編集を取り消せます。
下記の差分を確認して、本当に取り消していいか検証してください。よろしければ変更を保存して取り消しを完了してください。
最新版 | 編集中の文章 | ||
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 dan200.computercraft.api.ComputerCraftAPI; | import dan200.computercraft.api.ComputerCraftAPI; | ||
40行目: | 39行目: | ||
@EventHandler | @EventHandler | ||
− | public void | + | public void init(FMLInitializationEvent event) { |
// Turtle Upgradeの登録 | // Turtle Upgradeの登録 | ||
ComputerCraftAPI.registerTurtleUpgrade(new TurtleSample()); | ComputerCraftAPI.registerTurtleUpgrade(new TurtleSample()); | ||
− | |||
− | + | if (event.getSide().isClient()) { // クライアント限定の処理 | |
− | |||
− | |||
− | 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 com.google.common.base.Function; | import com.google.common.base.Function; | ||
− | |||
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 | + | private ResourceLocation upgradeID = new ResourceLocation(SampleUpgradeCore.MOD_ID, "sample"); |
// Turtle Upgradeの装着に必要なアイテム。ここではバニラブロックの石(焼石) | // Turtle Upgradeの装着に必要なアイテム。ここではバニラブロックの石(焼石) | ||
− | private | + | 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; | ||
− | // | + | // 前もって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行目: | ||
} | } | ||
− | |||
− | |||
@Override | @Override | ||
public ResourceLocation getUpgradeID() { | public ResourceLocation getUpgradeID() { | ||
+ | // Turtle UpgradeのIDをResourceLocationで指定 | ||
+ | // 他のTurtle Upgradeと重複しないようにする | ||
return upgradeID; | return upgradeID; | ||
} | } | ||
− | |||
− | |||
@Override | @Override | ||
public int getLegacyUpgradeID() { | public int getLegacyUpgradeID() { | ||
+ | // Minecraft 1.7.10やそれ以前のワールドからTurtle Upgradeを引き継ぐ場合は、そのTurtle Upgradeと同じIDを返す | ||
+ | // 引き継ぐ必要がない場合は-1を返す | ||
return -1; | return -1; | ||
} | } | ||
− | |||
− | |||
@Override | @Override | ||
public String getUnlocalisedAdjective() { | public String getUnlocalisedAdjective() { | ||
− | return " | + | // Turtle Upgradeを装着したTurtleのアイテム名に付加される形容詞を返す |
+ | // この例では"Sample Turtle"になる | ||
+ | return "Sample"; | ||
} | } | ||
− | |||
@Override | @Override | ||
public TurtleUpgradeType getType() { | public TurtleUpgradeType getType() { | ||
+ | // Turtle Upgradeの種類の指定 | ||
// 周辺機器タイプを指定 | // 周辺機器タイプを指定 | ||
return TurtleUpgradeType.Peripheral; | return TurtleUpgradeType.Peripheral; | ||
} | } | ||
− | |||
@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); | ||
} | } | ||
− | |||
@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; | ||
} | } | ||
− | |||
− | |||
− | |||
@Override | @Override | ||
@SideOnly(Side.CLIENT) | @SideOnly(Side.CLIENT) | ||
244行目: | 231行目: | ||
} | } | ||
− | |||
@Override | @Override | ||
public void update(ITurtleAccess turtle, TurtleSide side) { | public void update(ITurtleAccess turtle, TurtleSide side) { | ||
− | // | + | // Tick毎の処理 |
− | |||
− | |||
} | } | ||
260行目: | 244行目: | ||
package mods.sample.upgrade; | package mods.sample.upgrade; | ||
− | |||
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行目: | ||
} | } | ||
− | |||
@Override | @Override | ||
public void attach(IComputerAccess computer) { | public void attach(IComputerAccess computer) { | ||
− | + | // 装着された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を返している | ||
if ((other != null) && (other instanceof SamplePeripheral)) { | if ((other != null) && (other instanceof SamplePeripheral)) { | ||
− | + | SamplePeripheral other1 = (SamplePeripheral)other; | |
− | + | return (other1.turtleAccess == this.turtleAccess) && (other1.turtleSide == this.turtleSide); | |
− | |||
} | } | ||
329行目: | 309行目: | ||
} | } | ||
</source> | </source> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==== 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などの適当なテクスチャファイルを各自で用意してください。 |