Improved item model registration
- more generic item handling - fix double item block registration
This commit is contained in:
parent
f04782dd72
commit
3102520372
8 changed files with 58 additions and 25 deletions
|
@ -3,13 +3,11 @@ package cr0s.warpdrive.block;
|
|||
import cr0s.warpdrive.Commons;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.api.IBlockBase;
|
||||
import cr0s.warpdrive.client.ClientProxy;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
|
@ -55,8 +53,7 @@ public abstract class BlockAbstractBase extends Block implements IBlockBase {
|
|||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void modelInitialisation() {
|
||||
final Item item = Item.getItemFromBlock(this);
|
||||
ClientProxy.modelInitialisation(item);
|
||||
// no operation
|
||||
|
||||
/*
|
||||
// Force a single model through a custom state mapper
|
||||
|
|
|
@ -6,7 +6,6 @@ import cr0s.warpdrive.api.IBlockBase;
|
|||
import cr0s.warpdrive.api.IBlockUpdateDetector;
|
||||
import cr0s.warpdrive.api.IVideoChannel;
|
||||
import cr0s.warpdrive.api.WarpDriveText;
|
||||
import cr0s.warpdrive.client.ClientProxy;
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
import cr0s.warpdrive.data.EnumComponentType;
|
||||
import cr0s.warpdrive.data.EnumTier;
|
||||
|
@ -81,8 +80,7 @@ public abstract class BlockAbstractContainer extends BlockContainer implements I
|
|||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void modelInitialisation() {
|
||||
final Item item = Item.getItemFromBlock(this);
|
||||
ClientProxy.modelInitialisation(item);
|
||||
// no operation
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.block.state.BlockStateContainer;
|
|||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
|
@ -67,6 +68,12 @@ public class BlockAbstractLamp extends BlockAbstractBase {
|
|||
| (blockState.getValue(BlockProperties.FACING).getIndex());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemBlock createItemBlock() {
|
||||
return new ItemBlockLamp(this);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package cr0s.warpdrive.block.decoration;
|
||||
|
||||
import cr0s.warpdrive.block.ItemBlockAbstractBase;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemBlockLamp extends ItemBlockAbstractBase {
|
||||
|
||||
public ItemBlockLamp(final Block block) {
|
||||
super(block, true, false);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public ModelResourceLocation getModelResourceLocation(final ItemStack itemStack) {
|
||||
final ResourceLocation resourceLocation = getRegistryName();
|
||||
assert resourceLocation != null;
|
||||
final String variant = "inventory";
|
||||
return new ModelResourceLocation(resourceLocation, variant);
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@ package cr0s.warpdrive.block.hull;
|
|||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.api.IBlockBase;
|
||||
import cr0s.warpdrive.api.IDamageReceiver;
|
||||
import cr0s.warpdrive.client.ClientProxy;
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
import cr0s.warpdrive.data.EnumTier;
|
||||
import cr0s.warpdrive.data.Vector3;
|
||||
|
@ -16,7 +15,6 @@ import net.minecraft.block.BlockGlass;
|
|||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.EnumPushReaction;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
@ -84,8 +82,7 @@ public class BlockHullGlass extends BlockColored implements IBlockBase, IDamageR
|
|||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void modelInitialisation() {
|
||||
final Item item = Item.getItemFromBlock(this);
|
||||
ClientProxy.modelInitialisation(item);
|
||||
// no operation
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
|
|
@ -3,7 +3,6 @@ package cr0s.warpdrive.block.hull;
|
|||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.api.IBlockBase;
|
||||
import cr0s.warpdrive.api.IDamageReceiver;
|
||||
import cr0s.warpdrive.client.ClientProxy;
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
import cr0s.warpdrive.data.EnumTier;
|
||||
import cr0s.warpdrive.data.Vector3;
|
||||
|
@ -25,7 +24,6 @@ import net.minecraft.block.state.IBlockState;
|
|||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.EnumDyeColor;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.DamageSource;
|
||||
|
@ -316,8 +314,7 @@ public class BlockHullSlab extends BlockSlab implements IBlockBase, IDamageRecei
|
|||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void modelInitialisation() {
|
||||
final Item item = Item.getItemFromBlock(this);
|
||||
ClientProxy.modelInitialisation(item);
|
||||
// no operation
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,7 +3,6 @@ package cr0s.warpdrive.block.hull;
|
|||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.api.IBlockBase;
|
||||
import cr0s.warpdrive.api.IDamageReceiver;
|
||||
import cr0s.warpdrive.client.ClientProxy;
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
import cr0s.warpdrive.data.EnumTier;
|
||||
import cr0s.warpdrive.data.Vector3;
|
||||
|
@ -15,7 +14,6 @@ import net.minecraft.block.BlockStairs;
|
|||
import net.minecraft.block.material.EnumPushReaction;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.EnumDyeColor;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.DamageSource;
|
||||
|
@ -70,8 +68,7 @@ public class BlockHullStairs extends BlockStairs implements IBlockBase, IDamageR
|
|||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void modelInitialisation() {
|
||||
final Item item = Item.getItemFromBlock(this);
|
||||
ClientProxy.modelInitialisation(item);
|
||||
// no operation
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,7 +12,11 @@ import cr0s.warpdrive.render.*;
|
|||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.item.Item;
|
||||
|
@ -84,7 +88,7 @@ public class ClientProxy extends CommonProxy {
|
|||
ResourceLocation resourceLocation = item.getRegistryName();
|
||||
assert resourceLocation != null;
|
||||
|
||||
// reuse blockstate rendering for ItemBlocks
|
||||
// reuse blockstate rendering for ItemBlocks when their blockstate have at least one property (typically colored blocks)
|
||||
if (item instanceof ItemBlock) {
|
||||
final int damage = itemStack.getItemDamage();
|
||||
if (damage < 0 || damage > 15) {
|
||||
|
@ -92,14 +96,20 @@ public class ClientProxy extends CommonProxy {
|
|||
damage, itemStack.getItem()));
|
||||
}
|
||||
final Block block = ((ItemBlock) item).getBlock();
|
||||
final String variant = block.getStateFromMeta(damage).toString().split("[\\[\\]]")[1];
|
||||
return new ModelResourceLocation(resourceLocation, variant);
|
||||
final IBlockState blockState = block.getStateFromMeta(damage);
|
||||
final Collection<IProperty<?>> properties = blockState.getPropertyKeys();
|
||||
if (!properties.isEmpty()) {// reuse defined properties
|
||||
final String[] blockStateStrings = blockState.toString().split("[\\[\\]]");
|
||||
final String variant = blockStateStrings[1];
|
||||
return new ModelResourceLocation(resourceLocation, variant);
|
||||
}
|
||||
}
|
||||
|
||||
// use damage value as suffix for pure items
|
||||
// use damage value as suffix otherwise
|
||||
if (item.getHasSubtypes()) {
|
||||
resourceLocation = new ResourceLocation(resourceLocation.getNamespace(), resourceLocation.getPath() + "-" + itemStack.getItemDamage());
|
||||
}
|
||||
// defaults to inventory variant
|
||||
return new ModelResourceLocation(resourceLocation, "inventory");
|
||||
}
|
||||
|
||||
|
@ -110,8 +120,8 @@ public class ClientProxy extends CommonProxy {
|
|||
}
|
||||
|
||||
if (!item.getHasSubtypes()) {
|
||||
assert item.getRegistryName() != null;
|
||||
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
|
||||
final ModelResourceLocation modelResourceLocation = ((IItemBase) item).getModelResourceLocation(new ItemStack(item));
|
||||
ModelLoader.setCustomModelResourceLocation(item, 0, modelResourceLocation);
|
||||
|
||||
} else {
|
||||
final NonNullList<ItemStack> listItemStacks = NonNullList.create();
|
||||
|
|
Loading…
Reference in a new issue