提供: Minecraft Modding Wiki
1.6のモデル付きカスタムツール追加
このアイテムは、(つるはし)(ショベル)(斧)の三つ(鉄製)にモデルを付けて追加するものです。
ソース
- CustomModelTools.java
package custom.tool.item; import net.minecraft.item.EnumToolMaterial; import net.minecraft.item.Item; import net.minecraft.item.ItemTool; import net.minecraftforge.client.IItemRenderer; import net.minecraftforge.client.MinecraftForgeClient; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.registry.LanguageRegistry; @Mod( modid = "CustomModelTools", name = "Custom Model Tools", version = "1" ) @NetworkMod( clientSideRequired = CustomModelTools.clientSideRequiredBoolean, serverSideRequired = CustomModelTools.serverSideRequiredBoolean ) public class CustomModelTools { public static final boolean clientSideRequiredBoolean = true; public static final boolean serverSideRequiredBoolean = false; public static boolean Model_ON_OFF_Boolean = true; public static String ModelTexture; public static String texture; public static EnumToolMaterial toolMaterial; public static ItemTool mainItem; @EventHandler public void mainLoading(FMLPreInitializationEvent event) { mainItem = (ItemTool) new ItemCustomModelTools(3001, toolMaterial.IRON).setData("CustomModelItem", "CustomModelItem", 1.0F); registerItem(mainItem, "CustomModelItem", "Custom Model Item", "カスタムモデルアイテム", new ItemCustomModelToolsRenderer(), true, texture, 64, 32); } public void registerItem(Item items, String name, String en_US, String ja_JP, IItemRenderer itemRenderer, boolean modeling, String texture, int width, int height) { GameRegistry.registerItem(items, name); LanguageRegistry.instance().addNameForObject(items, "en_US", en_US); LanguageRegistry.instance().addNameForObject(items, "ja_JP", ja_JP); MinecraftForgeClient.registerItemRenderer(items.itemID, itemRenderer); Model_ON_OFF_Boolean = modeling; ModelTexture = texture; ModelCustomModelTools modelings = new ModelCustomModelTools(); modelings.setTextureSize(width, height); } }
- ItemCustomModelTools.java
package custom.tool.item; import net.minecraft.item.Item; import net.minecraft.item.ItemTool; import net.minecraft.item.ItemStack; import net.minecraft.item.EnumToolMaterial; import net.minecraft.block.Block; import net.minecraft.block.material.Material; public class ItemCustomModelTools extends ItemTool { //壊せるブロックのリスト private static final Block[] setBleakingList = new Block[] {// ItemSpade.java Block.grass, Block.dirt, Block.sand, Block.gravel, Block.snow, Block.blockSnow, Block.blockClay, Block.tilledField, Block.slowSand, Block.mycelium, // ItemPickaxe.java Block.cobblestone, Block.stoneDoubleSlab, Block.stoneSingleSlab, Block.stone, Block.sandStone, Block.cobblestoneMossy, Block.oreIron, Block.blockIron, Block.oreCoal, Block.blockGold, Block.oreGold, Block.oreDiamond, Block.blockDiamond, Block.ice, Block.netherrack, Block.oreLapis, Block.blockLapis, Block.oreRedstone, Block.oreRedstoneGlowing, Block.rail, Block.railDetector, Block.railPowered, Block.railActivator, // ItemAxe.java Block.planks, Block.bookShelf, Block.wood, Block.chest, Block.stoneDoubleSlab, Block.stoneSingleSlab, Block.pumpkin, Block.pumpkinLantern}; // 詳しい情報は、ItemSpade.java ItemPickaxe.java ItemAxe.javaを参照 public static float damageFloat = 1.0F; public ItemCustomModelTools(int par1ID, EnumToolMaterial par2EnumToolMaterial) { super(par1ID, damageFloat, par2EnumToolMaterial, setBleakingList); } @Override public boolean canHarvestBlock(Block par1Block) { return setBleakingList != null; } @Override public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block) { return par2Block != null && (par2Block.blockMaterial == Material.iron || //マテリアル属性 鉄 par2Block.blockMaterial == Material.anvil || //マテリアル属性 金床 par2Block.blockMaterial == Material.rock || //マテリアル属性 石 par2Block.blockMaterial == Material.wood || //マテリアル属性 原木 par2Block.blockMaterial == Material.plants || //マテリアル属性 木の厚板 par2Block.blockMaterial == Material.vine) ? //マテリアル属性 つる this.efficiencyOnProperMaterial : super.getStrVsBlock(par1ItemStack, par2Block); } public Item setData(String domain, String path, float damage) { setUnlocalizedName(path); iconString = domain + ":" + path; damageFloat = damage; return this; } }
- ItemCustomModelToolsRenderer.java
package custom.tool.item; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.IItemRenderer; import org.lwjgl.opengl.GL11; public class ItemCustomModelToolsRenderer implements IItemRenderer { private ModelCustomModelTools modeling; protected Minecraft mc; public ItemCustomModelToolsRenderer() { modeling = new ModelCustomModelTools(); } @Override public boolean handleRenderType(ItemStack item, ItemRenderType type) { switch(type) { case EQUIPPED : return CustomModelTools.Model_ON_OFF_Boolean; default: return false; } } @Override public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { return false; } @Override public void renderItem(ItemRenderType type, ItemStack item, Object... data) { switch(type) { case EQUIPPED : { GL11.glPushMatrix(); float scala = 2.5F; GL11.glScalef(scala, scala, scala); GL11.glRotatef(0F, -10.0F, 0.0F, 0.0F); GL11.glRotatef(8F, 0.0F, -10.0F, 0.0F); GL11.glRotatef(125F, 0.0F, 0.0F, -10.0F); GL11.glTranslatef(-0.304800F, -0.500F, -0.09F); mc.renderEngine.bindTexture(new ResourceLocation(CustomModelTools.ModelTexture)); modeling.render((Entity) data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F); GL11.glPopMatrix(); } default: break; } } }
- ModelCustomModelTools
package custom.tool.item; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.Entity; public class ModelCustomModelTools extends ModelBase { public ModelRenderer Stick; public ModelRenderer EnderEye; public ModelRenderer PickaxePats1; public ModelRenderer PickaxePats2; public ModelRenderer PickaxePats3; public ModelRenderer MainCenter; public ModelRenderer AxeUp; public ModelRenderer AxeLeft; public ModelRenderer AxeRight; public ModelRenderer AxeDown; public ModelRenderer Forward; public int TextureSizeWidth = 64; public int TextureSizeHeight = 32; public ModelCustomModelTools() { textureWidth = TextureSizeWidth ; textureHeight = TextureSizeHeight ; Stick = new ModelRenderer(this, 0, 0); Stick.addBox(0F, 0F, 0F, 2, 14, 2); Stick.setRotationPoint(-1F, 0F, -1F); Stick.setTextureSize(TextureSizeWidth, TextureSizeHeight); Stick.mirror = true; setRotation(Stick, 0F, 0F, 0F); EnderEye = new ModelRenderer(this, 8, 0); EnderEye.addBox(0F, 0F, 0F, 3, 3, 3); EnderEye.setRotationPoint(-1.5F, 13.5F, -1.5F); EnderEye.setTextureSize(TextureSizeWidth, TextureSizeHeight); EnderEye.mirror = true; setRotation(EnderEye, 0F, 0F, 0F); PickaxePats1 = new ModelRenderer(this, 20, 0); PickaxePats1.addBox(0F, 0F, 0F, 10, 2, 2); PickaxePats1.setRotationPoint(-4F, -2F, -1F); PickaxePats1.setTextureSize(TextureSizeWidth, TextureSizeHeight); PickaxePats1.mirror = true; setRotation(PickaxePats1, 0F, 0F, 0F); PickaxePats2 = new ModelRenderer(this, 44, 0); PickaxePats2.addBox(0F, 0F, 0F, 5, 2, 2); PickaxePats2.setRotationPoint(6F, -2F, -1F); PickaxePats2.setTextureSize(TextureSizeWidth, TextureSizeHeight); PickaxePats2.mirror = true; setRotation(PickaxePats2, 0F, 0F, 0.2617994F); PickaxePats3 = new ModelRenderer(this, 20, 4); PickaxePats3.addBox(0F, 0F, 0F, 3, 1, 2); PickaxePats3.setRotationPoint(10F, 0F, -1F); PickaxePats3.setTextureSize(TextureSizeWidth, TextureSizeHeight); PickaxePats3.mirror = true; setRotation(PickaxePats3, 0F, 0F, 0.4363323F); MainCenter = new ModelRenderer(this, 30, 4); MainCenter.addBox(0F, 0F, 0F, 4, 6, 4); MainCenter.setRotationPoint(-8F, -5F, -2F); MainCenter.setTextureSize(TextureSizeWidth, TextureSizeHeight); MainCenter.mirror = true; setRotation(MainCenter, 0F, 0F, 0F); AxeUp = new ModelRenderer(this, 30, 14); AxeUp.addBox(0F, 0F, 0F, 2, 6, 4); AxeUp.setRotationPoint(-4F, -9F, -2F); AxeUp.setTextureSize(TextureSizeWidth, TextureSizeHeight); AxeUp.mirror = true; setRotation(AxeUp, 0F, 0F, 0.7853982F); AxeLeft = new ModelRenderer(this, 30, 2); AxeLeft.addBox(0F, 0F, 0F, 2, 6, 6); AxeLeft.setRotationPoint(-3F, -5F, -5F); AxeLeft.setTextureSize(TextureSizeWidth, TextureSizeHeight); AxeLeft.mirror = true; setRotation(AxeLeft, 0F, -1.047198F, 0F); AxeRight = new ModelRenderer(this, 30, 2); AxeRight.addBox(0F, 0F, 0F, 2, 6, 6); AxeRight.setRotationPoint(-8F, -5F, 2F); AxeRight.setTextureSize(TextureSizeWidth, TextureSizeHeight); AxeRight.mirror = true; setRotation(AxeRight, 0F, 1.047198F, 0F); AxeDown = new ModelRenderer(this, 30, 14); AxeDown.addBox(0F, 0F, 0F, 2, 6, 4); AxeDown.setRotationPoint(-8F, 1F, -2F); AxeDown.setTextureSize(TextureSizeWidth, TextureSizeHeight); AxeDown.mirror = true; setRotation(AxeDown, 0F, 0F, -0.7853982F); Forward = new ModelRenderer(this, 8, 6); Forward.addBox(0F, 0F, 0F, 1, 4, 2); Forward.setRotationPoint(-8.5F, -4F, -1F); Forward.setTextureSize(TextureSizeWidth, TextureSizeHeight); Forward.mirror = true; setRotation(Forward, 0F, 0F, 0F); } public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) { super.render(entity, f, f1, f2, f3, f4, f5); setRotationAngles(f, f1, f2, f3, f4, f5, entity); Stick.render(f5); EnderEye.render(f5); PickaxePats1.render(f5); PickaxePats2.render(f5); PickaxePats3.render(f5); MainCenter.render(f5); AxeUp.render(f5); AxeLeft.render(f5); AxeRight.render(f5); AxeDown.render(f5); Forward.render(f5); } private void setRotation(ModelRenderer model, float x, float y, float z) { model.rotateAngleX = x; model.rotateAngleY = y; model.rotateAngleZ = z; } public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity) { super.setRotationAngles(f, f1, f2, f3, f4, f5, entity); } public void setTextureSize(int width, int height) { TextureSizeWidth = width; TextureSizeHeight = height; } }
未完成
チュートリアル一覧に乗せる方がいるのなら、まだ乗せないで下さい