mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-22 04:52:26 +00:00
Improve greenhouse multiblock
This commit is contained in:
1 parent
9a0e5dc3e3
commit
7238886d00
18 files changed
+141
-58
No files matched your search
@@ -8,14 +8,14 @@ package forestry.api.greenhouse;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.IErrorLogicSource;
|
||||
import forestry.core.tiles.IClimatised;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IGreenhouseHousing extends IErrorLogicSource {
|
||||
|
||||
EnumTemperature getTemperature();
|
||||
|
||||
EnumHumidity getHumidity();
|
||||
public interface IGreenhouseHousing extends IErrorLogicSource, IClimatised {
|
||||
|
||||
World getWorld();
|
||||
|
||||
boolean isInGreenhouse(BlockPos pos);
|
||||
|
||||
}
|
||||
@@ -537,24 +537,6 @@ public abstract class MultiblockControllerBase implements IMultiblockControllerI
|
||||
}
|
||||
}
|
||||
|
||||
protected BlockPos getMaxXYCoord() {
|
||||
BlockPos maximumCoord = new BlockPos(0, 0, 0);
|
||||
|
||||
for (IMultiblockComponent part : connectedParts) {
|
||||
BlockPos partCoords = part.getCoordinates();
|
||||
int maxX = maximumCoord.getX();
|
||||
int maxZ = maximumCoord.getZ();
|
||||
if (partCoords.getX() > maximumCoord.getX()) {
|
||||
maxX = partCoords.getX();
|
||||
}
|
||||
if (partCoords.getZ() > maximumCoord.getZ()) {
|
||||
maxZ = partCoords.getZ();
|
||||
}
|
||||
maximumCoord = new BlockPos(maxX, 0, maxZ);
|
||||
}
|
||||
return maximumCoord;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The minimum bounding-box coordinate containing this machine's blocks.
|
||||
*/
|
||||
|
||||
@@ -6,21 +6,27 @@ import javax.annotation.Nonnull;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.farming.blocks.EnumFarmBlockType;
|
||||
import forestry.farming.proxy.ProxyFarming;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouseType;
|
||||
import forestry.greenhouse.blocks.BlockRegistryGreenhouse;
|
||||
import forestry.greenhouse.proxy.ProxyGreenhouse;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseControl;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseDryer;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseFan;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseGearbox;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseHeater;
|
||||
import forestry.greenhouse.tiles.TileGreenhousePlain;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseSprinkler;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseValve;
|
||||
import forestry.plugins.BlankForestryPlugin;
|
||||
import forestry.plugins.ForestryPlugin;
|
||||
import forestry.plugins.ForestryPluginUids;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -38,6 +44,20 @@ public class PluginGreenhouse extends BlankForestryPlugin {
|
||||
blocks = new BlockRegistryGreenhouse();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doInit() {
|
||||
super.doInit();
|
||||
|
||||
GameRegistry.registerTileEntity(TileGreenhouseFan.class, "forestry.greenhouse.fan");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseHeater.class, "forestry.greenhouse.heater");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseDryer.class, "forestry.greenhouse.dryer");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseSprinkler.class, "forestry.greenhouse.sprinkler");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseValve.class, "forestry.greenhouse.valve");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseGearbox.class, "forestry.greenhouse.gearbox");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseControl.class, "forestry.greenhouse.controller");
|
||||
GameRegistry.registerTileEntity(TileGreenhousePlain.class, "forestry.greenhouse.plain");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preInit(){
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
@@ -23,6 +24,7 @@ import net.minecraft.block.state.BlockState;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -121,11 +123,6 @@ public abstract class BlockGreenhouse extends BlockStructure {
|
||||
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> list) {
|
||||
list.add(new ItemStack(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
return getMetaFromState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, IBlockState state) {
|
||||
@@ -159,18 +156,44 @@ public abstract class BlockGreenhouse extends BlockStructure {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public EnumWorldBlockLayer getBlockLayer() {
|
||||
if(getGreenhouseType() == BlockGreenhouseType.GLASS){
|
||||
return EnumWorldBlockLayer.TRANSLUCENT;
|
||||
}
|
||||
return EnumWorldBlockLayer.CUTOUT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNormalCube(IBlockAccess world, BlockPos pos) {
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
if(getGreenhouseType() == BlockGreenhouseType.SPRINKLER){
|
||||
return false;
|
||||
}
|
||||
return super.isNormalCube(world, pos);
|
||||
public boolean isFullCube() {
|
||||
return getGreenhouseType() != BlockGreenhouseType.GLASS && getGreenhouseType() == BlockGreenhouseType.SPRINKLER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube() {
|
||||
return getGreenhouseType() != BlockGreenhouseType.GLASS;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
|
||||
{
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (getGreenhouseType() == BlockGreenhouseType.GLASS)
|
||||
{
|
||||
if (worldIn.getBlockState(pos.offset(side.getOpposite())) != iblockstate)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (block == this)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return block == this ? false : super.shouldSideBeRendered(worldIn, pos, side);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
|
||||
@@ -72,7 +72,6 @@ public enum BlockGreenhouseType {
|
||||
TextureManager.registerSprite("blocks/greenhouse/fan.on"),
|
||||
TextureManager.registerSprite("blocks/greenhouse/heater.off"),
|
||||
TextureManager.registerSprite("blocks/greenhouse/heater.off"),
|
||||
TextureManager.registerSprite("blocks/greenhouse/heater"),
|
||||
TextureManager.registerSprite("blocks/greenhouse/dryer"),
|
||||
TextureManager.registerSprite("blocks/greenhouse/control")
|
||||
);
|
||||
|
||||
@@ -5,6 +5,7 @@ import forestry.greenhouse.blocks.BlockGreenhouseType;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BlockModelShapes;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
@@ -45,11 +46,24 @@ public class ModelGreenhouse extends ModelBlockOverlay<BlockGreenhouse> {
|
||||
BlockModelShapes modelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes();
|
||||
baker.addBakedModel(modelShapes.getModelForState(Block.getBlockFromItem(camouflageBlockStack.getItem()).getStateFromMeta(camouflageBlockStack.getItemDamage())));
|
||||
}
|
||||
else if(block.getGreenhouseType() == BlockGreenhouseType.GLASS){
|
||||
TextureAtlasSprite glassSprite = BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null);
|
||||
baker.addBlockModel(block, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null), 100);
|
||||
baker.setParticleSprite(glassSprite);
|
||||
}else{
|
||||
TextureAtlasSprite plainSprite = BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null);
|
||||
baker.addBlockModel(block, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null), 100);
|
||||
baker.setParticleSprite(plainSprite);
|
||||
}
|
||||
}else{
|
||||
if(block.getGreenhouseType() == BlockGreenhouseType.GLASS){
|
||||
TextureAtlasSprite glassSprite = BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null);
|
||||
baker.addBlockModel(block, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null), 100);
|
||||
baker.setParticleSprite(glassSprite);
|
||||
}else{
|
||||
TextureAtlasSprite plainSprite = BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null);
|
||||
baker.addBlockModel(block, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null), 100);
|
||||
baker.setParticleSprite(plainSprite);
|
||||
}
|
||||
}
|
||||
if(block.getGreenhouseType() != BlockGreenhouseType.PLAIN && block.getGreenhouseType() != BlockGreenhouseType.GLASS){
|
||||
|
||||
@@ -14,6 +14,7 @@ import forestry.core.fluids.FakeTankManager;
|
||||
import forestry.core.fluids.ITankManager;
|
||||
import forestry.core.multiblock.FakeMultiblockController;
|
||||
import forestry.energy.EnergyManager;
|
||||
import net.minecraft.util.BlockPos;
|
||||
|
||||
public class FakeGreenhouseController extends FakeMultiblockController implements IGreenhouseControllerInternal {
|
||||
public static final FakeGreenhouseController instance = new FakeGreenhouseController();
|
||||
@@ -31,5 +32,10 @@ public class FakeGreenhouseController extends FakeMultiblockController implement
|
||||
public EnergyManager getEnergyManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGreenhouse(BlockPos pos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,6 +42,7 @@ import forestry.core.tiles.ILiquidTankTile;
|
||||
import forestry.energy.EnergyManager;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouse;
|
||||
import forestry.greenhouse.network.packets.PacketCamouflageUpdate;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseSprinkler;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -341,6 +342,20 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void isBlockGoodForInterior(World world, BlockPos pos) throws MultiblockValidationException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGreenhouse(BlockPos pos) {
|
||||
for(InternalBlock inerBlock : internalBlocks){
|
||||
if(inerBlock.pos.equals(pos)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void isMachineWhole() throws MultiblockValidationException {
|
||||
int minX = getSizeLimits().getMinimumXSize();
|
||||
@@ -442,7 +457,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
}
|
||||
} else {
|
||||
if (part != null) {
|
||||
if (!myClass.equals(part.getMultiblockLogic().getController().getClass())) {
|
||||
if (myClass.equals(part.getMultiblockLogic().getController().getClass())) {
|
||||
throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.invalid.part", x, y, z, myClass.getSimpleName()));
|
||||
}
|
||||
isGoodForInterior(part);
|
||||
@@ -453,31 +468,49 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
}
|
||||
}
|
||||
if(isNextRoof){
|
||||
addInternalBlock(new InternalBlock(getMinimumCoord().add(1, 1, 1)), internalBlocks);
|
||||
}else{
|
||||
throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.space.closed"));
|
||||
InternalBlock iB = new InternalBlock(getMinimumCoord().add(1, 1, 1));
|
||||
internalBlocks.add(iB);
|
||||
addInternalBlock(iB, internalBlocks);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(internalBlocks.isEmpty()){
|
||||
throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.space.closed"));
|
||||
}
|
||||
this.internalBlocks.addAll(internalBlocks);
|
||||
}
|
||||
|
||||
private InternalBlock addInternalBlock(InternalBlock internalBlock, List<InternalBlock> internalBlocks) throws MultiblockValidationException{
|
||||
private void addInternalBlock(InternalBlock internalBlock, List<InternalBlock> internalBlocks) throws MultiblockValidationException{
|
||||
isBlockGoodForInterior(worldObj, internalBlock.pos);
|
||||
for(Map.Entry<EnumFacing, Boolean> entry : internalBlock.testetFaces.entrySet()){
|
||||
if(!entry.getValue()){
|
||||
BlockPos posFacing = new BlockPos(internalBlock.pos.getX() + entry.getKey().getFrontOffsetX(), internalBlock.pos.getY() + entry.getKey().getFrontOffsetY(), internalBlock.pos.getZ() + entry.getKey().getFrontOffsetZ());
|
||||
BlockPos minPos = getMinimumCoord();
|
||||
BlockPos maxPos = getMaxXYCoord();
|
||||
BlockPos maxPos = getMaximumCoord();
|
||||
if(minPos.getX() > posFacing.getX() || minPos.getZ() > posFacing.getZ() || maxPos.getX() < posFacing.getX() || maxPos.getZ() < posFacing.getZ()){
|
||||
throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.space.closed"));
|
||||
}
|
||||
if(worldObj.getTileEntity(posFacing) instanceof IGreenhouseComponent && worldObj.getBlockState(posFacing).getBlock().isSideSolid(worldObj, posFacing, entry.getKey())){
|
||||
entry.setValue(true);
|
||||
|
||||
TileEntity tile = worldObj.getTileEntity(posFacing);
|
||||
|
||||
if(tile instanceof IGreenhouseComponent){
|
||||
if(((IGreenhouseComponent) tile).getMultiblockLogic().getController() != this){
|
||||
throw new MultiblockValidationException(StatCollector.translateToLocalFormatted("for.multiblock.error.not.connected.part", posFacing.getX(), posFacing.getY(), posFacing.getZ()));
|
||||
}
|
||||
else if(!(tile instanceof TileGreenhouseSprinkler)){
|
||||
entry.setValue(true);
|
||||
}
|
||||
}else{
|
||||
InternalBlock iB = new InternalBlock(posFacing, entry.getKey().getOpposite(), internalBlock);
|
||||
if(!internalBlocks.contains(iB)){
|
||||
internalBlocks.add(iB);
|
||||
addInternalBlock(iB, internalBlocks);
|
||||
}else{
|
||||
entry.setValue(true);
|
||||
}
|
||||
}
|
||||
internalBlocks.add(addInternalBlock(new InternalBlock(posFacing, entry.getKey(), internalBlock), internalBlocks));
|
||||
}
|
||||
}
|
||||
return internalBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -485,25 +518,34 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
return CamouflageType.DEFAULT;
|
||||
}
|
||||
|
||||
private class InternalBlock{
|
||||
private static class InternalBlock{
|
||||
public BlockPos pos;
|
||||
public EnumMap<EnumFacing, Boolean> testetFaces = Maps.newEnumMap(EnumFacing.class);
|
||||
public InternalBlock root;
|
||||
|
||||
public InternalBlock(BlockPos pos) {
|
||||
private InternalBlock(BlockPos pos) {
|
||||
this.pos = pos;
|
||||
for(EnumFacing facing : EnumFacing.VALUES){
|
||||
testetFaces.put(facing, false);
|
||||
}
|
||||
}
|
||||
|
||||
public InternalBlock(BlockPos pos, EnumFacing facing, InternalBlock root) {
|
||||
private InternalBlock(BlockPos pos, EnumFacing facing, InternalBlock root) {
|
||||
this.pos = pos;
|
||||
for(EnumFacing f : EnumFacing.VALUES){
|
||||
testetFaces.put(facing, f == facing);
|
||||
testetFaces.put(f, f == facing);
|
||||
}
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof InternalBlock)){
|
||||
return false;
|
||||
}
|
||||
InternalBlock ib = (InternalBlock) obj;
|
||||
return ib.pos.equals(pos);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,7 +21,7 @@ class GreenhouseMultiblockSizeLimits implements IMultiblockSizeLimits {
|
||||
|
||||
@Override
|
||||
public int getMinimumNumberOfBlocksForAssembledMachine() {
|
||||
return 5 * 5 * 6;
|
||||
return 5 * 5 * 5 - 36;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,6 +51,6 @@ class GreenhouseMultiblockSizeLimits implements IMultiblockSizeLimits {
|
||||
|
||||
@Override
|
||||
public int getMinimumYSize() {
|
||||
return 6;
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import forestry.core.network.IStreamableGui;
|
||||
import forestry.core.tiles.IClimatised;
|
||||
import forestry.energy.EnergyManager;
|
||||
|
||||
public interface IGreenhouseControllerInternal extends IGreenhouseController, IMultiblockControllerInternal, IClimatised, IRestrictedAccess, IStreamableGui {
|
||||
public interface IGreenhouseControllerInternal extends IGreenhouseController, IMultiblockControllerInternal, IRestrictedAccess, IStreamableGui {
|
||||
|
||||
ITankManager getTankManager();
|
||||
|
||||
|
||||
@@ -12,11 +12,8 @@ package forestry.greenhouse.proxy;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import forestry.core.models.BlockModelIndex;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.farming.PluginFarming;
|
||||
import forestry.farming.models.ModelFarmBlock;
|
||||
import forestry.greenhouse.PluginGreenhouse;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouseType;
|
||||
import forestry.greenhouse.models.ModelGreenhouse;
|
||||
|
||||
Reference in new issue
Block a user