mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-19 19:49:54 +00:00
Fix Crate Models and other Models
This commit is contained in:
1 parent
f85b534389
commit
28502d23e0
62 files changed
+1918
-626
No files matched your search
@@ -98,6 +98,7 @@ public class Forestry {
|
||||
|
||||
PluginManager.runPreInit();
|
||||
|
||||
Proxies.render.registerLoaders();
|
||||
Proxies.render.registerModels();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.blocks;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.apiculture.tiles.TileApiary;
|
||||
@@ -40,6 +42,6 @@ public enum BlockTypeApiculture implements IBlockType {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name();
|
||||
return getMachineProperties().getName();
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.blocks;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -48,6 +50,6 @@ public enum BlockTypeApicultureTesr implements IBlockTypeTesr {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name();
|
||||
return getMachineProperties().getName();
|
||||
}
|
||||
}
|
||||
@@ -123,9 +123,7 @@ public class BlockArbFence extends BlockFence implements IWoodTyped, IItemModelR
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
if (!fireproof) {
|
||||
manager.registerVariant(item, ItemBlockWood.getVariants(this));
|
||||
}
|
||||
manager.registerVariant(item, ItemBlockWood.getVariants(this));
|
||||
manager.registerItemModel(item, new WoodMeshDefinition(this));
|
||||
}
|
||||
|
||||
|
||||
@@ -129,9 +129,7 @@ public class BlockArbStairs extends BlockStairs implements IWoodTyped, IItemMode
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
if (!fireproof) {
|
||||
manager.registerVariant(item, ItemBlockWood.getVariants(this));
|
||||
}
|
||||
manager.registerVariant(item, ItemBlockWood.getVariants(this));
|
||||
manager.registerItemModel(item, new WoodMeshDefinition(this));
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.arboriculture.blocks.property.PropertyFruit;
|
||||
import forestry.arboriculture.render.StateMapperFluidPod;
|
||||
import forestry.arboriculture.render.FluidPodStateMapper;
|
||||
import forestry.arboriculture.tiles.TileFruitPod;
|
||||
import forestry.core.blocks.propertys.UnlistedBlockAccess;
|
||||
import forestry.core.blocks.propertys.UnlistedBlockPos;
|
||||
@@ -137,7 +137,7 @@ public class BlockFruitPod extends BlockCocoa implements IStateMapperRegister {
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerStateMapper() {
|
||||
Proxies.render.registerStateMapper(this, new StateMapperFluidPod());
|
||||
Proxies.render.registerStateMapper(this, new FluidPodStateMapper());
|
||||
}
|
||||
|
||||
/* IGrowable */
|
||||
|
||||
@@ -20,6 +20,7 @@ import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.BlockState;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
@@ -30,18 +31,22 @@ import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IPlantable;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import forestry.api.arboriculture.EnumGermlingType;
|
||||
import forestry.api.arboriculture.IAlleleTreeSpecies;
|
||||
import forestry.api.arboriculture.TreeManager;
|
||||
import forestry.api.core.IItemModelRegister;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.arboriculture.blocks.property.PropertyTree;
|
||||
import forestry.arboriculture.render.StateMapperSapling;
|
||||
import forestry.arboriculture.render.SaplingStateMapper;
|
||||
import forestry.arboriculture.tiles.TileSapling;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
|
||||
public class BlockSapling extends BlockTreeContainer implements IGrowable, IStateMapperRegister {
|
||||
public class BlockSapling extends BlockTreeContainer implements IGrowable, IStateMapperRegister, IItemModelRegister {
|
||||
|
||||
/* PROPERTYS */
|
||||
public static final PropertyTree TREE = new PropertyTree("tree");
|
||||
@@ -109,7 +114,14 @@ public class BlockSapling extends BlockTreeContainer implements IGrowable, IStat
|
||||
|
||||
@Override
|
||||
public void registerStateMapper() {
|
||||
Proxies.render.registerStateMapper(this, new StateMapperSapling());
|
||||
Proxies.render.registerStateMapper(this, new SaplingStateMapper());
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
//To delete the error message
|
||||
manager.registerItemModel(item, 0, "germlings/sapling.treeLarch");
|
||||
}
|
||||
|
||||
/* PLANTING */
|
||||
|
||||
@@ -115,9 +115,7 @@ public class BlockSlab extends net.minecraft.block.BlockSlab implements IWoodTyp
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
if (!fireproof) {
|
||||
manager.registerVariant(item, ItemBlockWood.getVariants(this));
|
||||
}
|
||||
manager.registerVariant(item, ItemBlockWood.getVariants(this));
|
||||
manager.registerItemModel(item, new WoodMeshDefinition(this));
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.blocks;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -48,6 +50,6 @@ public enum BlockTypeArboricultureTesr implements IBlockTypeTesr {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name();
|
||||
return getMachineProperties().getName();
|
||||
}
|
||||
}
|
||||
@@ -91,9 +91,7 @@ public abstract class BlockWood extends Block implements ITileEntityProvider, II
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
if (!fireproof) {
|
||||
manager.registerVariant(item, ItemBlockWood.getVariants(this));
|
||||
}
|
||||
manager.registerVariant(item, ItemBlockWood.getVariants(this));
|
||||
manager.registerItemModel(item, new WoodMeshDefinition(this));
|
||||
}
|
||||
|
||||
|
||||
+6
-5
@@ -8,7 +8,7 @@ import forestry.api.arboriculture.IAlleleFruit;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.arboriculture.blocks.BlockFruitPod;
|
||||
import forestry.core.render.StateMapperForestry;
|
||||
import forestry.core.render.ForestryStateMapper;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockCocoa;
|
||||
import net.minecraft.block.BlockDirectional;
|
||||
@@ -19,7 +19,7 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class StateMapperFluidPod extends StateMapperForestry{
|
||||
public class FluidPodStateMapper extends ForestryStateMapper{
|
||||
|
||||
private final Map<IBlockState, ModelResourceLocation> mapStateModelLocations = Maps.newLinkedHashMap();
|
||||
|
||||
@@ -30,10 +30,11 @@ public class StateMapperFluidPod extends StateMapperForestry{
|
||||
for (int age = 0;age < BlockCocoa.AGE.getAllowedValues().size();age++){
|
||||
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) {
|
||||
if (allele instanceof IAlleleFruit) {
|
||||
if(((IAlleleFruit) allele).getModelName() != null){
|
||||
IBlockState state = block.getDefaultState().withProperty(BlockFruitPod.FRUIT, (IAlleleFruit)allele).withProperty(BlockDirectional.FACING, facing).withProperty(BlockCocoa.AGE, age);
|
||||
IAlleleFruit fruit = (IAlleleFruit) allele;
|
||||
if(fruit.getModelName() != null){
|
||||
IBlockState state = block.getDefaultState().withProperty(BlockFruitPod.FRUIT, fruit).withProperty(BlockDirectional.FACING, facing).withProperty(BlockCocoa.AGE, age);
|
||||
LinkedHashMap linkedhashmap = Maps.newLinkedHashMap(state.getProperties());
|
||||
String modID = ((IAlleleFruit) allele).getModID();
|
||||
String modID = fruit.getModID();
|
||||
if(modID == null){
|
||||
modID = "forestry";
|
||||
}
|
||||
+6
-5
@@ -9,7 +9,7 @@ import forestry.api.arboriculture.IAlleleTreeSpecies;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.arboriculture.blocks.BlockSapling;
|
||||
import forestry.core.render.StateMapperForestry;
|
||||
import forestry.core.render.ForestryStateMapper;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
@@ -17,19 +17,20 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class StateMapperSapling extends StateMapperForestry {
|
||||
public class SaplingStateMapper extends ForestryStateMapper {
|
||||
|
||||
@Override
|
||||
public Map putStateModelLocations(Block block) {
|
||||
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) {
|
||||
if (allele instanceof IAlleleTreeSpecies) {
|
||||
IBlockState state = block.getDefaultState().withProperty(BlockSapling.TREE, (IAlleleTreeSpecies)allele);
|
||||
IAlleleTreeSpecies tree = (IAlleleTreeSpecies)allele;
|
||||
IBlockState state = block.getDefaultState().withProperty(BlockSapling.TREE, tree);
|
||||
LinkedHashMap linkedhashmap = Maps.newLinkedHashMap(state.getProperties());
|
||||
String modID = ((IAlleleTreeSpecies) allele).getModID();
|
||||
String modID = tree.getModID();
|
||||
if(modID == null){
|
||||
modID = "forestry";
|
||||
}
|
||||
String s = String.format("%s:%s",((IAlleleTreeSpecies) allele).getModID(), "germlings");
|
||||
String s = String.format("%s:%s", modID, "germlings");
|
||||
mapStateModelLocations.put(state, new ModelResourceLocation(s, getPropertyString(linkedhashmap)));
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ import forestry.core.access.IAccessHandler;
|
||||
import forestry.core.circuits.ISocketable;
|
||||
import forestry.core.fluids.FluidHelper;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.StateMapperMachine;
|
||||
import forestry.core.render.MachineStateMapper;
|
||||
import forestry.core.tiles.TileBase;
|
||||
import forestry.core.tiles.TileForestry;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
@@ -56,24 +56,24 @@ import forestry.core.utils.PlayerUtil;
|
||||
|
||||
import jline.internal.Log;
|
||||
|
||||
public class BlockBase<C extends Enum<C> & IBlockType & IStringSerializable> extends BlockForestry implements IItemModelRegister, IStateMapperRegister {
|
||||
private final Map<C, IMachineProperties> definitions = new HashMap<>();
|
||||
public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> extends BlockForestry implements IItemModelRegister, IStateMapperRegister {
|
||||
private final Map<P, IMachineProperties> properties = new HashMap<>();
|
||||
private final boolean hasTESR;
|
||||
private final Class<C> machinePropertiesClass;
|
||||
private final Class<P> machinePropertiesClass;
|
||||
|
||||
/* PROPERTIES */
|
||||
private final PropertyEnum<C> TYPE;
|
||||
private final PropertyEnum<P> TYPE;
|
||||
private final PropertyEnum<EnumFacing> FACE;
|
||||
|
||||
protected final BlockState blockState;
|
||||
|
||||
private boolean isReady = false;
|
||||
|
||||
public BlockBase(Class<C> machinePropertiesClass) {
|
||||
public BlockBase(Class<P> machinePropertiesClass) {
|
||||
this(false, machinePropertiesClass);
|
||||
}
|
||||
|
||||
public BlockBase(boolean hasTESR, Class<C> machinePropertiesClass) {
|
||||
public BlockBase(boolean hasTESR, Class<P> machinePropertiesClass) {
|
||||
super(Material.iron);
|
||||
|
||||
this.hasTESR = hasTESR;
|
||||
@@ -91,12 +91,12 @@ public class BlockBase<C extends Enum<C> & IBlockType & IStringSerializable> ext
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public final void addDefinitions(C... blockTypes) {
|
||||
for (C blockType : blockTypes) {
|
||||
public final void addDefinitions(P... blockTypes) {
|
||||
for (P blockType : blockTypes) {
|
||||
IMachineProperties<?> machineProperties = blockType.getMachineProperties();
|
||||
if (machineProperties != null) {
|
||||
machineProperties.setBlock(this);
|
||||
this.definitions.put(blockType, machineProperties);
|
||||
this.properties.put(blockType, machineProperties);
|
||||
} else {
|
||||
Log.error("Null Definition found {}", Arrays.toString(blockTypes));
|
||||
}
|
||||
@@ -153,7 +153,7 @@ public class BlockBase<C extends Enum<C> & IBlockType & IStringSerializable> ext
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> list) {
|
||||
for (IMachineProperties definition : definitions.values()) {
|
||||
for (IMachineProperties definition : properties.values()) {
|
||||
definition.getSubBlocks(item, tab, list);
|
||||
}
|
||||
}
|
||||
@@ -253,7 +253,7 @@ public class BlockBase<C extends Enum<C> & IBlockType & IStringSerializable> ext
|
||||
}
|
||||
|
||||
public void init() {
|
||||
for (IMachineProperties def : definitions.values()) {
|
||||
for (IMachineProperties def : properties.values()) {
|
||||
def.registerTileEntity();
|
||||
}
|
||||
}
|
||||
@@ -262,7 +262,7 @@ public class BlockBase<C extends Enum<C> & IBlockType & IStringSerializable> ext
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
for (IMachineProperties def : definitions.values()) {
|
||||
for (IMachineProperties def : properties.values()) {
|
||||
def.registerModel(item, manager);
|
||||
}
|
||||
}
|
||||
@@ -270,7 +270,7 @@ public class BlockBase<C extends Enum<C> & IBlockType & IStringSerializable> ext
|
||||
/* STATES */
|
||||
@Override
|
||||
public void registerStateMapper() {
|
||||
Proxies.render.registerStateMapper(this, new StateMapperMachine<>(machinePropertiesClass, TYPE, FACE));
|
||||
Proxies.render.registerStateMapper(this, new MachineStateMapper<>(machinePropertiesClass, TYPE, FACE));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -289,10 +289,10 @@ public class BlockBase<C extends Enum<C> & IBlockType & IStringSerializable> ext
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
for(Map.Entry<C, IMachineProperties> entry : definitions.entrySet()){
|
||||
for(Map.Entry<P, IMachineProperties> entry : properties.entrySet()){
|
||||
IMachineProperties<?> machineProperties = entry.getValue();
|
||||
if (machineProperties.getMeta() == meta){
|
||||
C blockType = entry.getKey();
|
||||
P blockType = entry.getKey();
|
||||
return getDefaultState().withProperty(this.TYPE, blockType);
|
||||
}
|
||||
}
|
||||
@@ -326,7 +326,7 @@ public class BlockBase<C extends Enum<C> & IBlockType & IStringSerializable> ext
|
||||
return hasTESR;
|
||||
}
|
||||
|
||||
public final ItemStack get(C type) {
|
||||
public final ItemStack get(P type) {
|
||||
return new ItemStack(this, 1, type.getMachineProperties().getMeta());
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.blocks;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -41,6 +43,6 @@ public enum BlockTypeCoreTesr implements IBlockTypeTesr {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name();
|
||||
return getMachineProperties().getName();
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.particle.EntityFX;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
@@ -30,10 +31,12 @@ import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import forestry.api.core.IItemModelRegister;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.core.entities.EntityFXColoredDropParticle;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
|
||||
public class BlockForestryFluid extends BlockFluidClassic {
|
||||
public class BlockForestryFluid extends BlockFluidClassic implements IItemModelRegister {
|
||||
|
||||
private final boolean flammable;
|
||||
private final int flammability;
|
||||
@@ -135,6 +138,12 @@ public class BlockForestryFluid extends BlockFluidClassic {
|
||||
return super.getMaterial();
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
|
||||
|
||||
@@ -74,9 +74,9 @@ public class ItemCrated extends ItemForestry {
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
if(contained == null){
|
||||
manager.registerItemModel(item, 0, false);
|
||||
manager.registerItemModel(item, 1, "crate-filled");
|
||||
}else{
|
||||
String modID = ItemStackUtil.getItemNameFromRegistry(item).getResourceDomain();
|
||||
ModelResourceLocation modelLocation = new ModelResourceLocation(modID + ":crates", StringUtil.cleanItemName(item));
|
||||
ModelResourceLocation modelLocation = new ModelResourceLocation("forestry:crate-filled", StringUtil.cleanItemName(item));
|
||||
ModelLoader.setCustomModelResourceLocation(item, 0, modelLocation);
|
||||
ModelBakery.registerItemVariants(item, modelLocation);
|
||||
}
|
||||
|
||||
@@ -10,208 +10,275 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.models;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.block.model.ModelBlock;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.util.EnumWorldBlockLayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.ServerStatusResponse.MinecraftProtocolVersionIdentifier;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.ICustomModelLoader;
|
||||
import net.minecraftforge.client.ItemModelMesherForge;
|
||||
import net.minecraftforge.client.model.IFlexibleBakedModel;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.IModelCustomData;
|
||||
import net.minecraftforge.client.model.IModelState;
|
||||
import net.minecraftforge.client.model.IPerspectiveAwareModel;
|
||||
import net.minecraftforge.client.model.ISmartItemModel;
|
||||
import net.minecraftforge.client.model.ItemLayerModel;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.client.model.ModelStateComposition;
|
||||
import net.minecraftforge.client.model.MultiLayerModel;
|
||||
import net.minecraftforge.client.model.TRSRTransformation;
|
||||
import net.minecraftforge.client.model.MultiModel;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import forestry.core.utils.Log;
|
||||
public class ModelCrate implements IModelCustomData<ModelCrate> {
|
||||
public static final ModelCrate instance = new ModelCrate("cratedStone", "forestry", new ModelResourceLocation("forestry:crates", "cratedStone"), false);
|
||||
|
||||
private final String containedUID;
|
||||
private final String modID;
|
||||
private final ResourceLocation containedLocation;
|
||||
private final boolean isContainedItem;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import forestry.core.items.ItemCrated;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.plugins.PluginStorage;
|
||||
import gnu.trove.map.hash.TIntObjectHashMap;
|
||||
public class ModelCrate implements ISmartItemModel {
|
||||
|
||||
private HashMap<String, MultiModel.Baked> crates = Maps.newHashMap();
|
||||
|
||||
public static IModel crateModel;
|
||||
private final Function<ResourceLocation, TextureAtlasSprite> textureGetter;
|
||||
public static ModelBlock MODEL_GENERATED;
|
||||
public static ModelBlock MODEL_COMPASS;
|
||||
public static ModelBlock MODEL_CLOCK;
|
||||
public static ModelLoader loader;
|
||||
|
||||
public ModelCrate() {
|
||||
textureGetter = new Function<ResourceLocation, TextureAtlasSprite>() {
|
||||
public TextureAtlasSprite apply(ResourceLocation location) {
|
||||
return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param baseLocation The location of the crate model
|
||||
* @param UID The UID of the crate
|
||||
* @param modID The modId of the creat item
|
||||
* @param containedLocation The location of the model from the contained item
|
||||
* To bake the contained model
|
||||
*/
|
||||
private ModelCrate(String UID, String modID, ResourceLocation containedLocation, boolean isContainedItem){
|
||||
this.containedUID = UID;
|
||||
this.modID = modID;
|
||||
this.containedLocation = containedLocation;
|
||||
this.isContainedItem = isContainedItem;
|
||||
}
|
||||
private ImmutableMap<String, IFlexibleBakedModel> bakeModels(ItemCrated crated){
|
||||
ImmutableMap.Builder<String, IFlexibleBakedModel> pb = ImmutableMap.builder();
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getDependencies() {
|
||||
return ImmutableList.<ResourceLocation>of(new ModelResourceLocation("forestry:crates", "crate"), containedLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures(){
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param loc The location of the model
|
||||
* @return A model from the {@link ModelLoaderRegistry}
|
||||
*/
|
||||
private static IModel getModel(ResourceLocation loc){
|
||||
IModel model;
|
||||
try{
|
||||
model = ModelLoaderRegistry.getModel(loc);
|
||||
}
|
||||
catch (IOException e){
|
||||
Log.logThrowable("Couldn't load Crate Model dependency: %s", e, loc);
|
||||
model = ModelLoaderRegistry.getMissingModel();
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* To bake the base and the contained model
|
||||
*/
|
||||
private static ImmutableMap<Optional<EnumWorldBlockLayer>, IFlexibleBakedModel> buildModels(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter, ModelCrate modelToBake){
|
||||
ImmutableMap.Builder<Optional<EnumWorldBlockLayer>, IFlexibleBakedModel> builder = ImmutableMap.builder();
|
||||
IFlexibleBakedModel flexModel = getModel(crated.getContained());
|
||||
|
||||
IModel base = getModel(new ModelResourceLocation("forestry:crates", "crate"));
|
||||
IFlexibleBakedModel baseBaked = base.bake(new ModelStateComposition(state, base.getDefaultState()), format, bakedTextureGetter);
|
||||
IdentityHashMap<Item, TIntObjectHashMap<ModelResourceLocation>> modelResourceLocations = ObfuscationReflectionHelper.getPrivateValue(ItemModelMesherForge.class, (ItemModelMesherForge)Minecraft.getMinecraft().getRenderItem().getItemModelMesher(), 0);
|
||||
|
||||
//Set the crate color index to 100
|
||||
for(BakedQuad quad : baseBaked.getGeneralQuads()){
|
||||
ObfuscationReflectionHelper.setPrivateValue(BakedQuad.class, quad, 100, 1);
|
||||
}
|
||||
builder.put(Optional.<EnumWorldBlockLayer>absent(), baseBaked);
|
||||
builder.put(Optional.of(EnumWorldBlockLayer.SOLID), baseBaked);
|
||||
|
||||
|
||||
ModelResourceLocation modelResource = modelResourceLocations.get(crated.getContained().getItem()).get(crated.getContained().getItemDamage());
|
||||
ResourceLocation location = getItemLocation(modelResource);
|
||||
|
||||
IModel content = getModel(modelToBake.containedLocation);
|
||||
if(modelToBake.isContainedItem){
|
||||
builder.put(Optional.of(EnumWorldBlockLayer.CUTOUT), new TRSRBakedModel(content.bake(state, format, bakedTextureGetter), -0.0625F, 0, 0.0625F, 0.5F));
|
||||
builder.put(Optional.of(EnumWorldBlockLayer.CUTOUT_MIPPED), new TRSRBakedModel(content.bake(state, format, bakedTextureGetter), -0.0625F, 0, -0.0625F, 0.5F));
|
||||
if(hasItemModel(location)){
|
||||
pb.put(String.valueOf(0), new TRSRBakedModel(flexModel, -0.0625F, 0, 0.0625F, 0.5F));
|
||||
pb.put(String.valueOf(1), new TRSRBakedModel(flexModel, -0.0625F, 0, -0.0625F, 0.5F));
|
||||
}else{
|
||||
builder.put(Optional.of(EnumWorldBlockLayer.CUTOUT), new TRSRBakedModel(content.bake(state, format, bakedTextureGetter), -0.0625F, 0, 0, 0.5F));
|
||||
pb.put(String.valueOf(0), new TRSRBakedModel(flexModel, -0.0625F, 0, 0, 0.5F));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Bake the crate model and the content of the crate
|
||||
*/
|
||||
@Override
|
||||
public IFlexibleBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter){
|
||||
IModel missing = ModelLoaderRegistry.getMissingModel();
|
||||
return new MultiLayerModel.MultiLayerBakedModel(
|
||||
buildModels(state, format, bakedTextureGetter, this),
|
||||
missing.bake(missing.getDefaultState(), format, bakedTextureGetter),
|
||||
format,
|
||||
IPerspectiveAwareModel.MapWrapper.getTransforms(state)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelState getDefaultState(){
|
||||
return TRSRTransformation.identity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a crate model from the customData
|
||||
*/
|
||||
@Override
|
||||
public IModel process(ImmutableMap<String, String> customData){
|
||||
ResourceLocation location = null;
|
||||
String UID = "";
|
||||
boolean isContainedItem = false;
|
||||
String modID = "";
|
||||
for(String key : customData.keySet()){
|
||||
if("uid".equals(key)){
|
||||
UID = getString(customData.get(key));
|
||||
}
|
||||
else if("modID".equals(key)){
|
||||
modID = getString(customData.get(key));
|
||||
}
|
||||
else if("location".equals(key)){
|
||||
location = getLocation(customData.get(key));
|
||||
}
|
||||
else if("isItem".equals(key)){
|
||||
isContainedItem = getBoolean(customData.get(key));
|
||||
}
|
||||
}
|
||||
if(modID == null || modID.equals("")){
|
||||
modID = "forestry";
|
||||
}
|
||||
if(location == null || UID == null || UID.equals("")) {
|
||||
return instance;
|
||||
}
|
||||
return new ModelCrate(UID, modID, location, isContainedItem);
|
||||
}
|
||||
|
||||
private ResourceLocation getLocation(String json){
|
||||
JsonElement e = new JsonParser().parse(json);
|
||||
if(e.isJsonPrimitive() && e.getAsJsonPrimitive().isString()){
|
||||
if(e.getAsString().contains("#")){
|
||||
return new ModelResourceLocation(e.getAsString());
|
||||
}else{
|
||||
return new ResourceLocation(e.getAsString());
|
||||
}
|
||||
}
|
||||
return new ModelResourceLocation("builtin/missing", "missing");
|
||||
return pb.build();
|
||||
}
|
||||
|
||||
private String getString(String json){
|
||||
JsonElement e = new JsonParser().parse(json);
|
||||
if(e.isJsonPrimitive() && e.getAsJsonPrimitive().isString()){
|
||||
return e.getAsString();
|
||||
}
|
||||
return null;
|
||||
/**
|
||||
* @return The item model {@link ResourceLocation} from the {@link ModelResourceLocation}
|
||||
*/
|
||||
private ResourceLocation getItemLocation(ModelResourceLocation modelResource){
|
||||
ResourceLocation resourcelocation = new ResourceLocation(modelResource.toString().replaceAll("#.*", ""));
|
||||
return new ResourceLocation(resourcelocation.getResourceDomain(), "item/" + resourcelocation.getResourcePath());
|
||||
}
|
||||
|
||||
private boolean getBoolean(String json){
|
||||
JsonElement e = new JsonParser().parse(json);
|
||||
if(e.isJsonPrimitive() && e.getAsJsonPrimitive().isBoolean()){
|
||||
return e.getAsBoolean();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The model loader to load crate models from the blockstate file
|
||||
* @return Return true, when the model from the {@link ResourceLocation} a item model is
|
||||
*/
|
||||
public static enum Loader implements ICustomModelLoader{
|
||||
instance;
|
||||
private boolean hasItemModel(ResourceLocation location){
|
||||
try{
|
||||
ModelBlock p_177581_1_ = loadModel(location);
|
||||
if (p_177581_1_ == null){
|
||||
return false;
|
||||
}else{
|
||||
ModelBlock modelblock = p_177581_1_.getRootModel();
|
||||
return modelblock == MODEL_GENERATED || modelblock == MODEL_COMPASS || modelblock == MODEL_CLOCK;
|
||||
}
|
||||
}catch(Exception e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected ModelBlock loadModel(ResourceLocation p_177594_1_) throws IOException
|
||||
{
|
||||
String s = p_177594_1_.getResourcePath();
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {}
|
||||
|
||||
@Override
|
||||
public boolean accepts(ResourceLocation modelLocation){
|
||||
return modelLocation.getResourceDomain().equals("forestry") &&
|
||||
modelLocation.getResourcePath().equals("models/block/crate");
|
||||
if ("builtin/generated".equals(s))
|
||||
{
|
||||
return MODEL_GENERATED;
|
||||
}
|
||||
else if ("builtin/compass".equals(s))
|
||||
{
|
||||
return MODEL_COMPASS;
|
||||
}
|
||||
else if ("builtin/clock".equals(s))
|
||||
{
|
||||
return MODEL_CLOCK;
|
||||
}
|
||||
else
|
||||
{
|
||||
Reader reader;
|
||||
|
||||
@Override
|
||||
public IModel loadModel(ResourceLocation modelLocation){
|
||||
return ModelCrate.instance;
|
||||
if (s.startsWith("builtin/"))
|
||||
{
|
||||
String s1 = s.substring("builtin/".length());
|
||||
if(s1.equals("missing")){
|
||||
reader = new StringReader("{ \"textures\": { \"particle\": \"missingno\", \"missingno\": \"missingno\"}, \"elements\": [ { \"from\": [ 0, 0, 0 ], \"to\": [ 16, 16, 16 ], \"faces\": { \"down\": { \"uv\": [ 0, 0, 16, 16 ], \"cullface\": \"down\", \"texture\": \"#missingno\" }, \"up\": { \"uv\": [ 0, 0, 16, 16 ], \"cullface\": \"up\", \"texture\": \"#missingno\" }, \"north\": { \"uv\": [ 0, 0, 16, 16 ], \"cullface\": \"north\", \"texture\": \"#missingno\" }, \"south\": { \"uv\": [ 0, 0, 16, 16 ], \"cullface\": \"south\", \"texture\": \"#missingno\" }, \"west\": { \"uv\": [ 0, 0, 16, 16 ], \"cullface\": \"west\", \"texture\": \"#missingno\" }, \"east\": { \"uv\": [ 0, 0, 16, 16 ], \"cullface\": \"east\", \"texture\": \"#missingno\" } }}]}");
|
||||
}
|
||||
else{
|
||||
throw new FileNotFoundException(p_177594_1_.toString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(this.getModelLocation(p_177594_1_));
|
||||
reader = new InputStreamReader(iresource.getInputStream(), Charsets.UTF_8);
|
||||
}
|
||||
|
||||
ModelBlock model;
|
||||
|
||||
try
|
||||
{
|
||||
ModelBlock modelblock = ModelBlock.deserialize(reader);
|
||||
modelblock.name = p_177594_1_.toString();
|
||||
model = modelblock;
|
||||
}
|
||||
finally
|
||||
{
|
||||
reader.close();
|
||||
}
|
||||
|
||||
if(model != null && model.getParentLocation() != null){
|
||||
if(model.getParentLocation().getResourcePath().equals("builtin/generated"))
|
||||
{
|
||||
model.parent = MODEL_GENERATED;
|
||||
}
|
||||
else
|
||||
{
|
||||
try{
|
||||
model.parent = loadModel(model.getParentLocation());
|
||||
}catch (IOException e){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
protected ResourceLocation getModelLocation(ResourceLocation p_177580_1_)
|
||||
{
|
||||
return new ResourceLocation(p_177580_1_.getResourceDomain(), "models/" + p_177580_1_.getResourcePath() + ".json");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The baked model from the filled crate
|
||||
*/
|
||||
private IFlexibleBakedModel getModel(ItemStack stack){
|
||||
IBakedModel model = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(stack);
|
||||
if(model == null) {
|
||||
return null;
|
||||
}
|
||||
else if(model instanceof IFlexibleBakedModel) {
|
||||
return (IFlexibleBakedModel) model;
|
||||
}
|
||||
else {
|
||||
return new IFlexibleBakedModel.Wrapper(model, DefaultVertexFormats.ITEM);
|
||||
}
|
||||
}
|
||||
|
||||
private IFlexibleBakedModel getModelCrate(){
|
||||
IFlexibleBakedModel flexModel;
|
||||
IBakedModel model = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(new ItemStack(PluginStorage.items.crate, 1, 1));
|
||||
if(model == null) {
|
||||
return null;
|
||||
}
|
||||
else if(model instanceof IFlexibleBakedModel) {
|
||||
flexModel = (IFlexibleBakedModel) model;
|
||||
}
|
||||
else {
|
||||
flexModel = new IFlexibleBakedModel.Wrapper(model, DefaultVertexFormats.ITEM);
|
||||
}
|
||||
return crateModel.bake(crateModel.getDefaultState(), flexModel.getFormat(), textureGetter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getFaceQuads(EnumFacing facing) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getGeneralQuads() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleTexture() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemCameraTransforms getItemCameraTransforms() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bake the crated model
|
||||
*/
|
||||
@Override
|
||||
public IBakedModel handleItemState(ItemStack stack) {
|
||||
ItemCrated crated = (ItemCrated) stack.getItem();
|
||||
String crateUID = StringUtil.cleanItemName(crated);
|
||||
if(crates.get(crateUID) == null){
|
||||
IFlexibleBakedModel baseBaked = getModelCrate();
|
||||
|
||||
//Set the crate color index to 100
|
||||
for(BakedQuad quad : baseBaked.getGeneralQuads()){
|
||||
ObfuscationReflectionHelper.setPrivateValue(BakedQuad.class, quad, 100, 1);
|
||||
}
|
||||
crates.put(crateUID, new MultiModel.Baked(baseBaked, bakeModels(crated)));
|
||||
}
|
||||
return crates.get(crateUID);
|
||||
}
|
||||
}
|
||||
@@ -10,15 +10,15 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.models;
|
||||
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
|
||||
public class ModelIndex {
|
||||
|
||||
public final ModelResourceLocation modelLocation;
|
||||
public final IModel model;
|
||||
|
||||
public ModelIndex(ModelResourceLocation modelLocation, IModel model) {
|
||||
public final IBakedModel model;
|
||||
|
||||
public ModelIndex(ModelResourceLocation modelLocation, IBakedModel model) {
|
||||
this.modelLocation = modelLocation;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@@ -83,9 +83,6 @@ public class ModelManager implements IModelManager {
|
||||
if (block instanceof IItemModelRegister) {
|
||||
((IItemModelRegister) block).registerModel(Item.getItemFromBlock(block), getInstance());
|
||||
}
|
||||
if (block instanceof IStateMapperRegister) {
|
||||
((IStateMapperRegister) block).registerStateMapper();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ public class RenderHandler {
|
||||
public static void registerModels(ModelBakeEvent event) {
|
||||
IRegistry registry = event.modelRegistry;
|
||||
for (final BlockModelIndex index : blockModels) {
|
||||
Object o = registry.getObject(index.blockModelLocation);
|
||||
registry.putObject(index.blockModelLocation, index.model);
|
||||
registry.putObject(index.itemModelLocation, index.model);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.client.model.b3d.B3DLoader;
|
||||
import forestry.core.fluids.Fluids;
|
||||
import forestry.core.models.BlockModelIndex;
|
||||
import forestry.core.models.ModelIndex;
|
||||
@@ -90,8 +90,12 @@ public class ProxyRender {
|
||||
|
||||
public void bindTexture(ResourceLocation location) {
|
||||
}
|
||||
|
||||
public void registerModels() {
|
||||
}
|
||||
|
||||
public void registerLoaders(){
|
||||
}
|
||||
|
||||
/* FX */
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import net.minecraft.client.renderer.block.statemap.IStateMapper;
|
||||
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -29,6 +30,8 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.b3d.B3DLoader;
|
||||
import net.minecraftforge.client.model.obj.OBJLoader;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
|
||||
import forestry.apiculture.entities.EntityFXBee;
|
||||
@@ -150,12 +153,19 @@ public class ProxyRenderClient extends ProxyRender {
|
||||
return fluidLocation;
|
||||
}
|
||||
});
|
||||
ModelBakery.registerItemVariants(Item.getItemFromBlock(block), fluidLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStateMapper(Block block, IStateMapper mapper) {
|
||||
ModelLoader.setCustomStateMapper(block, mapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerLoaders(){
|
||||
B3DLoader.instance.addDomain(Constants.ID);
|
||||
OBJLoader.instance.addDomain(Constants.ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerModels() {
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.statemap.IStateMapper;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
|
||||
public abstract class StateMapperForestry implements IStateMapper {
|
||||
public abstract class ForestryStateMapper implements IStateMapper {
|
||||
|
||||
protected Map<IBlockState, ModelResourceLocation> mapStateModelLocations = Maps.newLinkedHashMap();
|
||||
|
||||
+11
-10
@@ -1,6 +1,7 @@
|
||||
package forestry.core.render;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
@@ -17,30 +18,30 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class StateMapperMachine<C extends Enum<C> & IBlockType & IStringSerializable> extends StateMapperForestry {
|
||||
public class MachineStateMapper<T extends Enum<T> & IBlockType & IStringSerializable> extends ForestryStateMapper {
|
||||
|
||||
private final Class<C> clazz;
|
||||
private final PropertyEnum<C> META;
|
||||
private final Class<T> machinePropertiesClass;
|
||||
private final PropertyEnum<T> META;
|
||||
private final PropertyEnum<EnumFacing> FACE;
|
||||
|
||||
public StateMapperMachine(Class<C> clazz, PropertyEnum<C> META, PropertyEnum<EnumFacing> FACE) {
|
||||
this.clazz = clazz;
|
||||
public MachineStateMapper(Class<T> machinePropertiesClass, PropertyEnum<T> META, PropertyEnum<EnumFacing> FACE) {
|
||||
this.machinePropertiesClass = machinePropertiesClass;
|
||||
this.META = META;
|
||||
this.FACE = FACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<IBlockState, ModelResourceLocation> putStateModelLocations(Block block) {
|
||||
for (C definition : clazz.getEnumConstants()) {
|
||||
if (definition instanceof IMachinePropertiesTesr)
|
||||
for (T type : machinePropertiesClass.getEnumConstants()) {
|
||||
if (type.getMachineProperties() instanceof IMachinePropertiesTesr)
|
||||
continue;
|
||||
for (EnumFacing facing : EnumFacing.values()) {
|
||||
if (facing == EnumFacing.DOWN || facing == EnumFacing.UP)
|
||||
continue;
|
||||
IBlockState state = block.getDefaultState().withProperty(META, definition).withProperty(FACE, facing);
|
||||
IBlockState state = block.getDefaultState().withProperty(META, type).withProperty(FACE, facing);
|
||||
LinkedHashMap linkedhashmap = Maps.newLinkedHashMap(state.getProperties());
|
||||
ResourceLocation RL = Block.blockRegistry.getNameForObject(block);
|
||||
String s = String.format("%s:%s", RL.getResourceDomain(), RL.getResourcePath() + "_" + META.getName((C) linkedhashmap.remove(META)));
|
||||
ResourceLocation blockLocation = Block.blockRegistry.getNameForObject(block);
|
||||
String s = String.format("%s:%s", blockLocation.getResourceDomain(), blockLocation.getResourcePath() + "_" + META.getName((T) linkedhashmap.remove(META)));
|
||||
mapStateModelLocations.put(state, new ModelResourceLocation(s, getPropertyString(linkedhashmap)));
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.energy.blocks;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
@@ -46,6 +48,6 @@ public enum BlockTypeEngine implements IBlockTypeTesr {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name();
|
||||
return getMachineProperties().getName();
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.factory.blocks;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.core.blocks.IBlockType;
|
||||
@@ -42,6 +44,6 @@ public enum BlockTypeFactoryPlain implements IBlockType {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name();
|
||||
return getMachineProperties().getName();
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.factory.blocks;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -62,6 +64,6 @@ public enum BlockTypeFactoryTesr implements IBlockTypeTesr {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name();
|
||||
return getMachineProperties().getName();
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.lepidopterology.blocks;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -48,6 +50,6 @@ public enum BlockTypeLepidopterologyTesr implements IBlockTypeTesr {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name();
|
||||
return getMachineProperties().getName();
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,20 @@
|
||||
******************************************************************************/
|
||||
package forestry.lepidopterology.proxy;
|
||||
|
||||
import forestry.core.models.ModelIndex;
|
||||
import forestry.core.models.ModelManager;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.lepidopterology.entities.EntityButterfly;
|
||||
import forestry.lepidopterology.render.ModelButterflyItem;
|
||||
import forestry.lepidopterology.render.RenderButterflyEntity;
|
||||
import forestry.plugins.PluginLepidopterology;
|
||||
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
||||
|
||||
public class ProxyLepidopterologyClient extends ProxyLepidopterology {
|
||||
|
||||
@Override
|
||||
public void initializeRendering() {
|
||||
/*RenderingRegistry.registerEntityRenderingHandler(EntityButterfly.class, new RenderButterflyEntity());
|
||||
MinecraftForgeClient.registerItemRenderer(PluginLepidopterology.items.butterflyGE, new RenderButterflyItem());*/
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityButterfly.class, new RenderButterflyEntity());
|
||||
//Proxies.render.registerModel(new ModelIndex(ModelManager.getInstance().getModelLocation(PluginLepidopterology.items.butterflyGE, "butterflyGE"), new ModelButterflyItem()));
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,10 @@ import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import forestry.api.lepidopterology.ButterflyManager;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.core.models.ModelManager;
|
||||
import forestry.core.models.TRSRBakedModel;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.plugins.PluginLepidopterology;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
@@ -37,8 +40,9 @@ public class ModelButterflyItem implements ISmartItemModel {
|
||||
public IRetexturableModel modelButterfly;
|
||||
public ResourceLocation location;
|
||||
|
||||
public ModelButterflyItem(ResourceLocation location) {
|
||||
this.location = location;
|
||||
public ModelButterflyItem() {
|
||||
this.location = new ResourceLocation("forestry:item/butterflyGE.b3d");
|
||||
//this.location = new ResourceLocation("forestry:item/butterflyGE.obj");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,20 +82,23 @@ public class ModelButterflyItem implements ISmartItemModel {
|
||||
|
||||
@Override
|
||||
public IBakedModel handleItemState(ItemStack item) {
|
||||
try {
|
||||
modelButterfly = (IRetexturableModel) ModelLoaderRegistry.getModel(location);
|
||||
} catch (IOException e) {
|
||||
Log.warning(
|
||||
"Failed to find Butterfly Model for (" + location.toString() + ") in the Forestry registry.");
|
||||
if(modelButterfly == null){
|
||||
try {
|
||||
modelButterfly = (IRetexturableModel) ModelLoaderRegistry.getModel(location);
|
||||
} catch (IOException e) {
|
||||
Log.warning(
|
||||
"Failed to find Butterfly Model for (" + location.toString() + ") in the Forestry registry.");
|
||||
}
|
||||
if (modelButterfly == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
IButterfly butterfly = ButterflyManager.butterflyRoot.getMember(item);
|
||||
if (modelButterfly == null) {
|
||||
return null;
|
||||
}
|
||||
if (butterfly == null) {
|
||||
butterfly = ButterflyManager.butterflyRoot.templateAsIndividual(ButterflyManager.butterflyRoot.getDefaultTemplate());
|
||||
}
|
||||
return bakeModel(butterfly);
|
||||
//return bakeModel(butterfly);
|
||||
}
|
||||
|
||||
public IBakedModel bakeModel(IButterfly butterfly) {
|
||||
@@ -103,8 +110,9 @@ public class ModelButterflyItem implements ISmartItemModel {
|
||||
};
|
||||
ImmutableMap.Builder<String, String> textures = ImmutableMap.builder();
|
||||
textures.put("#ButterflyGE", butterfly.getGenome().getSecondary().getEntityTexture().toString().replace(".png", "").replace("textures/", ""));
|
||||
textures.put("Butterfly2texture", butterfly.getGenome().getSecondary().getEntityTexture().toString().replace(".png", "").replace("textures/", ""));
|
||||
modelButterfly = (IRetexturableModel) modelButterfly.retexture(textures.build());
|
||||
return modelButterfly.bake(ModelRotation.X270_Y90, DefaultVertexFormats.ITEM, textureGetter);
|
||||
return new TRSRBakedModel(modelButterfly.bake(ModelRotation.X0_Y0, DefaultVertexFormats.ITEM, textureGetter), -0.5F, -1.5F, 1.5F, 0, (float)Math.PI * 2, 0, 1F);
|
||||
}
|
||||
|
||||
public static float getIrregularWingYaw(long flapping, float flap) {
|
||||
|
||||
@@ -45,6 +45,6 @@ public enum BlockTypeMail implements IBlockType {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name();
|
||||
return getMachineProperties().getName();
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,7 @@ import forestry.core.models.RenderHandler;
|
||||
import forestry.core.multiblock.MultiblockLogicFactory;
|
||||
import forestry.core.network.IPacketRegistry;
|
||||
import forestry.core.network.PacketRegistryCore;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.recipes.RecipeUtil;
|
||||
import forestry.core.utils.ClimateUtil;
|
||||
import forestry.core.utils.ForestryModEnvWarningCallable;
|
||||
|
||||
@@ -12,6 +12,7 @@ package forestry.plugins;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -35,17 +36,27 @@ import net.minecraft.block.BlockTrapDoor;
|
||||
import net.minecraft.block.BlockWall;
|
||||
import net.minecraft.block.BlockWorkbench;
|
||||
import net.minecraft.block.IGrowable;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemDoor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||
import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.common.IPlantable;
|
||||
import net.minecraftforge.common.IShearable;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import forestry.Forestry;
|
||||
@@ -60,6 +71,8 @@ import forestry.core.config.Constants;
|
||||
import forestry.core.config.LocalizedConfiguration;
|
||||
import forestry.core.fluids.Fluids;
|
||||
import forestry.core.items.ItemCrated;
|
||||
import forestry.core.models.ModelCrate;
|
||||
import forestry.core.models.RenderHandler;
|
||||
import forestry.core.recipes.RecipeUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.Log;
|
||||
@@ -74,7 +87,6 @@ import forestry.storage.CrateRegistry;
|
||||
import forestry.storage.PickupHandlerStorage;
|
||||
import forestry.storage.ResupplyHandler;
|
||||
import forestry.storage.items.ItemRegistryStorage;
|
||||
import forestry.storage.proxy.ProxyStorage;
|
||||
|
||||
@Plugin(pluginID = "Storage", name = "Storage", author = "SirSengir", url = Constants.URL, unlocalizedDescription = "for.plugin.storage.description")
|
||||
public class PluginStorage extends ForestryPlugin {
|
||||
@@ -82,8 +94,6 @@ public class PluginStorage extends ForestryPlugin {
|
||||
private static final List<ItemCrated> crates = new ArrayList<>();
|
||||
private static final String CONFIG_CATEGORY = "backpacks";
|
||||
|
||||
@SidedProxy(clientSide = "forestry.storage.proxy.ProxyStorageClient", serverSide = "forestry.storage.proxy.ProxyStorage")
|
||||
public static ProxyStorage proxy;
|
||||
private final ArrayList<ItemStack> minerItems = new ArrayList<>();
|
||||
private final ArrayList<ItemStack> diggerItems = new ArrayList<>();
|
||||
private final ArrayList<ItemStack> foresterItems = new ArrayList<>();
|
||||
@@ -141,7 +151,6 @@ public class PluginStorage extends ForestryPlugin {
|
||||
definition = new BackpackDefinition("builder", new Color(0xdd3a3a).getRGB());
|
||||
BackpackManager.definitions.put(definition.getKey(), definition);
|
||||
|
||||
proxy.registerCrateModelLoader();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -160,6 +169,11 @@ public class PluginStorage extends ForestryPlugin {
|
||||
protected void registerItemsAndBlocks() {
|
||||
items = new ItemRegistryStorage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void preInit() {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit() {
|
||||
@@ -561,4 +575,18 @@ public class PluginStorage extends ForestryPlugin {
|
||||
'W', wovenSilk,
|
||||
'T', backpackT1);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void onBakeModel(ModelBakeEvent event) {
|
||||
try {
|
||||
ModelCrate.crateModel = ModelLoaderRegistry.getModel(new ModelResourceLocation("forestry:crate-filled", "inventory"));
|
||||
ModelCrate.MODEL_GENERATED = ObfuscationReflectionHelper.getPrivateValue(ModelBakery.class, event.modelLoader, 14);
|
||||
ModelCrate.MODEL_COMPASS = ObfuscationReflectionHelper.getPrivateValue(ModelBakery.class, event.modelLoader, 15);
|
||||
ModelCrate.MODEL_CLOCK = ObfuscationReflectionHelper.getPrivateValue(ModelBakery.class, event.modelLoader, 16);
|
||||
ModelCrate.loader = event.modelLoader;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,11 +11,15 @@
|
||||
package forestry.storage;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import forestry.api.storage.ICrateRegistry;
|
||||
import forestry.core.items.ItemCrated;
|
||||
import forestry.core.models.ModelCrate;
|
||||
import forestry.core.models.ModelIndex;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.plugins.PluginStorage;
|
||||
@@ -36,6 +40,7 @@ public class CrateRegistry implements ICrateRegistry {
|
||||
ItemCrated crate = new ItemCrated(stack, useOreDict);
|
||||
crate.setUnlocalizedName(uid);
|
||||
GameRegistry.registerItem(crate, StringUtil.cleanItemName(crate));
|
||||
Proxies.render.registerModel(new ModelIndex(new ModelResourceLocation("forestry:crate-filled", StringUtil.cleanItemName(crate)), new ModelCrate()));
|
||||
PluginStorage.registerCrate(crate);
|
||||
}
|
||||
|
||||
|
||||
@@ -232,9 +232,6 @@ public class ItemBackpack extends ItemWithGui {
|
||||
@SideOnly(Side.CLIENT)
|
||||
private ModelResourceLocation[] models;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static int i = 0;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
@@ -245,13 +242,10 @@ public class ItemBackpack extends ItemWithGui {
|
||||
models[1] = new ModelResourceLocation("forestry:" + typeTag + "_locked", "inventory");
|
||||
models[2] = new ModelResourceLocation("forestry:" + typeTag + "_receive", "inventory");
|
||||
models[3] = new ModelResourceLocation("forestry:" + typeTag + "_resupply", "inventory");
|
||||
if (i == 0 && (type == EnumBackpackType.T1 || type == EnumBackpackType.APIARIST) || i == 1 && type == EnumBackpackType.T2) {
|
||||
manager.registerVariant(item, new ResourceLocation("forestry:" + typeTag + "_neutral"));
|
||||
manager.registerVariant(item, new ResourceLocation("forestry:" + typeTag + "_locked"));
|
||||
manager.registerVariant(item, new ResourceLocation("forestry:" + typeTag + "_receive"));
|
||||
manager.registerVariant(item, new ResourceLocation("forestry:" + typeTag + "_resupply"));
|
||||
i++;
|
||||
}
|
||||
manager.registerVariant(item, new ResourceLocation("forestry:" + typeTag + "_neutral"));
|
||||
manager.registerVariant(item, new ResourceLocation("forestry:" + typeTag + "_locked"));
|
||||
manager.registerVariant(item, new ResourceLocation("forestry:" + typeTag + "_receive"));
|
||||
manager.registerVariant(item, new ResourceLocation("forestry:" + typeTag + "_resupply"));
|
||||
manager.registerItemModel(item, new BackpackMeshDefinition());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.storage.proxy;
|
||||
|
||||
public class ProxyStorage {
|
||||
|
||||
public void registerCrateModelLoader() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.storage.proxy;
|
||||
|
||||
import forestry.core.models.ModelCrate;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
|
||||
public class ProxyStorageClient extends ProxyStorage {
|
||||
|
||||
@Override
|
||||
public void registerCrateModelLoader() {
|
||||
ModelLoaderRegistry.registerLoader(ModelCrate.Loader.instance);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user