diff --git a/src/main/java/forestry/api/core/IModelBaker.java b/src/main/java/forestry/api/core/IModelBaker.java index 6c38a4954..00f998df8 100644 --- a/src/main/java/forestry/api/core/IModelBaker.java +++ b/src/main/java/forestry/api/core/IModelBaker.java @@ -24,19 +24,15 @@ import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public interface IModelBaker { - void setRenderBounds(AxisAlignedBB renderBounds); - - void setRenderBounds(double d, double e, double f, double g, double h, double i); - void setColorIndex(int color); - void addBlockModel(Block block, AxisAlignedBB renderBounds, @Nullable BlockPos pos, TextureAtlasSprite[] sprites, int colorIndex); + void addBlockModel(@Nullable BlockPos pos, TextureAtlasSprite[] sprites, int colorIndex); - void addBlockModel(Block block, AxisAlignedBB renderBounds, @Nullable BlockPos pos, TextureAtlasSprite sprites, int colorIndex); + void addBlockModel(@Nullable BlockPos pos, TextureAtlasSprite sprites, int colorIndex); - void addModel(AxisAlignedBB renderBounds, TextureAtlasSprite[] textures, int colorIndex); + void addModel(TextureAtlasSprite[] textures, int colorIndex); - void addModel(AxisAlignedBB renderBounds, TextureAtlasSprite texture, int colorIndex); + void addModel(TextureAtlasSprite texture, int colorIndex); void addBakedModel(@Nullable IBlockState state, IBakedModel model); diff --git a/src/main/java/forestry/arboriculture/models/ModelDecorativeLeaves.java b/src/main/java/forestry/arboriculture/models/ModelDecorativeLeaves.java index 9a07d4adb..62e3050b2 100644 --- a/src/main/java/forestry/arboriculture/models/ModelDecorativeLeaves.java +++ b/src/main/java/forestry/arboriculture/models/ModelDecorativeLeaves.java @@ -61,13 +61,13 @@ public class ModelDecorativeLeaves extends ModelBlockCached implements IBakedMod IExtendedBlockState stateExtended = (IExtendedBlockState) state; IBlockAccess world = stateExtended.getValue(UnlistedBlockAccess.BLOCKACCESS); BlockPos pos = stateExtended.getValue(UnlistedBlockPos.POS); - baker.setRenderBounds(state.getBoundingBox(world, pos)); } bakeBlock(block, key, baker, false); @@ -83,11 +82,6 @@ public abstract class ModelBlockDefault implements IBakedMod Block block = Block.getBlockFromItem(stack.getItem()); Preconditions.checkArgument(blockClass.isInstance(block)); B bBlock = blockClass.cast(block); - - // FIXME: This way of getting the IBlockState will probably backfire. - IBlockState state = block.getStateFromMeta(stack.getItemDamage()); - AxisAlignedBB boundingBox = state.getBoundingBox(world, null); - baker.setRenderBounds(boundingBox); bakeBlock(bBlock, key, baker, true); return itemModel = baker.bakeModel(true); diff --git a/src/main/java/forestry/core/models/baker/ModelBaker.java b/src/main/java/forestry/core/models/baker/ModelBaker.java index 292aba632..1878c44d5 100644 --- a/src/main/java/forestry/core/models/baker/ModelBaker.java +++ b/src/main/java/forestry/core/models/baker/ModelBaker.java @@ -18,8 +18,8 @@ import forestry.api.core.IModelBaker; import forestry.api.core.IModelBakerModel; import forestry.core.models.ModelManager; import forestry.core.proxy.Proxies; -import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.BlockFaceUV; import net.minecraft.client.renderer.block.model.BlockPartFace; @@ -28,7 +28,6 @@ import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.block.model.ModelRotation; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.model.IModelState; @@ -38,33 +37,21 @@ import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.util.vector.Vector3f; /** - * A model baker to make custom models in the mod + * A model baker to make custom block models with more than one texture layer. */ @SideOnly(Side.CLIENT) -public class ModelBaker implements IModelBaker { +public final class ModelBaker implements IModelBaker { + + private static final float[] UVS = new float[] { 16.0F, 16.0F, 0F, 0F, 16.0F, 16.0F, 0F, 0F }; + private static final FaceBakery FACE_BAKERY = new FaceBakery(); + private static final Vector3f POS_FROM = new Vector3f(0.0F, 0.0F, 0.0F); + private static final Vector3f POS_TO = new Vector3f(16.0F, 16.0F, 16.0F); - private static final float quadsUV[] = new float[]{0, 0, 1, 1, 0, 0, 1, 1}; private final List faces = new ArrayList<>(); private final List> bakedModels = new ArrayList<>(); - protected AxisAlignedBB renderBounds = Block.FULL_BLOCK_AABB; - protected final ModelBakerModel currentModel = new ModelBakerModel(ModelManager.getInstance().DEFAULT_BLOCK); - protected final FaceBakery faceBakery = new FaceBakery(); - - protected final float[] defUVs = new float[]{0, 0, 1, 1}; - - @Override - public void setRenderBounds(AxisAlignedBB renderBounds) { - this.renderBounds = renderBounds; - } - - @Override - public void setRenderBounds(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { - renderBounds = new AxisAlignedBB(minX, minY, minZ, maxX, maxY, maxZ); - } - protected int colorIndex = -1; @Override @@ -73,34 +60,28 @@ public class ModelBaker implements IModelBaker { } @Override - public void addModel(AxisAlignedBB renderBounds, TextureAtlasSprite[] textures, int colorIndex) { - setRenderBounds(renderBounds); - + public void addModel(TextureAtlasSprite[] textures, int colorIndex) { setColorIndex(colorIndex); for (EnumFacing facing : EnumFacing.VALUES) { addFace(facing, textures[facing.ordinal()]); } - - setRenderBounds(Block.FULL_BLOCK_AABB); } @Override - public void addModel(AxisAlignedBB renderBounds, TextureAtlasSprite texture, int colorIndex) { - addModel(renderBounds, new TextureAtlasSprite[]{texture, texture, texture, texture, texture, texture}, colorIndex); + public void addModel(TextureAtlasSprite texture, int colorIndex) { + addModel(new TextureAtlasSprite[] { texture, texture, texture, texture, texture, texture }, colorIndex); } @Override - public void addBlockModel(Block block, AxisAlignedBB renderBounds, @Nullable BlockPos pos, TextureAtlasSprite[] textures, int colorIndex) { - setRenderBounds(renderBounds); - + public void addBlockModel(@Nullable BlockPos pos, TextureAtlasSprite[] textures, int colorIndex) { setColorIndex(colorIndex); if (pos != null) { World world = Proxies.common.getRenderWorld(); - IBlockState blockState = world.getBlockState(pos); + IBlockState state = world.getBlockState(pos); for (EnumFacing facing : EnumFacing.VALUES) { - if (block.shouldSideBeRendered(blockState, world, pos, facing)) { + if (state.shouldSideBeRendered(world, pos, facing)) { addFace(facing, textures[facing.ordinal()]); } } @@ -110,12 +91,12 @@ public class ModelBaker implements IModelBaker { } } - setRenderBounds(Block.FULL_BLOCK_AABB); } @Override - public void addBlockModel(Block block, AxisAlignedBB renderBounds, @Nullable BlockPos pos, TextureAtlasSprite texture, int colorIndex) { - addBlockModel(block, renderBounds, pos, new TextureAtlasSprite[]{texture, texture, texture, texture, texture, texture}, colorIndex); + public void addBlockModel(@Nullable BlockPos pos, TextureAtlasSprite texture, int colorIndex) { + addBlockModel(pos, new TextureAtlasSprite[] { texture, texture, texture, texture, texture, texture }, + colorIndex); } @Override @@ -123,103 +104,34 @@ public class ModelBaker implements IModelBaker { this.bakedModels.add(Pair.of(state, model)); } - protected static float[] getFaceUvs(final EnumFacing face, final Vector3f to_16, final Vector3f from_16) { - float from_a = 0; - float from_b = 0; - float to_a = 0; - float to_b = 0; - - switch (face) { - case UP: - from_a = from_16.x / 16.0f; - from_b = from_16.z / 16.0f; - to_a = to_16.x / 16.0f; - to_b = to_16.z / 16.0f; - break; - case DOWN: - from_a = from_16.x / 16.0f; - from_b = from_16.z / 16.0f; - to_a = to_16.x / 16.0f; - to_b = to_16.z / 16.0f; - break; - case SOUTH: - from_a = from_16.x / 16.0f; - from_b = from_16.y / 16.0f; - to_a = to_16.x / 16.0f; - to_b = to_16.y / 16.0f; - break; - case NORTH: - from_a = from_16.x / 16.0f; - from_b = from_16.y / 16.0f; - to_a = to_16.x / 16.0f; - to_b = to_16.y / 16.0f; - break; - case EAST: - from_a = from_16.y / 16.0f; - from_b = from_16.z / 16.0f; - to_a = to_16.y / 16.0f; - to_b = to_16.z / 16.0f; - break; - case WEST: - from_a = from_16.y / 16.0f; - from_b = from_16.z / 16.0f; - to_a = to_16.y / 16.0f; - to_b = to_16.z / 16.0f; - break; - default: - } - - from_a = 1.0f - from_a; - from_b = 1.0f - from_b; - to_a = 1.0f - to_a; - to_b = 1.0f - to_b; - - return new float[]{ // :P - 16.0f * (quadsUV[0] + quadsUV[2] * from_a + quadsUV[4] * from_b), // 0 - 16.0f * (quadsUV[1] + quadsUV[3] * from_a + quadsUV[5] * from_b), // 1 - - 16.0f * (quadsUV[0] + quadsUV[2] * to_a + quadsUV[4] * from_b), // 2 - 16.0f * (quadsUV[1] + quadsUV[3] * to_a + quadsUV[5] * from_b), // 3 - - 16.0f * (quadsUV[0] + quadsUV[2] * to_a + quadsUV[4] * to_b), // 2 - 16.0f * (quadsUV[1] + quadsUV[3] * to_a + quadsUV[5] * to_b), // 3 - - 16.0f * (quadsUV[0] + quadsUV[2] * from_a + quadsUV[4] * to_b), // 0 - 16.0f * (quadsUV[1] + quadsUV[3] * from_a + quadsUV[5] * to_b), // 1 - }; - } - @Override public void addFace(EnumFacing facing, TextureAtlasSprite sprite) { - Vector3f to = new Vector3f((float) renderBounds.minX * 16.0f, (float) renderBounds.minY * 16.0f, (float) renderBounds.minZ * 16.0f); - Vector3f from = new Vector3f((float) renderBounds.maxX * 16.0f, (float) renderBounds.maxY * 16.0f, (float) renderBounds.maxZ * 16.0f); - - faces.add(new ModelBakerFace(facing, colorIndex, to, from, defUVs, sprite)); + if (sprite != Minecraft.getMinecraft().getTextureMapBlocks().missingImage) { + faces.add(new ModelBakerFace(facing, colorIndex, sprite)); + } } @Override public IModelBakerModel bakeModel(boolean flip) { - ModelRotation mr = ModelRotation.X0_Y0; + ModelRotation modelRotation = ModelRotation.X0_Y0; if (flip) { - mr = ModelRotation.X0_Y180; + modelRotation = ModelRotation.X0_Y180; } - //Add baked models to the current model. + // Add baked models to the current model. for (Pair bakedModel : bakedModels) { currentModel.addModelQuads(bakedModel); } for (ModelBakerFace face : faces) { - final EnumFacing myFace = face.face; - final float[] uvs = getFaceUvs(myFace, face.from, face.to); + EnumFacing facing = face.face; + BlockFaceUV uvFace = new BlockFaceUV(UVS, 0); + BlockPartFace partFace = new BlockPartFace(facing, face.colorIndex, "", uvFace); + BakedQuad quad = FACE_BAKERY.makeBakedQuad(POS_FROM, POS_TO, partFace, face.spite, facing, modelRotation, + null, true, true); - final BlockFaceUV uv = new BlockFaceUV(uvs, 0); - final BlockPartFace bpf = new BlockPartFace(myFace, face.colorIndex, "", uv); - - BakedQuad bf = faceBakery.makeBakedQuad(face.to, face.from, bpf, face.spite, myFace, mr, null, true, true); - - currentModel.addQuad(myFace, bf); + currentModel.addQuad(facing, quad); } return currentModel; diff --git a/src/main/java/forestry/core/models/baker/ModelBakerFace.java b/src/main/java/forestry/core/models/baker/ModelBakerFace.java index 0c92a11ad..aa33b4cb3 100644 --- a/src/main/java/forestry/core/models/baker/ModelBakerFace.java +++ b/src/main/java/forestry/core/models/baker/ModelBakerFace.java @@ -23,21 +23,13 @@ import org.lwjgl.util.vector.Vector3f; public class ModelBakerFace { public final EnumFacing face; - public final Vector3f to; - public final Vector3f from; - - public final float[] uv; - public final TextureAtlasSprite spite; public final int colorIndex; - public ModelBakerFace(EnumFacing face, int colorIndex, Vector3f to, Vector3f from, float[] defUVs2, TextureAtlasSprite sprite) { + public ModelBakerFace(EnumFacing face, int colorIndex, TextureAtlasSprite sprite) { this.colorIndex = colorIndex; this.face = face; - this.to = to; - this.from = from; - this.uv = defUVs2; this.spite = sprite; } diff --git a/src/main/java/forestry/core/models/baker/ModelBakerModel.java b/src/main/java/forestry/core/models/baker/ModelBakerModel.java index 2040c818a..93c667c52 100644 --- a/src/main/java/forestry/core/models/baker/ModelBakerModel.java +++ b/src/main/java/forestry/core/models/baker/ModelBakerModel.java @@ -20,6 +20,7 @@ import java.util.Map; import com.google.common.collect.ImmutableMap; import forestry.api.core.IModelBakerModel; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; @@ -38,7 +39,6 @@ public class ModelBakerModel implements IModelBakerModel { private boolean isGui3d; private boolean isAmbientOcclusion; - @Nullable private TextureAtlasSprite particleSprite; @Nullable private IModelState modelState; @@ -57,6 +57,7 @@ public class ModelBakerModel implements IModelBakerModel { models = new ArrayList<>(); faceQuads = new EnumMap<>(EnumFacing.class); generalQuads = new ArrayList<>(); + particleSprite = Minecraft.getMinecraft().getTextureMapBlocks().missingImage; isGui3d = true; isAmbientOcclusion = false; setModelState(modelState); @@ -124,15 +125,15 @@ public class ModelBakerModel implements IModelBakerModel { return ItemOverrideList.NONE; } - public static float[] getDefaultRotation() { + private static float[] getDefaultRotation() { return new float[]{-80, -45, 170}; } - public static float[] getDefaultTranslation() { + private static float[] getDefaultTranslation() { return new float[]{0, 1.5F, -2.75F}; } - public static float[] getDefaultScale() { + private static float[] getDefaultScale() { return new float[]{0.375F, 0.375F, 0.375F}; } diff --git a/src/main/java/forestry/farming/models/ModelFarmBlock.java b/src/main/java/forestry/farming/models/ModelFarmBlock.java index 2cf9bbb7c..31c2c6ecc 100644 --- a/src/main/java/forestry/farming/models/ModelFarmBlock.java +++ b/src/main/java/forestry/farming/models/ModelFarmBlock.java @@ -81,9 +81,9 @@ public class ModelFarmBlock extends ModelBlockCached sprites; private enum BlockGreenhouseSprites { - GEARS("gears"), VALVE("valve"), FAN_OFF("fan.off"), FAN_ON("fan.on"), HEATER_OFF("heater.off"), HEATER_ON("heater.on"), DRYER("dryer"), CONTROL("control"), HATCH_DEFAULT("hatch"), HATCH_INPUT("hatch_input"), HATCH_OUTPUT("hatch_output"), CLIMATE_CONTROL("climate_control"), BUTTERFLY_HATCH("butterfly_hatch"); + GEARS("gears"), + VALVE("valve"), + FAN_OFF("fan.off"), FAN_ON("fan.on"), + HEATER_OFF("heater.off"), HEATER_ON("heater.on"), + DRYER("dryer"), + CONTROL("control"), + HUMUDIFIER_OFF("humidifier.on"), HUMUDIFIER_ON("humidifier.on"), + HATCH_DEFAULT("hatch"), HATCH_INPUT("hatch_input"), HATCH_OUTPUT("hatch_output"), + CLIMATE_CONTROL("climate_control"), + BUTTERFLY_HATCH("butterfly_hatch"); public static final BlockGreenhouseSprites[] VALUES = values(); diff --git a/src/main/java/forestry/greenhouse/models/ModelGreenhouse.java b/src/main/java/forestry/greenhouse/models/ModelGreenhouse.java index e1648a68e..7d2bf8420 100644 --- a/src/main/java/forestry/greenhouse/models/ModelGreenhouse.java +++ b/src/main/java/forestry/greenhouse/models/ModelGreenhouse.java @@ -70,11 +70,11 @@ public class ModelGreenhouse extends ModelBlockDefault()); - continue; } else if (greenhouseType == BlockGreenhouseType.BUTTERFLY_HATCH) { if (!ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)) { continue;