Refactored model initialization for items using block learnings
This commit is contained in:
parent
d2da012ce5
commit
41fe9af457
7 changed files with 183 additions and 27 deletions
|
@ -13,9 +13,10 @@ public interface IItemBase {
|
|||
// wrapper for Forge ItemExpireEvent
|
||||
void onEntityExpireEvent(final EntityItem entityItem, final ItemStack itemStack);
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
void modelInitialisation();
|
||||
|
||||
@Nonnull
|
||||
@SideOnly(Side.CLIENT)
|
||||
ModelResourceLocation getModelResourceLocation(final ItemStack itemStack);
|
||||
|
||||
void modelInitialisation();
|
||||
}
|
128
src/main/java/cr0s/warpdrive/api/ModelInitialisation.puml
Normal file
128
src/main/java/cr0s/warpdrive/api/ModelInitialisation.puml
Normal file
|
@ -0,0 +1,128 @@
|
|||
@startuml
|
||||
participant Forge #cyan
|
||||
participant WarpDrive
|
||||
participant IBlockBase
|
||||
participant IItemBase
|
||||
participant ClientProxy
|
||||
participant ModelLoader #cyan
|
||||
participant ClientRegistry #cyan
|
||||
|
||||
Forge -[#blue]> WarpDrive: FMLPreInitializationEvent
|
||||
activate WarpDrive
|
||||
|
||||
loop blocks and items
|
||||
WarpDrive ->o IBlockBase: new
|
||||
activate IBlockBase
|
||||
IBlockBase -> WarpDrive: register(block)
|
||||
WarpDrive -> WarpDrive: register(item)
|
||||
IBlockBase <-- WarpDrive
|
||||
IBlockBase -> IBlockBase: registerTileEntity
|
||||
|
||||
WarpDrive <-- IBlockBase
|
||||
deactivate IBlockBase
|
||||
|
||||
|
||||
WarpDrive ->o IItemBase: new
|
||||
activate IItemBase
|
||||
IItemBase -> WarpDrive: register(item)
|
||||
IItemBase <-- WarpDrive
|
||||
|
||||
WarpDrive <-- IItemBase
|
||||
deactivate IItemBase
|
||||
end
|
||||
|
||||
Forge <-[#blue]- WarpDrive
|
||||
deactivate WarpDrive
|
||||
|
||||
Forge -[#blue]> WarpDrive: RegistryEvent.Register<Block>
|
||||
activate WarpDrive
|
||||
loop blocks
|
||||
WarpDrive -[#blue]> Forge: register(block)
|
||||
WarpDrive <-[#blue]- Forge
|
||||
end
|
||||
Forge <-[#blue]- WarpDrive
|
||||
deactivate WarpDrive
|
||||
|
||||
Forge -[#blue]> WarpDrive: RegistryEvent.Register<Item>
|
||||
activate WarpDrive
|
||||
loop items
|
||||
WarpDrive -[#blue]> Forge: register(item)
|
||||
WarpDrive <-[#blue]- Forge
|
||||
WarpDrive -> ClientProxy: onModelInitialisation(item)
|
||||
activate ClientProxy
|
||||
ClientProxy -> IItemBase: modelInitialisation()
|
||||
activate IItemBase
|
||||
IItemBase -> ClientProxy: modelInitialisation(item)
|
||||
activate ClientProxy
|
||||
loop sub items
|
||||
ClientProxy -[#blue]> ModelLoader: setCustomModelResourceLocation
|
||||
ClientProxy <-[#blue]- ModelLoader
|
||||
end
|
||||
IItemBase <-- ClientProxy
|
||||
deactivate ClientProxy
|
||||
|
||||
IItemBase -> IItemBase: (custom init)
|
||||
ClientProxy <-- IItemBase
|
||||
deactivate IItemBase
|
||||
|
||||
WarpDrive <- ClientProxy: onModelInitialisation(item)
|
||||
deactivate ClientProxy
|
||||
end
|
||||
|
||||
loop blocks
|
||||
WarpDrive -> ClientProxy: onModelInitialisation(block)
|
||||
activate ClientProxy
|
||||
ClientProxy -> IBlockBase: modelInitialisation(block)
|
||||
activate IBlockBase
|
||||
IBlockBase -> ClientProxy: modelInitialisation(itemBlock)
|
||||
activate ClientProxy
|
||||
loop sub items
|
||||
ClientProxy -[#blue]> ModelLoader: setCustomModelResourceLocation
|
||||
ClientProxy <-[#blue]- ModelLoader
|
||||
end
|
||||
IBlockBase <-- ClientProxy
|
||||
deactivate ClientProxy
|
||||
|
||||
IBlockBase -[#blue]> ModelLoader: setCustomStateMapper
|
||||
activate ModelLoader
|
||||
IBlockBase <-[#blue]- ModelLoader
|
||||
deactivate ModelLoader
|
||||
|
||||
IBlockBase -[#blue]> ClientRegistry: bindTileEntitySpecialRenderer
|
||||
activate ClientRegistry
|
||||
IBlockBase <-[#blue]- ClientRegistry
|
||||
deactivate ClientRegistry
|
||||
|
||||
|
||||
IBlockBase -> ModelBakeEventHandler: registerBakedModel(IMyBakedModel)
|
||||
activate ModelBakeEventHandler
|
||||
IBlockBase <-- ModelBakeEventHandler
|
||||
deactivate ModelBakeEventHandler
|
||||
|
||||
ClientProxy <-- IBlockBase
|
||||
deactivate IBlockBase
|
||||
|
||||
WarpDrive <-- ClientProxy: onModelInitialisation(block)
|
||||
deactivate ClientProxy
|
||||
end
|
||||
|
||||
Forge <-[#blue]- WarpDrive
|
||||
deactivate WarpDrive
|
||||
|
||||
Forge -[#blue]> ModelBakeEventHandler: ModelBakeEvent
|
||||
activate ModelBakeEventHandler
|
||||
loop bakedModels
|
||||
ModelBakeEventHandler ->o IMyBakedModel: new
|
||||
ModelBakeEventHandler -> IMyBakedModel: setResourceLocation()
|
||||
activate IMyBakedModel
|
||||
ModelBakeEventHandler <-- IMyBakedModel
|
||||
deactivate IMyBakedModel
|
||||
ModelBakeEventHandler -> IMyBakedModel: setOriginalBakedModel(IBakedModel)
|
||||
activate IMyBakedModel
|
||||
ModelBakeEventHandler <-- IMyBakedModel
|
||||
deactivate IMyBakedModel
|
||||
end
|
||||
Forge <-[#blue]- ModelBakeEventHandler
|
||||
deactivate ModelBakeEventHandler
|
||||
|
||||
@enduml
|
|
@ -56,8 +56,8 @@ public abstract class BlockAbstractBase extends Block implements IBlockBase {
|
|||
final Item item = Item.getItemFromBlock(this);
|
||||
ClientProxy.modelInitialisation(item);
|
||||
|
||||
// Force a single model through through a custom state mapper
|
||||
/*
|
||||
// Force a single model through a custom state mapper
|
||||
final StateMapperBase stateMapperBase = new StateMapperBase() {
|
||||
@Nonnull
|
||||
@Override
|
||||
|
@ -66,10 +66,8 @@ public abstract class BlockAbstractBase extends Block implements IBlockBase {
|
|||
}
|
||||
};
|
||||
ModelLoader.setCustomStateMapper(this, stateMapperBase);
|
||||
/**/
|
||||
|
||||
// Bind our TESR to our tile entity
|
||||
/*
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityXXXX.class, new TileEntityXXXRenderer());
|
||||
/**/
|
||||
}
|
||||
|
|
|
@ -88,6 +88,13 @@ public class ItemBlockAbstractBase extends ItemBlock implements IItemBase {
|
|||
public void onEntityExpireEvent(EntityItem entityItem, ItemStack itemStack) {
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void modelInitialisation() {
|
||||
ClientProxy.modelInitialisation(this);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Nonnull
|
||||
@Override
|
||||
public ModelResourceLocation getModelResourceLocation(final ItemStack itemStack) {
|
||||
|
|
|
@ -10,9 +10,7 @@ import cr0s.warpdrive.render.*;
|
|||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
@ -75,15 +73,12 @@ public class ClientProxy extends CommonProxy {
|
|||
public void onModelInitialisation(final Object object) {
|
||||
if (object instanceof IBlockBase) {
|
||||
((IBlockBase) object).modelInitialisation();
|
||||
} else if (object instanceof Block) {
|
||||
final Item item = Item.getItemFromBlock((Block) object);
|
||||
modelInitialisation(item);
|
||||
} else if (object instanceof Item) {
|
||||
modelInitialisation((Item) object);
|
||||
} else if (object == null) {
|
||||
WarpDrive.logger.info("Ignoring null object ModelInitialisation...");
|
||||
|
||||
} else if (object instanceof IItemBase) {
|
||||
((IItemBase) object).modelInitialisation();
|
||||
|
||||
} else {
|
||||
throw new RuntimeException(String.format("Invalid object %s",
|
||||
throw new RuntimeException(String.format("Unsupported object, expecting an IBlockBase or IItemBase instance: %s",
|
||||
object));
|
||||
}
|
||||
}
|
||||
|
@ -100,24 +95,21 @@ public class ClientProxy extends CommonProxy {
|
|||
}
|
||||
|
||||
public static void modelInitialisation(final Item item) {
|
||||
if (item == null) {
|
||||
throw new RuntimeException("Unable to ModelInitialize a null item");
|
||||
} else if (item == Items.AIR) {
|
||||
throw new RuntimeException("Unable to ModelInitialize an air item");
|
||||
} else if (!item.getHasSubtypes()) {
|
||||
if (!(item instanceof IItemBase)) {
|
||||
throw new RuntimeException(String.format("Unable to item, expecting an IItemBase instance: %s",
|
||||
item));
|
||||
}
|
||||
|
||||
if (!item.getHasSubtypes()) {
|
||||
assert item.getRegistryName() != null;
|
||||
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
|
||||
|
||||
} else {
|
||||
NonNullList<ItemStack> listItemStacks = NonNullList.create();
|
||||
assert item.getCreativeTab() != null;
|
||||
item.getSubItems(item.getCreativeTab(), listItemStacks);
|
||||
for (final ItemStack itemStack : listItemStacks) {
|
||||
ModelResourceLocation modelResourceLocation;
|
||||
if (item instanceof IItemBase) {
|
||||
modelResourceLocation = ((IItemBase) item).getModelResourceLocation(itemStack);
|
||||
} else {
|
||||
modelResourceLocation = getModelResourceLocation(itemStack);
|
||||
}
|
||||
final ModelResourceLocation modelResourceLocation = ((IItemBase) item).getModelResourceLocation(itemStack);
|
||||
ModelLoader.setCustomModelResourceLocation(item, itemStack.getMetadata(), modelResourceLocation);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,12 @@ public class ItemAbstractBase extends Item implements IItemBase {
|
|||
public void onEntityExpireEvent(final EntityItem entityItem, final ItemStack itemStack) {
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void modelInitialisation() {
|
||||
ClientProxy.modelInitialisation(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
|
|
@ -2,16 +2,23 @@ package cr0s.warpdrive.item;
|
|||
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.api.IBreathingHelmet;
|
||||
import cr0s.warpdrive.api.IItemBase;
|
||||
import cr0s.warpdrive.client.ClientProxy;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.item.ItemArmor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ItemWarpArmor extends ItemArmor implements IBreathingHelmet {
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemWarpArmor extends ItemArmor implements IItemBase, IBreathingHelmet {
|
||||
|
||||
public static final String[] suffixes = { "boots", "leggings", "chestplate", "helmet" };
|
||||
|
||||
|
@ -30,6 +37,23 @@ public class ItemWarpArmor extends ItemArmor implements IBreathingHelmet {
|
|||
return "warpdrive:textures/armor/warp_armor_" + (armorType == EntityEquipmentSlot.LEGS ? 2 : 1) + ".png";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityExpireEvent(final EntityItem entityItem, final ItemStack itemStack) {
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void modelInitialisation() {
|
||||
ClientProxy.modelInitialisation(this);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public ModelResourceLocation getModelResourceLocation(final ItemStack itemStack) {
|
||||
return ClientProxy.getModelResourceLocation(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreath(final EntityLivingBase entityLivingBase) {
|
||||
return armorType == EntityEquipmentSlot.HEAD;
|
||||
|
|
Loading…
Add table
Reference in a new issue