最新版 |
編集中の文章 |
1行目: |
1行目: |
| ==1.6のモデル付きカスタムツール追加== | | ==1.6のモデル付きカスタムツール追加== |
− |
| |
− | このアイテムは、(つるはし)(ショベル)(斧)の三つ(鉄製)にモデルを付けて追加するものです。
| |
| | | |
| ===ソース=== | | ===ソース=== |
10行目: |
8行目: |
| package custom.tool.item; | | package custom.tool.item; |
| | | |
− | import net.minecraft.block.Block;
| |
− | import net.minecraft.item.EnumToolMaterial;
| |
− | import net.minecraft.item.Item;
| |
− | import net.minecraft.item.ItemStack;
| |
− | 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; |
| + | import cpw.mods.fml.common.network.NetworkMod; |
| import cpw.mods.fml.common.Mod.EventHandler; | | import cpw.mods.fml.common.Mod.EventHandler; |
| import cpw.mods.fml.common.event.FMLPreInitializationEvent; | | import cpw.mods.fml.common.event.FMLPreInitializationEvent; |
− | import cpw.mods.fml.common.network.NetworkMod;
| |
− | import cpw.mods.fml.common.registry.GameRegistry;
| |
− | import cpw.mods.fml.common.registry.LanguageRegistry;
| |
| | | |
| @Mod( | | @Mod( |
− | modid = CustomModelTools.modid, | + | modid = "CustomModelTools", |
− | name = CustomModelTools.name, | + | name = "Custom Model Tools", |
− | version = CustomModelTools.version | + | version = "1" |
| ) | | ) |
| @NetworkMod( | | @NetworkMod( |
35行目: |
24行目: |
| public class CustomModelTools | | public class CustomModelTools |
| { | | { |
− | public static final String modid = "CustomModelTools";
| |
− | public static final String name = "Custom Model Tools Modification";
| |
− | public static final String version = "1";
| |
− |
| |
| public static final boolean clientSideRequiredBoolean = true; | | public static final boolean clientSideRequiredBoolean = true; |
− | public static final boolean serverSideRequiredBoolean = false; | + | public static final boolean serverSudeRequiredBoolean = false; |
− |
| |
− | public static boolean Model_ON_OFF_Boolean = true;
| |
− | public static String ModelTexture;
| |
− | public static String texture = "model";
| |
− | public static int textureWidth = 64;
| |
− | public static int textureHeight = 32;
| |
− |
| |
− | public static EnumToolMaterial toolMaterial;
| |
| | | |
| public static ItemTool mainItem; | | public static ItemTool mainItem; |
− | public static int itemID = 3001; //default 3001 = 3257
| |
− | public static int damageFloat = (int) 1.0;
| |
− | public static String domain = "CustomModelItem";
| |
− | public static String item_name = "CustomModelItem";
| |
| | | |
− | @EventHandler | + | @EventHabdler |
| public void mainLoading(FMLPreInitializationEvent event) | | public void mainLoading(FMLPreInitializationEvent event) |
| { | | { |
− | mainItem = (ItemTool) new ItemCustomModelTools(itemID, toolMaterial.IRON).setData(domain, item_name, damageFloat); | + | mainItem = new |
− | registerItem(mainItem, "CustomModelItem", "Custom Model Item", "カスタムモデルアイテム", new ItemCustomModelToolsRenderer(), true, texture, textureWidth, textureHeight);
| |
− | GameRegistry.addRecipe(new ItemStack(mainItem, 1, 0), new Object[] {" S ", "DCF", " X ", 'S', Item.pickaxeIron, 'D', Item.shovelIron, 'F', Item.axeIron, 'X', Item.stick, 'C', Block.stone});
| |
− | }
| |
− | 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);
| |
− | }
| |
− | public static void configInformation(int ItemID, String domain, String name, int damage, boolean modeling, int width, int height)
| |
− | {
| |
− | itemID = ItemID;
| |
− | CustomModelTools.domain = domain;
| |
− | item_name = name;
| |
− | damageFloat = damage;
| |
− | Model_ON_OFF_Boolean = modeling;
| |
− | ModelCustomModelTools modelings = new ModelCustomModelTools();
| |
− | modelings.setTextureSize(width, height);
| |
| } | | } |
| } | | } |
92行目: |
42行目: |
| <source lang = java> | | <source lang = java> |
| package custom.tool.item; | | 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 | | public class ItemCustomModelTools extends ItemTool |
| { | | { |
− | //壊せるブロックのリスト
| + | public ItemCustomModelTools(int par1ID, |
− | 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;
| |
− | }
| |
− | }
| |
− | | |
− | </source>
| |
− | | |
− | *ItemCustomModelToolsRenderer.java
| |
− | | |
− | <source lang = 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;
| |
− | 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);
| |
− |
| |
− | Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(CustomModelTools.domain, "textures/model/" + CustomModelTools.texture + ".png"));
| |
− |
| |
− | modeling.render((Entity) data[1], 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
| |
− |
| |
− | GL11.glPopMatrix();
| |
− | }
| |
− | default:
| |
− | break;
| |
− | }
| |
− | }
| |
− | }
| |
− | | |
− | </source>
| |
− | | |
− | *ModelCustomModelTools
| |
− | | |
− | <source lang = java>
| |
− | 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;
| |
− | }
| |
− | }
| |
− | | |
− | </source>
| |
− | | |
− | ==解説==
| |
− | | |
− | 注意、Mod開発上級者しかわからないと思いますが、すべて解説していきます。
| |
− | | |
− | ===CustomModelTools.java===
| |
− | | |
− | <source lang = java>
| |
− | public void mainLoading(FMLPreInitializationEvent event)
| |
− | </source>
| |
− | これは、最前列に実行するポイントで、メドッソ名のmainLoadingはpreInit限定ではありません。<br>
| |
− | <source lang = java>
| |
− | public static void configInformation(int ItemID, String domain, String name, int damage, boolean modeling, int width, int height)
| |
− | </source>
| |
− | ここでは、メドッソ名道理、コンフィグ用のところです。<br>
| |
− | なので、使わない場合、消去してかまいません。<br>
| |
− | UTF-8で保存してください。
| |
− | | |
− | <source lang = java>
| |
− | mainItem = (ItemTool) new ItemCustomModelTools(itemID, toolMaterial.IRON).setData("CustomModelItem", "CustomModelItem", damageFloat);
| |
− | </source>
| |
− | ここの最初のコンテナで、アイテム登録します。<br>
| |
− | setDataは、最初のストリングは「場所」、2番目のストリングは「アイテム名、テクスチャ名」、3番目は「アイテムのダメージカウント」
| |
− | | |
− | <source lang = java>
| |
− | registerItem(mainItem, "CustomModelItem", "Custom Model Item", "カスタムモデルアイテム", new ItemCustomModelToolsRenderer(), true, texture, textureWidth, textureHeight);
| |
− | </source>
| |
− | ここでは、アイテムデータを詳しく登録するところです。<br>
| |
− | 1番目は「アイテムコンテナ」、2番目は「アイテム名」、3番目は「英語名」、4番目は「日本語名」、5番目は「モデルデータ」、6番目は「モデルを使うか」、7_8番目は「モデルテクスチャサイズ」<br>
| |
− | | |
− | ===ItemCustomModelTools.java===
| |
− | | |
− | <source lang = java>
| |
− | private static final Block[] setBleakingList = new Block[] {..., ...., ..., ....};
| |
− | </source>
| |
− | ここでは、壊せるブロックのリストです。<br>
| |
− | ここに、登録されてなくても壊せるものはありますが、ここで登録しといたほうがいいです。
| |
− | | |
− | <source lang = java>
| |
− | public static float damageFloat = 1.0F;
| |
− | </source>
| |
− | ここでは、対mobに使うところです。
| |
− | | |
− | <source lang = java>
| |
− | public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block)
| |
− | </source>
| |
− | ここでは、掘れるマテリアル属性を登録するところです。
| |
− | | |
− | ===ItemCustomModelToolsRenderer.java===
| |
− | | |
− | <source lang = java>
| |
− | private ModelCustomModelTools modeling;
| |
− | public ItemCustomModelToolsRenderer()
| |
− | {
| |
− | modeling = new ModelCustomModelTools();
| |
| } | | } |
− | </source>
| |
− | ここでは、モデルデータを登録するところです。
| |
| | | |
− | <source lang = java>
| |
− | public boolean handleRenderType(ItemStack item, ItemRenderType type)
| |
| </source> | | </source> |
− | ここでは、モデルをつけるかどうかを認識するところです。<br>
| |
− | IItemRendererないにある、EnumクラスのItemRenderType.javaにある、「ENTITY」「EQUIPPED」「EQUIPPED_FIRST_PERSON」「INVENTORY」「FIRST_PERSON_MAP」の五つあり、
| |
− | ENTITYは、EntityItem認識を行うところです。<br>
| |
− | EQUIPPEDは、今回使うもので、モデル認識を行うところです。<br>
| |
− | EQUIPPED_FIRST_PERSONは、三人称視点でのモデル認識を行うところです<br>
| |
− | INVENTORYは、インベントリ内のみモデル認識を行うところです。<br>
| |
− | FIRST_PERSON_MAPは、MapData.javaの認識転移範囲内にプレイヤーがあるかどうかを確認させて、実行させるかどうかです。
| |
− |
| |
− | <source lang = java>
| |
− | public void renderItem(ItemRenderType type, ItemStack item, Object... data)
| |
− | </source>
| |
− | ここでは、モデルデータを詳しく登録するところで、先ほど出した「EQUIPPED」の内容を登録するところです。<br>
| |
− | テクスチャロードは、CustomModelItemをドメインにしてるので、
| |
− | assets/CustomModelItem/...
| |
− | となり、モデル名前が「model」なので、
| |
− | assets/CustomModelItem/textures/model/model.png
| |
− | となります。
| |
− | テクスチャの場所は「assets/CustomModelItem/textures/model/model.png」
| |
− |
| |
− | ===ModelCustomModelTools.java===
| |
| | | |
− | ここでは、アイテムに使うモデルを設定するところです。
| + | 未完成 |