mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 20:42:35 +00:00
Clean Up ModelBaker and start to clean up greenhouse
This commit is contained in:
1 parent
8cfafec6f9
commit
08c99cb0ca
15 files changed
+112
-235
No files matched your search
@@ -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);
|
||||
|
||||
|
||||
@@ -61,13 +61,13 @@ public class ModelDecorativeLeaves extends ModelBlockCached<BlockDecorativeLeave
|
||||
TextureAtlasSprite leafSprite = map.getAtlasSprite(leafSpriteLocation.toString());
|
||||
|
||||
// Render the plain leaf block.
|
||||
baker.addBlockModel(block, Block.FULL_BLOCK_AABB, null, leafSprite, 0);
|
||||
baker.addBlockModel(null, leafSprite, 0);
|
||||
|
||||
// Render overlay for fruit leaves.
|
||||
ResourceLocation fruitSpriteLocation = genome.getFruitProvider().getDecorativeSprite();
|
||||
if (fruitSpriteLocation != null) {
|
||||
TextureAtlasSprite fruitSprite = map.getAtlasSprite(fruitSpriteLocation.toString());
|
||||
baker.addBlockModel(block, Block.FULL_BLOCK_AABB, null, fruitSprite, 1);
|
||||
baker.addBlockModel(null, fruitSprite, 1);
|
||||
}
|
||||
|
||||
// Set the particle sprite
|
||||
@@ -78,7 +78,6 @@ public class ModelDecorativeLeaves extends ModelBlockCached<BlockDecorativeLeave
|
||||
protected IBakedModel bakeModel(IBlockState state, TreeDefinition key, BlockDecorativeLeaves block) {
|
||||
IModelBaker baker = new ModelBaker();
|
||||
|
||||
baker.setRenderBounds(Block.FULL_BLOCK_AABB);
|
||||
bakeBlock(block, key, baker, false);
|
||||
|
||||
blockModel = baker.bakeModel(false);
|
||||
|
||||
@@ -114,10 +114,10 @@ public class ModelLeaves extends ModelBlockCached<BlockForestryLeaves, ModelLeav
|
||||
@Override
|
||||
protected void bakeBlock(BlockForestryLeaves block, Key key, IModelBaker baker, boolean inventory) {
|
||||
// Render the plain leaf block.
|
||||
baker.addBlockModel(block, Block.FULL_BLOCK_AABB, null, key.leafSprite, 0);
|
||||
baker.addBlockModel(null, key.leafSprite, 0);
|
||||
|
||||
if (key.fruitSprite != null) {
|
||||
baker.addBlockModel(block, Block.FULL_BLOCK_AABB, null, key.fruitSprite, 1);
|
||||
baker.addBlockModel(null, key.fruitSprite, 1);
|
||||
}
|
||||
|
||||
// Set the particle sprite
|
||||
|
||||
@@ -60,7 +60,6 @@ public abstract class ModelBlockDefault<B extends Block, K> 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<B extends Block, K> 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);
|
||||
|
||||
@@ -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<ModelBakerFace> faces = new ArrayList<>();
|
||||
private final List<Pair<IBlockState, IBakedModel>> 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<IBlockState, IBakedModel> 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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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};
|
||||
}
|
||||
|
||||
|
||||
@@ -81,9 +81,9 @@ public class ModelFarmBlock extends ModelBlockCached<BlockFarm, ModelFarmBlock.K
|
||||
TextureAtlasSprite[] textures = getSprites(key.texture);
|
||||
|
||||
// Add the plain block.
|
||||
baker.addBlockModel(blockFarm, Block.FULL_BLOCK_AABB, null, textures, 0);
|
||||
baker.addBlockModel(null, textures, 0);
|
||||
// Add the overlay block.
|
||||
baker.addBlockModel(blockFarm, Block.FULL_BLOCK_AABB, null, getOverlaySprites(key.type), 0);
|
||||
baker.addBlockModel(null, getOverlaySprites(key.type), 0);
|
||||
|
||||
// Set the particle sprite
|
||||
baker.setParticleSprite(textures[0]);
|
||||
|
||||
@@ -158,7 +158,7 @@ public class PluginGreenhouse extends BlankForestryPlugin {
|
||||
'#', OreDictUtil.INGOT_TIN,
|
||||
'T', coreItems.tubes.get(EnumElectronTube.BLAZE, 1));
|
||||
|
||||
Block greenhouseSprinklerBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.SPRINKLER);
|
||||
Block greenhouseSprinklerBlock = blocks.getGreenhouseBlock(BlockGreenhouseType.HUMUDIFIER);
|
||||
RecipeUtil.addRecipe(greenhouseSprinklerBlock,
|
||||
"TXT",
|
||||
"GIG",
|
||||
|
||||
@@ -34,6 +34,7 @@ import forestry.core.tiles.IActivatable;
|
||||
import forestry.core.utils.CamouflageUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseButterflyHatch;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseClimateControl;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseControl;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseDoor;
|
||||
@@ -112,7 +113,7 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
if (type == BlockGreenhouseType.DOOR) {
|
||||
block = new BlockGreenhouseDoor();
|
||||
} else {
|
||||
block = new BlockGreenhouse() {
|
||||
block = new BlockGreenhouse(type) {
|
||||
|
||||
@Override
|
||||
public BlockGreenhouseType getGreenhouseType() {
|
||||
@@ -122,7 +123,7 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
|
||||
@Override
|
||||
public SoundType getSoundType() {
|
||||
if (type == BlockGreenhouseType.SPRINKLER || type == BlockGreenhouseType.GLASS || type == BlockGreenhouseType.WINDOW || type == BlockGreenhouseType.WINDOW_UP) {
|
||||
if (hasGlass()) {
|
||||
return SoundType.GLASS;
|
||||
}
|
||||
return super.getSoundType();
|
||||
@@ -134,14 +135,10 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
return blockMap;
|
||||
}
|
||||
|
||||
public BlockGreenhouse() {
|
||||
public BlockGreenhouse(BlockGreenhouseType type) {
|
||||
super(Material.ROCK);
|
||||
BlockGreenhouseType greenhouseType = getGreenhouseType();
|
||||
IBlockState defaultState = this.blockState.getBaseState();
|
||||
if (greenhouseType.activatable && greenhouseType != BlockGreenhouseType.SPRINKLER) {
|
||||
defaultState = defaultState.withProperty(STATE, State.OFF);
|
||||
}
|
||||
if (greenhouseType == BlockGreenhouseType.WINDOW || greenhouseType == BlockGreenhouseType.WINDOW_UP) {
|
||||
if (type == BlockGreenhouseType.WINDOW || type == BlockGreenhouseType.WINDOW_UP) {
|
||||
defaultState = defaultState.withProperty(FACING, EnumFacing.NORTH);
|
||||
}
|
||||
setDefaultState(defaultState);
|
||||
@@ -222,27 +219,9 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World worldIn, BlockPos pos) {
|
||||
if (getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
|
||||
return SPRINKLER_BOUNDS.offset(pos);
|
||||
}
|
||||
return super.getSelectedBoundingBox(state, worldIn, pos);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos) {
|
||||
if (getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
|
||||
return SPRINKLER_BOUNDS;
|
||||
}
|
||||
return super.getCollisionBoundingBox(blockState, worldIn, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
||||
if (getGreenhouseType() != BlockGreenhouseType.SPRINKLER && getGreenhouseType() != BlockGreenhouseType.WINDOW && getGreenhouseType() != BlockGreenhouseType.WINDOW_UP) {
|
||||
if (getGreenhouseType() != BlockGreenhouseType.WINDOW && getGreenhouseType() != BlockGreenhouseType.WINDOW_UP) {
|
||||
return ((IExtendedBlockState) super.getExtendedState(state, world, pos)).withProperty(UnlistedBlockPos.POS, pos)
|
||||
.withProperty(UnlistedBlockAccess.BLOCKACCESS, world);
|
||||
}
|
||||
@@ -251,9 +230,7 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
if (getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
|
||||
return new ExtendedBlockState(this, new IProperty[]{Properties.StaticProperty}, new IUnlistedProperty[]{Properties.AnimationProperty});
|
||||
} else if (getGreenhouseType() == BlockGreenhouseType.WINDOW || getGreenhouseType() == BlockGreenhouseType.WINDOW_UP) {
|
||||
if (getGreenhouseType() == BlockGreenhouseType.WINDOW || getGreenhouseType() == BlockGreenhouseType.WINDOW_UP) {
|
||||
return new BlockStateContainer(this, STATE, FACING);
|
||||
} else if (getGreenhouseType().activatable) {
|
||||
return new ExtendedBlockState(this, new IProperty[]{STATE}, new IUnlistedProperty[]{UnlistedBlockPos.POS, UnlistedBlockAccess.BLOCKACCESS});
|
||||
@@ -264,18 +241,14 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
|
||||
@Override
|
||||
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
|
||||
if (getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
|
||||
return state.withProperty(Properties.StaticProperty, true);
|
||||
} else {
|
||||
TileEntity tile = worldIn.getTileEntity(pos);
|
||||
if (tile instanceof IActivatable) {
|
||||
state = state.withProperty(STATE, ((IActivatable) tile).isActive() ? State.ON : State.OFF);
|
||||
}
|
||||
if (tile instanceof TileGreenhouseWindow) {
|
||||
TileGreenhouseWindow window = (TileGreenhouseWindow) tile;
|
||||
}
|
||||
return super.getActualState(state, worldIn, pos);
|
||||
TileEntity tile = worldIn.getTileEntity(pos);
|
||||
if (tile instanceof IActivatable) {
|
||||
state = state.withProperty(STATE, ((IActivatable) tile).isActive() ? State.ON : State.OFF);
|
||||
}
|
||||
if (tile instanceof TileGreenhouseWindow) {
|
||||
TileGreenhouseWindow window = (TileGreenhouseWindow) tile;
|
||||
}
|
||||
return super.getActualState(state, worldIn, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -329,8 +302,6 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
switch (type) {
|
||||
case GEARBOX:
|
||||
return new TileGreenhouseGearbox();
|
||||
case SPRINKLER:
|
||||
return new TileGreenhouseSprinkler();
|
||||
case DRYER:
|
||||
return new TileGreenhouseDryer();
|
||||
case VALVE:
|
||||
@@ -352,7 +323,7 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
case HATCH_OUTPUT:
|
||||
return new TileGreenhouseHatch();
|
||||
case BUTTERFLY_HATCH:
|
||||
return new TileGreenhouseHatch();
|
||||
return new TileGreenhouseButterflyHatch();
|
||||
default:
|
||||
return new TileGreenhousePlain();
|
||||
}
|
||||
@@ -387,7 +358,7 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public BlockRenderLayer getBlockLayer() {
|
||||
if (getGreenhouseType() == BlockGreenhouseType.GLASS || getGreenhouseType() == BlockGreenhouseType.WINDOW || getGreenhouseType() == BlockGreenhouseType.WINDOW_UP || getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
|
||||
if (hasGlass()) {
|
||||
return BlockRenderLayer.TRANSLUCENT;
|
||||
}
|
||||
return BlockRenderLayer.CUTOUT;
|
||||
@@ -395,25 +366,17 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
|
||||
@Override
|
||||
public boolean isFullCube(IBlockState state) {
|
||||
return getGreenhouseType() != BlockGreenhouseType.GLASS && getGreenhouseType() != BlockGreenhouseType.SPRINKLER && getGreenhouseType() != BlockGreenhouseType.WINDOW && getGreenhouseType() != BlockGreenhouseType.WINDOW_UP;
|
||||
return !hasGlass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube(IBlockState state) {
|
||||
return getGreenhouseType() != BlockGreenhouseType.GLASS && getGreenhouseType() != BlockGreenhouseType.SPRINKLER && getGreenhouseType() != BlockGreenhouseType.WINDOW && getGreenhouseType() != BlockGreenhouseType.WINDOW_UP;
|
||||
return !hasGlass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
|
||||
if (getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
|
||||
if (worldIn.getBlockState(pos.up()).getBlock() == this) {
|
||||
return false;
|
||||
}
|
||||
if (!(worldIn.getTileEntity(pos.up()) instanceof IGreenhouseComponent)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return super.canPlaceBlockAt(worldIn, pos);
|
||||
|
||||
protected boolean hasGlass(){
|
||||
BlockGreenhouseType type = getGreenhouseType();
|
||||
return type == BlockGreenhouseType.GLASS || type == BlockGreenhouseType.WINDOW || type == BlockGreenhouseType.WINDOW_UP;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -461,11 +424,10 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
if (getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
|
||||
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse.sprinkler", "inventory"));
|
||||
} else if (getGreenhouseType() == BlockGreenhouseType.WINDOW) {
|
||||
BlockGreenhouseType type = getGreenhouseType();
|
||||
if (type == BlockGreenhouseType.WINDOW) {
|
||||
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse.window", "inventory"));
|
||||
} else if (getGreenhouseType() == BlockGreenhouseType.WINDOW_UP) {
|
||||
} else if (type == BlockGreenhouseType.WINDOW_UP) {
|
||||
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse.window_up", "inventory"));
|
||||
} else {
|
||||
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:greenhouse", "inventory"));
|
||||
|
||||
@@ -64,6 +64,7 @@ public class BlockGreenhouseDoor extends BlockGreenhouse implements IStateMapper
|
||||
protected static final AxisAlignedBB EAST_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.1875D, 1.0D, 1.0D);
|
||||
|
||||
public BlockGreenhouseDoor() {
|
||||
super(BlockGreenhouseType.DOOR);
|
||||
setSoundType(SoundType.GLASS);
|
||||
setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(OPEN, false).withProperty(HINGE, BlockDoor.EnumHingePosition.LEFT).withProperty(POWERED, false).withProperty(HALF, BlockDoor.EnumDoorHalf.LOWER).withProperty(CAMOUFLAGED, false));
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ import forestry.core.config.Constants;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouse.State;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseHatch;
|
||||
import net.minecraft.block.BlockFurnace;
|
||||
import net.minecraft.block.BlockStone;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
@@ -22,7 +25,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public enum BlockGreenhouseType {
|
||||
PLAIN,
|
||||
GLASS,
|
||||
GLASS(Material.GLASS),
|
||||
HATCH_INPUT(true),
|
||||
HATCH_OUTPUT(true),
|
||||
GEARBOX(true),
|
||||
@@ -31,38 +34,59 @@ public enum BlockGreenhouseType {
|
||||
HEATER(true, true),
|
||||
DRYER(true, true),
|
||||
CONTROL(true),
|
||||
SPRINKLER(false, true),
|
||||
HUMUDIFIER(true, true), //humidifier
|
||||
DOOR,
|
||||
CLIMATE_CONTROL(true),
|
||||
WINDOW(true),
|
||||
WINDOW_UP(true),
|
||||
WINDOW(Material.GLASS, false, true),
|
||||
WINDOW_UP(Material.GLASS, false, true),
|
||||
BUTTERFLY_HATCH(true);
|
||||
|
||||
public static final BlockGreenhouseType[] VALUES = values();
|
||||
|
||||
public final boolean hasOverlaySprite;
|
||||
public final boolean activatable;
|
||||
public final Material material;
|
||||
|
||||
BlockGreenhouseType(boolean hasOverlaySprite, boolean activatable) {
|
||||
BlockGreenhouseType(Material material, boolean hasOverlaySprite, boolean activatable) {
|
||||
this.hasOverlaySprite = hasOverlaySprite;
|
||||
this.activatable = activatable;
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
BlockGreenhouseType(Material material, boolean hasOverlaySprite) {
|
||||
this(material, hasOverlaySprite, false);
|
||||
}
|
||||
|
||||
BlockGreenhouseType(Material material) {
|
||||
this(material, false, false);
|
||||
}
|
||||
|
||||
BlockGreenhouseType(boolean hasOverlaySprite, boolean activatable) {
|
||||
this(Material.ROCK, hasOverlaySprite, activatable);
|
||||
}
|
||||
|
||||
BlockGreenhouseType(boolean hasOverlaySprite) {
|
||||
this.hasOverlaySprite = hasOverlaySprite;
|
||||
this.activatable = false;
|
||||
this(Material.ROCK, hasOverlaySprite);
|
||||
}
|
||||
|
||||
BlockGreenhouseType() {
|
||||
this.hasOverlaySprite = false;
|
||||
this.activatable = false;
|
||||
this(Material.ROCK);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static EnumMap<BlockGreenhouseSprites, TextureAtlasSprite> 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();
|
||||
|
||||
|
||||
@@ -70,11 +70,11 @@ public class ModelGreenhouse extends ModelBlockDefault<BlockGreenhouse, ModelGre
|
||||
|
||||
@Override
|
||||
protected void bakeBlock(BlockGreenhouse block, Key key, IModelBaker baker, boolean inventory) {
|
||||
ItemStack camouflageStack = key.world != null ? CamouflageUtil.getCamouflageBlock(key.world, key.pos) : null;
|
||||
ItemStack camouflageStack = key.world != null ? CamouflageUtil.getCamouflageBlock(key.world, key.pos) : ItemStack.EMPTY;
|
||||
IBlockAccess world = key.world;
|
||||
BlockPos pos = key.pos;
|
||||
|
||||
if (camouflageStack != null) {
|
||||
if (!camouflageStack.isEmpty()) {
|
||||
ICamouflageHandler camouflageHandler = CamouflageUtil.getCamouflageHandler(world, pos);
|
||||
ICamouflagedTile camouflageTile = (ICamouflagedTile) world.getTileEntity(pos);
|
||||
ICamouflageItemHandler itemHandler = CamouflageManager.camouflageAccess.getHandlerFromItem(camouflageStack);
|
||||
@@ -90,12 +90,12 @@ public class ModelGreenhouse extends ModelBlockDefault<BlockGreenhouse, ModelGre
|
||||
else if (block.getGreenhouseType() == BlockGreenhouseType.GLASS) {
|
||||
TextureAtlasSprite glassSprite = BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null, null, world, pos);
|
||||
|
||||
baker.addBlockModel(block, Block.FULL_BLOCK_AABB, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null, null, world, pos), 100);
|
||||
baker.addBlockModel(pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null, null, world, pos), 100);
|
||||
baker.setParticleSprite(glassSprite);
|
||||
} else {
|
||||
TextureAtlasSprite plainSprite = BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null, null, world, pos);
|
||||
|
||||
baker.addBlockModel(block, Block.FULL_BLOCK_AABB, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null, null, world, pos), 100);
|
||||
baker.addBlockModel(pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null, null, world, pos), 100);
|
||||
baker.setParticleSprite(plainSprite);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public class ModelGreenhouse extends ModelBlockDefault<BlockGreenhouse, ModelGre
|
||||
for (EnumFacing facing : EnumFacing.VALUES) {
|
||||
sprite[facing.ordinal()] = BlockGreenhouseType.getSprite(block.getGreenhouseType(), facing, key.state, world, pos);
|
||||
}
|
||||
baker.addBlockModel(block, Block.FULL_BLOCK_AABB, pos, sprite, 101);
|
||||
baker.addBlockModel(pos, sprite, 101);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -603,7 +603,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
} else {
|
||||
if (part != null) {
|
||||
IBlockState state = world.getBlockState(part.getCoordinates());
|
||||
if (state.getBlock() instanceof BlockGreenhouse && ((BlockGreenhouse) state.getBlock()).getGreenhouseType() == BlockGreenhouseType.SPRINKLER || !myClass.equals(part.getMultiblockLogic().getController().getClass())) {
|
||||
if (!myClass.equals(part.getMultiblockLogic().getController().getClass())) {
|
||||
isGoodForInterior(part);
|
||||
} else {
|
||||
throw new MultiblockValidationException(Translator.translateToLocalFormatted("for.multiblock.error.invalid.part", Translator.translateToLocal(getUnlocalizedType())));
|
||||
|
||||
@@ -25,7 +25,6 @@ import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraftforge.client.model.animation.AnimationTESR;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class ProxyGreenhouseClient extends ProxyGreenhouse {
|
||||
|
||||
@Override
|
||||
@@ -41,9 +40,6 @@ public class ProxyGreenhouseClient extends ProxyGreenhouse {
|
||||
null, new ModelGreenhouse(),
|
||||
greenhouseBlock, false));
|
||||
continue;
|
||||
} else if (greenhouseType == BlockGreenhouseType.SPRINKLER) {
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileGreenhouseSprinkler.class, new AnimationTESR<>());
|
||||
continue;
|
||||
} else if (greenhouseType == BlockGreenhouseType.BUTTERFLY_HATCH) {
|
||||
if (!ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)) {
|
||||
continue;
|
||||
|
||||
Reference in new issue
Block a user