-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Going to put this in Mantle and not Natura. It helps with deal with M…
…etadata (Different Variants).
- Loading branch information
Alexander
committed
Mar 29, 2015
1 parent
ff9c829
commit 3b1b56b
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package mantle.blocks.abstracts; | ||
|
||
import mantle.blocks.iface.IBlockWithVariants; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.item.ItemBlock; | ||
import net.minecraft.item.ItemStack; | ||
|
||
public class ItemBlockVariants extends ItemBlock | ||
{ | ||
private final IBlockWithVariants variantBlock; | ||
|
||
public ItemBlockVariants(Block block) | ||
{ | ||
super(block); | ||
|
||
this.variantBlock = (IBlockWithVariants) block; | ||
this.setMaxDamage(0); | ||
this.setHasSubtypes(true); | ||
} | ||
|
||
@Override | ||
public int getMetadata(int damage) | ||
{ | ||
return damage; | ||
} | ||
|
||
@Override | ||
public String getUnlocalizedName(ItemStack stack) | ||
{ | ||
return super.getUnlocalizedName() + "." + this.variantBlock.getVariantNameFromStack(stack); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package mantle.blocks.iface; | ||
|
||
import net.minecraft.util.IStringSerializable; | ||
|
||
public interface IBlockVariant extends IStringSerializable | ||
{ | ||
int getMetadata(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package mantle.blocks.iface; | ||
|
||
import net.minecraft.item.ItemStack; | ||
|
||
public interface IBlockWithVariants | ||
{ | ||
String getVariantNameFromStack(ItemStack stack); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package mantle.client; | ||
|
||
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.item.Item; | ||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.fml.relauncher.SideOnly; | ||
import mantle.blocks.iface.IBlockVariant; | ||
|
||
@SideOnly(Side.CLIENT) | ||
public class ModelVariant | ||
{ | ||
private String modID; | ||
|
||
public ModelVariant(String modId) | ||
{ | ||
this.modID = modId; | ||
} | ||
|
||
public void registerItemRenderer(Block block, IBlockVariant[] variants) | ||
{ | ||
String[] names = new String[variants.length]; | ||
|
||
for (int i = 0; i < variants.length; ++i) | ||
{ | ||
IBlockVariant subtype = variants[i]; | ||
names[i] = (this.modID + ":") + subtype.getName(); | ||
|
||
this.registerItemRenderer(names[i], Item.getItemFromBlock(block), subtype.getMetadata()); | ||
} | ||
|
||
ModelBakery.addVariantName(Item.getItemFromBlock(block), names); | ||
} | ||
|
||
public void registerItemRenderer(Block block, int meta) | ||
{ | ||
this.registerItemRenderer(Item.getItemFromBlock(block), meta); | ||
} | ||
|
||
public void registerItemRenderer(Item item, int meta) | ||
{ | ||
String name = (this.modID + ":") + item.getUnlocalizedName().substring(5); | ||
|
||
this.registerItemRenderer(name, item, meta); | ||
} | ||
|
||
public void registerItemRenderer(String name, Block block, int meta) | ||
{ | ||
this.registerItemRenderer(name, Item.getItemFromBlock(block), meta); | ||
} | ||
|
||
public static void registerItemRenderer(String name, Item item, int meta) | ||
{ | ||
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, meta, new ModelResourceLocation(name, "inventory")); | ||
} | ||
} |