Skip to content
Permalink
Browse files

Fix Crate Models

  • Loading branch information
Nedelosk committed Feb 21, 2016
1 parent 48c8c01 commit 96170b5f2193fa182d8fa7f76b4b338d00df15c5
@@ -5,10 +5,6 @@
******************************************************************************/
package forestry.api.apiculture;

import java.util.ArrayList;

import net.minecraft.item.ItemStack;

import forestry.api.genetics.IFlowerRegistry;

public class FlowerManager {
@@ -9,7 +9,6 @@
import java.util.Random;

import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IStringSerializable;

public enum EnumWoodType implements IStringSerializable {
@@ -11,7 +11,6 @@
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import forestry.api.core.ITextureManager;
import forestry.api.genetics.IFruitFamily;

public interface IFruitProvider {
@@ -7,7 +7,6 @@

import java.util.Collection;

import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ResourceLocation;
@@ -5,8 +5,6 @@
******************************************************************************/
package forestry.api.genetics;

import java.util.Set;

import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
@@ -7,7 +7,6 @@

import javax.annotation.Nullable;

import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;

import net.minecraftforge.fluids.FluidStack;
@@ -19,7 +19,6 @@
import forestry.core.tiles.IActivatable;
import forestry.energy.EnergyManager;

import cofh.api.energy.IEnergyHandler;
import cofh.api.energy.IEnergyReceiver;

public abstract class TileAlvearyClimatiser extends TileAlveary implements IEnergyReceiver, IActivatable, IAlvearyComponent.Climatiser {
@@ -15,7 +15,6 @@
import forestry.api.core.IErrorLogicSource;
import forestry.core.errors.EnumErrorCode;
import forestry.core.triggers.Trigger;

import buildcraft.api.statements.IStatementContainer;
import buildcraft.api.statements.IStatementParameter;

@@ -81,5 +81,12 @@ public void registerModel(Item item, IModelManager manager) {
ModelBakery.registerItemVariants(item, modelLocation);
}
}

@Override
public int getColorFromItemStack(ItemStack stack, int renderPass) {
if(getContained() == null || renderPass == 100)
return super.getColorFromItemStack(stack, renderPass);
return getContained().getItem().getColorFromItemStack(getContained(), renderPass);
}

}
@@ -12,6 +12,7 @@

import java.io.IOException;
import java.util.Collection;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.resources.IResourceManager;
@@ -28,6 +29,7 @@
import net.minecraftforge.client.model.ModelStateComposition;
import net.minecraftforge.client.model.MultiLayerModel;
import net.minecraftforge.client.model.TRSRTransformation;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;

import com.google.common.base.Function;
import com.google.common.base.Optional;
@@ -38,32 +40,29 @@

import forestry.core.utils.Log;
public class ModelCrate implements IModelCustomData<ModelCrate> {
public static final ModelCrate instance = new ModelCrate(new ModelResourceLocation("forestry:crates", "crate"), EnumWorldBlockLayer.CUTOUT, "cratedStone", "forestry", new ModelResourceLocation("forestry:crates", "cratedStone"));
public static final ModelCrate instance = new ModelCrate("cratedStone", "forestry", new ModelResourceLocation("forestry:crates", "cratedStone"), false);

private final ModelResourceLocation baseLocation;
private final String containedUID;
private final String modID;
private final ResourceLocation containedLocation;
private final EnumWorldBlockLayer containedLayer;
private final boolean isContainedItem;

/**
* @param baseLocation The location of the crate model
* @param containedLayer The layer for the rendering from the contained item model
* @param UID The UID of the crate
* @param modID The modId of the creat item
* @param location The location of the model from the contained item
* @param containedLocation The location of the model from the contained item
*/
private ModelCrate(ModelResourceLocation baseLocation, EnumWorldBlockLayer containedLayer, String UID, String modID, ResourceLocation location){
this.baseLocation = baseLocation;
this.containedLayer = containedLayer;
private ModelCrate(String UID, String modID, ResourceLocation containedLocation, boolean isContainedItem){
this.containedUID = UID;
this.modID = modID;
this.containedLocation = location;
this.containedLocation = containedLocation;
this.isContainedItem = isContainedItem;
}

@Override
public Collection<ResourceLocation> getDependencies() {
return ImmutableList.<ResourceLocation>of(baseLocation, containedLocation);
return ImmutableList.<ResourceLocation>of(new ModelResourceLocation("forestry:crates", "crate"), containedLocation);
}

@Override
@@ -91,16 +90,28 @@ private static IModel getModel(ResourceLocation loc){
/**
* To bake the base and the contained model
*/
private static ImmutableMap<Optional<EnumWorldBlockLayer>, IFlexibleBakedModel> buildModels(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter, IModel crateModel, ModelCrate modelToBake){
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();

IModel base = getModel(modelToBake.baseLocation);
IModel base = getModel(new ModelResourceLocation("forestry:crates", "crate"));
IFlexibleBakedModel baseBaked = base.bake(new ModelStateComposition(state, base.getDefaultState()), format, bakedTextureGetter);

//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);




IModel content = getModel(modelToBake.containedLocation);
builder.put(Optional.of(modelToBake.containedLayer), content.bake(new ModelStateComposition(state, crateModel.getDefaultState()), format, bakedTextureGetter));
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));
}else{
builder.put(Optional.of(EnumWorldBlockLayer.CUTOUT), new TRSRBakedModel(content.bake(state, format, bakedTextureGetter), -0.0625F, 0, 0, 0.5F));
}
return builder.build();
}

@@ -110,18 +121,8 @@ private static IModel getModel(ResourceLocation loc){
@Override
public IFlexibleBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter){
IModel missing = ModelLoaderRegistry.getMissingModel();
IModel creat;
try {
creat = ModelLoaderRegistry.getModel(new ModelResourceLocation(modID + ":crates", containedUID));
} catch (IOException e) {
e.printStackTrace();
return missing.bake(state, format, bakedTextureGetter);
}
if(creat == null){
return missing.bake(state, format, bakedTextureGetter);
}
return new MultiLayerModel.MultiLayerBakedModel(
buildModels(state, format, bakedTextureGetter, creat, this),
buildModels(state, format, bakedTextureGetter, this),
missing.bake(missing.getDefaultState(), format, bakedTextureGetter),
format,
IPerspectiveAwareModel.MapWrapper.getTransforms(state)
@@ -138,17 +139,12 @@ public IModelState getDefaultState(){
*/
@Override
public IModel process(ImmutableMap<String, String> customData){
ImmutableMap.Builder<Optional<EnumWorldBlockLayer>, ModelResourceLocation> builder = ImmutableMap.builder();
ModelResourceLocation baseLocation = null;
ResourceLocation location = null;
String UID = "";
boolean isContainedItem = false;
String modID = "";
EnumWorldBlockLayer layer = null;
for(String key : customData.keySet()){
if("base".equals(key)){
baseLocation = (ModelResourceLocation) getLocation(customData.get(key));
}
else if("uid".equals(key)){
if("uid".equals(key)){
UID = getString(customData.get(key));
}
else if("modID".equals(key)){
@@ -157,23 +153,17 @@ else if("modID".equals(key)){
else if("location".equals(key)){
location = getLocation(customData.get(key));
}
else if("layer".equals(key)){
String layerName = getString(customData.get(key));
for(EnumWorldBlockLayer l : EnumWorldBlockLayer.values()){
if(l.toString().equals(layerName)){
layer = l;
break;
}
}
else if("isItem".equals(key)){
isContainedItem = getBoolean(customData.get(key));
}
}
if(modID == null){
if(modID == null || modID.equals("")){
modID = "forestry";
}
if(baseLocation == null || layer == null || location == null || UID == null) {
if(location == null || UID == null || UID.equals("")) {
return instance;
}
return new ModelCrate(baseLocation, layer, UID, modID, location);
return new ModelCrate(UID, modID, location, isContainedItem);
}

private ResourceLocation getLocation(String json){
@@ -195,6 +185,14 @@ private String getString(String json){
}
return null;
}

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

0 comments on commit 96170b5

Please sign in to comment.
You can’t perform that action at this time.