mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-19 11:49:08 +00:00
Working on the Variants/Block Subtypes.
This commit is contained in:
1 parent
2737713f6c
commit
cd4ec4c38e
7 files changed
+44
-71
No files matched your search
+2
-2
@@ -1,5 +1,5 @@
|
||||
mod_version=0.4
|
||||
minecraft_version=1.8
|
||||
forge_version=11.14.1.1392
|
||||
mappings=snapshot_20150424
|
||||
forge_version=11.14.2.1435
|
||||
mappings=snapshot_20150606
|
||||
|
||||
@@ -23,7 +23,7 @@ public class BlockVariant implements Comparable<BlockVariant>
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(BlockVariant o)
|
||||
public int compareTo(BlockVariant variant)
|
||||
{
|
||||
return this.meta;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package mantle.blocks.util;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IBlockWithSubtypes
|
||||
{
|
||||
String getSubtypeUnlocalizedName(ItemStack stack);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package mantle.blocks.util;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IBlockWithVariants
|
||||
{
|
||||
String getVariantNameFromStack(ItemStack stack);
|
||||
}
|
||||
+7
-7
@@ -1,19 +1,19 @@
|
||||
package mantle.blocks.abstracts;
|
||||
package mantle.blocks.util;
|
||||
|
||||
import mantle.blocks.util.IBlockWithVariants;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ItemBlockVariants extends ItemBlock
|
||||
public class ItemBlockSubtypes extends ItemBlock
|
||||
{
|
||||
private final IBlockWithVariants variantBlock;
|
||||
private final IBlockWithSubtypes blockWithSubtypes;
|
||||
|
||||
public ItemBlockVariants(Block block)
|
||||
public ItemBlockSubtypes(Block block)
|
||||
{
|
||||
super(block);
|
||||
|
||||
this.variantBlock = (IBlockWithVariants) block;
|
||||
this.blockWithSubtypes = (IBlockWithSubtypes) block;
|
||||
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
@@ -27,7 +27,7 @@ public class ItemBlockVariants extends ItemBlock
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack stack)
|
||||
{
|
||||
return super.getUnlocalizedName() + "." + this.variantBlock.getVariantNameFromStack(stack);
|
||||
return super.getUnlocalizedName() + "." + this.blockWithSubtypes.getSubtypeUnlocalizedName(stack);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package mantle.blocks.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -11,16 +9,17 @@ public class PropertyVariant implements IProperty
|
||||
{
|
||||
private String name;
|
||||
|
||||
private ArrayList<BlockVariant> values;
|
||||
private BlockVariant defaultVariant;
|
||||
|
||||
private HashMap<Integer, BlockVariant> metaMap;
|
||||
|
||||
protected PropertyVariant(String name, BlockVariant... variants)
|
||||
{
|
||||
this.name = name;
|
||||
this.values = new ArrayList<BlockVariant>(Arrays.asList(variants));
|
||||
this.metaMap = new HashMap<Integer, BlockVariant>();
|
||||
|
||||
this.defaultVariant = variants[0];
|
||||
|
||||
for (BlockVariant variant : variants)
|
||||
{
|
||||
this.metaMap.put(variant.getMeta(), variant);
|
||||
@@ -41,7 +40,7 @@ public class PropertyVariant implements IProperty
|
||||
@Override
|
||||
public Collection<BlockVariant> getAllowedValues()
|
||||
{
|
||||
return this.values;
|
||||
return this.metaMap.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,15 +50,16 @@ public class PropertyVariant implements IProperty
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public String getName(Comparable value)
|
||||
{
|
||||
return ((BlockVariant) value).getName();
|
||||
}
|
||||
|
||||
public BlockVariant getVariantFromMeta(int meta)
|
||||
public BlockVariant fromMeta(int meta)
|
||||
{
|
||||
return this.metaMap.get(meta);
|
||||
BlockVariant variant = this.metaMap.get(meta);
|
||||
|
||||
return variant != null ? variant : this.defaultVariant;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +1,11 @@
|
||||
package mantle.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import mantle.blocks.util.BlockVariant;
|
||||
import mantle.items.util.IItemWithVariants;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -28,59 +22,38 @@ public class ModelVariant
|
||||
this.mc = mc;
|
||||
}
|
||||
|
||||
public void registerBlockModelVariants(Block block, Collection<BlockVariant> variants)
|
||||
private void registerBlockModel(Block block)
|
||||
{
|
||||
for (BlockVariant variant : variants)
|
||||
{
|
||||
Item item = Item.getItemFromBlock(block);
|
||||
ResourceLocation resourceLocation = (ResourceLocation) Block.blockRegistry.getNameForObject(block);
|
||||
|
||||
this.registerItemModel(item, variant.getName(), variant.getMeta());
|
||||
ModelBakery.addVariantName(item, (this.MOD_ID + ":") + variant.getName());
|
||||
}
|
||||
registerBlockModel(block, 0, resourceLocation.getResourcePath());
|
||||
}
|
||||
|
||||
public void registerBlockModel(Block block)
|
||||
private void registerItemModel(Item item)
|
||||
{
|
||||
this.registerBlockModel(block, block.getUnlocalizedName().substring(5), 0);
|
||||
ResourceLocation resourceLocation = (ResourceLocation) Item.itemRegistry.getNameForObject(item);
|
||||
|
||||
registerItemModel(item, 0, resourceLocation.getResourcePath());
|
||||
}
|
||||
|
||||
public void registerBlockModel(Block block, String name, int meta)
|
||||
private void registerBlockModel(Block block, int meta, String modelName)
|
||||
{
|
||||
this.registerItemModel(Item.getItemFromBlock(block), name, meta);
|
||||
registerItemModel(Item.getItemFromBlock(block), meta, modelName);
|
||||
}
|
||||
|
||||
public void registerItemModel(Item item)
|
||||
private void registerItemModel(Item item, int meta, String resourcePath)
|
||||
{
|
||||
this.registerItemModel(item, item.getUnlocalizedName().substring(5), 0);
|
||||
ModelResourceLocation modelResourceLocation = new ModelResourceLocation((this.MOD_ID + ":") + resourcePath, "inventory");
|
||||
|
||||
this.mc.getRenderItem().getItemModelMesher().register(item, meta, modelResourceLocation);
|
||||
}
|
||||
|
||||
public void registerItemModel(Item item, String name, int meta)
|
||||
private void registerBlockModelVariant(Block block, int meta, String resourcePath)
|
||||
{
|
||||
this.mc.getRenderItem().getItemModelMesher().register(item, meta, this.getModelResource(name, "inventory"));
|
||||
}
|
||||
Item item = Item.getItemFromBlock(block);
|
||||
|
||||
public void registerItemModelVariants(Item item)
|
||||
{
|
||||
for (int i = 0; i < ((IItemWithVariants) item).getVariantNames().length; i++)
|
||||
{
|
||||
String NAME = item.getUnlocalizedName().substring(5) + "_" + ((IItemWithVariants) item).getVariantNames()[i];
|
||||
ModelBakery.addVariantName(item, (this.MOD_ID + ":") + NAME);
|
||||
this.registerItemModel(item, NAME, i);
|
||||
}
|
||||
}
|
||||
registerItemModel(item, meta, resourcePath);
|
||||
|
||||
public void registerItemSubTypesModel(Item item, CreativeTabs tab)
|
||||
{
|
||||
ArrayList<ItemStack> list = new ArrayList<ItemStack>();
|
||||
item.getSubItems(item, tab, list);
|
||||
for (ItemStack i : list)
|
||||
{
|
||||
this.registerItemModel(item, item.getUnlocalizedName().substring(5), i.getItemDamage());
|
||||
}
|
||||
}
|
||||
|
||||
private ModelResourceLocation getModelResource(String name, String type)
|
||||
{
|
||||
return new ModelResourceLocation((this.MOD_ID + ":") + name, type);
|
||||
ModelBakery.addVariantName(item, (this.MOD_ID + ":") + resourcePath);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user