diff --git a/src/main/java/forestry/core/errors/EnumErrorCode.java b/src/main/java/forestry/core/errors/EnumErrorCode.java index 9d9fa4482..ce1d1fb1a 100644 --- a/src/main/java/forestry/core/errors/EnumErrorCode.java +++ b/src/main/java/forestry/core/errors/EnumErrorCode.java @@ -5,14 +5,16 @@ ******************************************************************************/ package forestry.core.errors; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.ResourceLocation; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + import forestry.api.core.ForestryAPI; import forestry.api.core.IErrorState; import forestry.core.config.Constants; import forestry.core.render.TextureManagerForestry; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; public enum EnumErrorCode implements IErrorState { @@ -80,7 +82,12 @@ public enum EnumErrorCode implements IErrorState { // Farms NO_FERTILIZER("no_fertilizer"), // Farms require fertilizer for function. Compost is insufficient. NO_FARMLAND("no_farmland"), // Smooth sandstone, bricks or stone bricks create a platform the farm will build on. - NO_LIQUID_FARM("no_liquid") // Depending on rainfall, temperature and humidity farms need to be supplied with varying amounts of water. + NO_LIQUID_FARM("no_liquid"), // Depending on rainfall, temperature and humidity farms need to be supplied with varying amounts of water. + + // Greenhouse + NOT_LOADED("not_loaded"), // One chunk of the greenhouse is not loaded. + NOT_CLOSED("not_closed"), // The greenhouse is not closed. + TOO_LARGE("too_large") // The greenhouse is too large. ; private final String name; diff --git a/src/main/java/forestry/core/multiblock/MultiblockEventHandlerClient.java b/src/main/java/forestry/core/multiblock/MultiblockEventHandlerClient.java index 9a4992cfc..91c7dea1b 100755 --- a/src/main/java/forestry/core/multiblock/MultiblockEventHandlerClient.java +++ b/src/main/java/forestry/core/multiblock/MultiblockEventHandlerClient.java @@ -4,7 +4,6 @@ import java.util.Set; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.RenderGlobal; @@ -17,6 +16,7 @@ import net.minecraft.world.World; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderWorldLastEvent; + import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -36,7 +36,6 @@ public class MultiblockEventHandlerClient { if(event.getType() == RenderGameOverlayEvent.ElementType.ALL && Minecraft.getMinecraft().currentScreen == null){ Minecraft minecraft = Minecraft.getMinecraft(); RayTraceResult posHit = minecraft.objectMouseOver; - FontRenderer font = minecraft.fontRenderer; ScaledResolution resolution = event.getResolution(); if(posHit != null && posHit.getBlockPos() != null){ diff --git a/src/main/java/forestry/core/utils/ClimateUtil.java b/src/main/java/forestry/core/utils/ClimateUtil.java index 8780555b7..5e831aeaa 100644 --- a/src/main/java/forestry/core/utils/ClimateUtil.java +++ b/src/main/java/forestry/core/utils/ClimateUtil.java @@ -293,7 +293,7 @@ public class ClimateUtil implements IClimateHelper { case NONE: return 0x011f4b; default: - return 16777215; + return 0xFFFFFF; } } } diff --git a/src/main/java/forestry/greenhouse/GreenhouseEventHandler.java b/src/main/java/forestry/greenhouse/GreenhouseEventHandler.java index 423fa6b32..be817805e 100644 --- a/src/main/java/forestry/greenhouse/GreenhouseEventHandler.java +++ b/src/main/java/forestry/greenhouse/GreenhouseEventHandler.java @@ -34,11 +34,11 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import forestry.api.multiblock.IGreenhouseComponent; +import forestry.core.multiblock.MultiblockUtil; import forestry.greenhouse.api.greenhouse.IGreenhouseLimits; import forestry.greenhouse.api.greenhouse.IGreenhouseProvider; import forestry.greenhouse.api.greenhouse.Position2D; -import forestry.api.multiblock.IGreenhouseComponent; -import forestry.core.multiblock.MultiblockUtil; import forestry.greenhouse.items.ItemGreenhouseScreen; import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; diff --git a/src/main/java/forestry/greenhouse/api/greenhouse/IGreenhouseBlockHandler.java b/src/main/java/forestry/greenhouse/api/greenhouse/IGreenhouseBlockHandler.java index aec958fbe..5c9e0a922 100644 --- a/src/main/java/forestry/greenhouse/api/greenhouse/IGreenhouseBlockHandler.java +++ b/src/main/java/forestry/greenhouse/api/greenhouse/IGreenhouseBlockHandler.java @@ -11,7 +11,7 @@ import java.util.List; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; -import forestry.greenhouse.multiblock.blocks.GreenhouseException; +import forestry.api.core.IErrorState; public interface IGreenhouseBlockHandler { @@ -20,10 +20,11 @@ public interface IGreenhouseBlockHandler newBlocksToCheck); - List checkNeighborBlocks(IGreenhouseBlockStorage storage, B blockToCheck) throws GreenhouseException; - - boolean onCheckPosition(IGreenhouseBlockStorage storage, R rootBlock, BlockPos position, EnumFacing facing, IGreenhouseBlock block, List newBlocksToCheck) throws GreenhouseException; + boolean onCheckPosition(IGreenhouseBlockStorage storage, R rootBlock, BlockPos position, EnumFacing facing, IGreenhouseBlock block, List newBlocksToCheck); Class getBlockClass(); } diff --git a/src/main/java/forestry/greenhouse/api/greenhouse/IGreenhouseProvider.java b/src/main/java/forestry/greenhouse/api/greenhouse/IGreenhouseProvider.java index a1623736d..792046265 100644 --- a/src/main/java/forestry/greenhouse/api/greenhouse/IGreenhouseProvider.java +++ b/src/main/java/forestry/greenhouse/api/greenhouse/IGreenhouseProvider.java @@ -11,15 +11,16 @@ import java.util.Collection; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import forestry.api.core.IErrorLogicSource; +import forestry.api.core.IErrorState; import forestry.greenhouse.api.climate.GreenhouseState; import forestry.greenhouse.api.climate.IClimateContainer; -import forestry.greenhouse.multiblock.blocks.GreenhouseException; /** * Can be used to test if a space is closed. Is used by the greenhouse. * */ -public interface IGreenhouseProvider { +public interface IGreenhouseProvider extends IErrorLogicSource { /** * @return the climate container of this provider. @@ -47,11 +48,6 @@ public interface IGreenhouseProvider { */ void clear(boolean chunkUnloading); - /** - * @return The last error that has coded that the provider is not closed. - */ - String getLastNotClosedError(); - /** * Called from the thread if a {@link IGreenhouseBlock} was modified by the player. */ @@ -74,7 +70,9 @@ public interface IGreenhouseProvider { /** * @return The limits that a greenhouse has. Used to test if the greenhouse is tested. * At the test the provider stops if the currently tested position is out of this limits and marks the greenhouse as open. + * Null if the provider is not created. */ + @Nullable IGreenhouseLimits getLimits(); /** @@ -95,7 +93,7 @@ public interface IGreenhouseProvider { /** * Test if the provider is closed. */ - void checkPosition(BlockPos position) throws GreenhouseException; + IErrorState checkPosition(BlockPos position); int getSize(); diff --git a/src/main/java/forestry/greenhouse/gui/GuiGreenhouse.java b/src/main/java/forestry/greenhouse/gui/GuiGreenhouse.java index 8484d4f4b..8658df9d9 100755 --- a/src/main/java/forestry/greenhouse/gui/GuiGreenhouse.java +++ b/src/main/java/forestry/greenhouse/gui/GuiGreenhouse.java @@ -25,7 +25,7 @@ import forestry.core.gui.TextLayoutHelper; import forestry.core.utils.NetworkUtil; import forestry.greenhouse.gui.widgets.WidgetCamouflageTab; import forestry.greenhouse.gui.widgets.WidgetClimatePanel; -import forestry.greenhouse.gui.widgets.WidgetClimatePillar; +import forestry.greenhouse.gui.widgets.WidgetClimateBar; import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; import forestry.greenhouse.network.packets.PacketSelectClimateTargeted; import forestry.greenhouse.tiles.TileGreenhouse; @@ -52,8 +52,8 @@ public class GuiGreenhouse extends GuiForestryTitled { IClimateData data = container.getData(); //Add the camouflage tab - widgetManager.add(new WidgetCamouflageTab(widgetManager, xSize / 2 - WidgetCamouflageTab.WIDTH / 2, -WidgetCamouflageTab.HEIGHT, controller, tile)); - widgetManager.add(new WidgetClimatePillar(widgetManager, -WidgetClimatePillar.WIDTH, GUI_HEIGHT / 2 - WidgetClimatePillar.HEIGHT / 2)); + widgetManager.add(new WidgetCamouflageTab(widgetManager, xSize / 4 - WidgetCamouflageTab.WIDTH / 2, -WidgetCamouflageTab.HEIGHT, controller, tile)); + widgetManager.add(new WidgetClimateBar(widgetManager, xSize / 3 + WidgetClimateBar.WIDTH / 3, -WidgetClimateBar.HEIGHT)); widgetManager.add(temperaturePanel = new WidgetClimatePanel(widgetManager, this, 9, 18, ClimateType.TEMPERATURE, data)); widgetManager.add(humidityPanel = new WidgetClimatePanel(widgetManager, this, 102, 18, ClimateType.HUMIDITY, data)); } diff --git a/src/main/java/forestry/greenhouse/gui/widgets/WidgetClimatePillar.java b/src/main/java/forestry/greenhouse/gui/widgets/WidgetClimateBar.java similarity index 89% rename from src/main/java/forestry/greenhouse/gui/widgets/WidgetClimatePillar.java rename to src/main/java/forestry/greenhouse/gui/widgets/WidgetClimateBar.java index 33a21ffef..320e23c07 100644 --- a/src/main/java/forestry/greenhouse/gui/widgets/WidgetClimatePillar.java +++ b/src/main/java/forestry/greenhouse/gui/widgets/WidgetClimateBar.java @@ -29,14 +29,14 @@ import forestry.core.gui.widgets.WidgetManager; import forestry.core.render.TextureManagerForestry; import forestry.greenhouse.gui.GuiGreenhouse; -public class WidgetClimatePillar extends Widget { +public class WidgetClimateBar extends Widget { - public static final int WIDTH = 23; - public static final int HEIGHT = 90; + public static final int WIDTH = 90; + public static final int HEIGHT = 23; private final List buttons = new ArrayList<>(); - public WidgetClimatePillar(WidgetManager manager, int xPos, int yPos) { + public WidgetClimateBar(WidgetManager manager, int xPos, int yPos) { super(manager, xPos, yPos); this.width = WIDTH; this.height = HEIGHT; @@ -60,7 +60,7 @@ public class WidgetClimatePillar extends Widget { value = 0.5F; break; } - buttons.add(new ClimateButton(this, temp, value, xPos + 5, yPos + 5 + (i - 1) * 16)); + buttons.add(new ClimateButton(this, temp, value, xPos + 5 + (i - 1) * 16, yPos + 5)); } } @@ -68,7 +68,7 @@ public class WidgetClimatePillar extends Widget { public void draw(int startX, int startY) { TextureManager textureManager = Minecraft.getMinecraft().getTextureManager(); textureManager.bindTexture(manager.gui.textureFile); - manager.gui.drawTexturedModalRect(startX + xPos, startY + yPos, 220, 25, width, height); + manager.gui.drawTexturedModalRect(startX + xPos, startY + yPos, 0, 202, width, height); for (ClimateButton button : buttons) { button.draw(startX, startY); } @@ -109,7 +109,7 @@ public class WidgetClimatePillar extends Widget { } private static class ClimateButton { - final WidgetClimatePillar parent; + final WidgetClimateBar parent; final EnumTemperature temperature; final float value; protected final ToolTip toolTip = new ToolTip(250) { @@ -123,7 +123,7 @@ public class WidgetClimatePillar extends Widget { }; final int xPos, yPos; - public ClimateButton(WidgetClimatePillar parent, EnumTemperature temperature, float value, int xPos, int yPos) { + public ClimateButton(WidgetClimateBar parent, EnumTemperature temperature, float value, int xPos, int yPos) { this.parent = parent; this.temperature = temperature; this.value = value; diff --git a/src/main/java/forestry/greenhouse/items/ItemGreenhouseScreen.java b/src/main/java/forestry/greenhouse/items/ItemGreenhouseScreen.java index 2f6714e5e..799a61f0c 100644 --- a/src/main/java/forestry/greenhouse/items/ItemGreenhouseScreen.java +++ b/src/main/java/forestry/greenhouse/items/ItemGreenhouseScreen.java @@ -31,7 +31,6 @@ import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import forestry.greenhouse.api.climate.IClimateContainer; import forestry.api.climate.IClimateState; import forestry.api.core.EnumTemperature; import forestry.api.multiblock.IGreenhouseComponent; @@ -42,6 +41,7 @@ import forestry.core.multiblock.MultiblockUtil; import forestry.core.utils.ClimateUtil; import forestry.core.utils.Translator; import forestry.greenhouse.PluginGreenhouse; +import forestry.greenhouse.api.climate.IClimateContainer; import forestry.greenhouse.multiblock.IGreenhouseControllerInternal; public class ItemGreenhouseScreen extends ItemForestry implements IColoredItem { @@ -113,10 +113,15 @@ public class ItemGreenhouseScreen extends ItemForestry implements IColoredItem { @Override public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) { + ItemStack itemStack = player.getHeldItem(hand); + BlockPos itemPos = getGreenhousePos(itemStack); if (!player.isSneaking()) { return EnumActionResult.PASS; } - ItemStack itemStack = player.getHeldItem(hand); + return handleSneaking(world, pos, player, itemStack, itemPos); + } + + private EnumActionResult handleSneaking(World world, BlockPos pos,EntityPlayer player, ItemStack itemStack, BlockPos itemPos){ IGreenhouseComponent component = MultiblockUtil.getComponent(world, pos, IGreenhouseComponent.class); if (component != null) { IGreenhouseController controller = component.getMultiblockLogic().getController(); @@ -131,7 +136,6 @@ public class ItemGreenhouseScreen extends ItemForestry implements IColoredItem { player.sendStatusMessage(new TextComponentTranslation("for.message.greenhouse_screen.position"), true); } } else { - BlockPos itemPos = getGreenhousePos(itemStack); if (itemPos == null) { if (!world.isRemote) { player.sendStatusMessage(new TextComponentTranslation("for.message.greenhouse_screen.fail"), true); @@ -168,11 +172,11 @@ public class ItemGreenhouseScreen extends ItemForestry implements IColoredItem { @SideOnly(Side.CLIENT) public int getColorFromItemstack(ItemStack stack, int tintIndex) { if (tintIndex == 2) { - return isValid(stack, Minecraft.getMinecraft().world) ? 1356406 : 12197655; + return isValid(stack, Minecraft.getMinecraft().world) ? 0x14B276 : 0xBA1F17; } else if (tintIndex == 1) { World world = Minecraft.getMinecraft().world; if (!isValid(stack, world)) { - return 16777215; + return 0xFFFFFF; } BlockPos pos = getGreenhousePos(stack); IGreenhouseControllerInternal controller = MultiblockUtil.getController(world, pos, IGreenhouseComponent.class); @@ -180,6 +184,6 @@ public class ItemGreenhouseScreen extends ItemForestry implements IColoredItem { IClimateState state = container.getState(); return ClimateUtil.getColor(EnumTemperature.getFromValue(state.getTemperature())); } - return 16777215; + return 0xFFFFFF; } } diff --git a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java index c5a58d168..4aff028d1 100644 --- a/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java +++ b/src/main/java/forestry/greenhouse/multiblock/GreenhouseController.java @@ -26,21 +26,13 @@ import net.minecraft.world.biome.Biome; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import forestry.greenhouse.api.climate.GreenhouseState; -import forestry.greenhouse.api.climate.IClimateContainer; -import forestry.greenhouse.api.climate.IClimateContainerListener; import forestry.api.climate.ImmutableClimateState; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.api.core.ICamouflagedTile; -import forestry.greenhouse.api.greenhouse.GreenhouseManager; -import forestry.greenhouse.api.greenhouse.IGreenhouseBlock; -import forestry.greenhouse.api.greenhouse.IGreenhouseLimits; +import forestry.api.core.IErrorLogic; import forestry.api.greenhouse.IGreenhouseListener; import forestry.api.greenhouse.IGreenhouseLogic; -import forestry.greenhouse.api.greenhouse.IGreenhouseProvider; -import forestry.greenhouse.api.greenhouse.IGreenhouseProviderListener; -import forestry.greenhouse.api.greenhouse.Position2D; import forestry.api.multiblock.IGreenhouseComponent; import forestry.api.multiblock.IGreenhouseComponent.Active; import forestry.api.multiblock.IGreenhouseComponent.Listener; @@ -56,8 +48,16 @@ import forestry.core.utils.ItemStackUtil; import forestry.core.utils.NetworkUtil; import forestry.core.utils.Translator; import forestry.energy.EnergyManager; +import forestry.greenhouse.api.climate.GreenhouseState; +import forestry.greenhouse.api.climate.IClimateContainer; +import forestry.greenhouse.api.climate.IClimateContainerListener; +import forestry.greenhouse.api.greenhouse.GreenhouseManager; +import forestry.greenhouse.api.greenhouse.IGreenhouseBlock; +import forestry.greenhouse.api.greenhouse.IGreenhouseLimits; +import forestry.greenhouse.api.greenhouse.IGreenhouseProvider; +import forestry.greenhouse.api.greenhouse.IGreenhouseProviderListener; +import forestry.greenhouse.api.greenhouse.Position2D; import forestry.greenhouse.camouflage.CamouflageHandlerType; -import forestry.greenhouse.multiblock.blocks.GreenhouseException; import forestry.greenhouse.multiblock.blocks.storage.GreenhouseProvider; import forestry.greenhouse.multiblock.blocks.storage.GreenhouseProviderClient; import forestry.greenhouse.multiblock.blocks.storage.GreenhouseProviderServer; @@ -167,6 +167,11 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im } } + @Override + public IErrorLogic getErrorLogic() { + return provider.getErrorLogic(); + } + @Override public ImmutableClimateState getDefaultClimate() { return defaultState; @@ -256,19 +261,6 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im limits = null; } - @Override - public BlockPos getLastValidationErrorPosition() { - BlockPos pos = super.getLastValidationErrorPosition(); - if (pos != null) { - return pos; - } - GreenhouseException exception = provider.getLastNotClosedException(); - if (exception == null) { - return null; - } - return exception.pos; - } - @Override protected void onAssimilate(IMultiblockControllerInternal assimilated) { } diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/blank/BlankBlockHandler.java b/src/main/java/forestry/greenhouse/multiblock/blocks/blank/BlankBlockHandler.java index 2d0a3c1d7..165f3f903 100644 --- a/src/main/java/forestry/greenhouse/multiblock/blocks/blank/BlankBlockHandler.java +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/blank/BlankBlockHandler.java @@ -10,18 +10,17 @@ ******************************************************************************/ package forestry.greenhouse.multiblock.blocks.blank; -import java.util.LinkedList; import java.util.List; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; +import forestry.api.core.IErrorState; import forestry.greenhouse.api.greenhouse.IBlankBlock; import forestry.greenhouse.api.greenhouse.IGreenhouseBlock; import forestry.greenhouse.api.greenhouse.IGreenhouseBlockHandler; import forestry.greenhouse.api.greenhouse.IGreenhouseBlockStorage; import forestry.greenhouse.api.greenhouse.IGreenhouseProvider; -import forestry.greenhouse.multiblock.blocks.GreenhouseException; public class BlankBlockHandler implements IGreenhouseBlockHandler { @@ -54,15 +53,17 @@ public class BlankBlockHandler implements IGreenhouseBlockHandler checkNeighborBlocks(IGreenhouseBlockStorage storage, IBlankBlock blockToCheck) throws GreenhouseException { - List newBlocksToCheck = new LinkedList<>(); + public IErrorState checkNeighborBlocks(IGreenhouseBlockStorage storage, IBlankBlock blockToCheck, List newBlocksToCheck) { BlockPos position = blockToCheck.getPos(); if (storage.setBlock(position, blockToCheck)) { for (EnumFacing facing : EnumFacing.HORIZONTALS) { - checkBlockFacing(storage, blockToCheck, position, facing, newBlocksToCheck); + IErrorState errorState = checkBlockFacing(storage, blockToCheck, position, facing, newBlocksToCheck); + if(errorState != null){ + return errorState; + } } } - return newBlocksToCheck; + return null; } @Override @@ -83,19 +84,23 @@ public class BlankBlockHandler implements IGreenhouseBlockHandler newBlocksToCheck) throws GreenhouseException { + private IErrorState checkBlockFacing(IGreenhouseBlockStorage storage, IBlankBlock blockToCheck, BlockPos rootPos, EnumFacing facing, List newBlocksToCheck) { if (!blockToCheck.isFaceTested(facing)) { BlockPos facingPosition = rootPos.offset(facing); IGreenhouseProvider provider = storage.getProvider(); - provider.checkPosition(facingPosition); + IErrorState errorState = provider.checkPosition(facingPosition); + if(errorState != null){ + return errorState; + } IGreenhouseBlock logicBlock = storage.getBlock(facingPosition); for (IGreenhouseBlockHandler handler : provider.getHandlers()) { - if (handler.onCheckPosition(storage, blockToCheck, facingPosition, facing, logicBlock, newBlocksToCheck)) { + if(handler.onCheckPosition(storage, blockToCheck, facingPosition, facing, logicBlock, newBlocksToCheck)){ break; } } } + return null; } } diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/client/ClientBlockHandler.java b/src/main/java/forestry/greenhouse/multiblock/blocks/client/ClientBlockHandler.java index 27f7263fc..d8098a173 100644 --- a/src/main/java/forestry/greenhouse/multiblock/blocks/client/ClientBlockHandler.java +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/client/ClientBlockHandler.java @@ -11,16 +11,15 @@ package forestry.greenhouse.multiblock.blocks.client; import javax.annotation.Nullable; -import java.util.Collections; import java.util.List; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; +import forestry.api.core.IErrorState; import forestry.greenhouse.api.greenhouse.IGreenhouseBlock; import forestry.greenhouse.api.greenhouse.IGreenhouseBlockHandler; import forestry.greenhouse.api.greenhouse.IGreenhouseBlockStorage; -import forestry.greenhouse.multiblock.blocks.GreenhouseException; public class ClientBlockHandler implements IGreenhouseBlockHandler { @@ -49,12 +48,12 @@ public class ClientBlockHandler implements IGreenhouseBlockHandler checkNeighborBlocks(IGreenhouseBlockStorage storage, ClientBlock blockToCheck) throws GreenhouseException { - return Collections.emptyList(); + public IErrorState checkNeighborBlocks(IGreenhouseBlockStorage storage, ClientBlock blockToCheck, List newBlocks) { + return null; } @Override - public boolean onCheckPosition(IGreenhouseBlockStorage storage, ClientBlock rootBlock, BlockPos position, EnumFacing facing, IGreenhouseBlock block, List newBlocksToCheck) throws GreenhouseException { + public boolean onCheckPosition(IGreenhouseBlockStorage storage, ClientBlock rootBlock, BlockPos position, EnumFacing facing, IGreenhouseBlock block, List newBlocksToCheck) { return false; } diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProvider.java b/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProvider.java index a6b49386a..f933a9c31 100644 --- a/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProvider.java +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProvider.java @@ -18,13 +18,14 @@ import java.util.Set; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import forestry.api.core.ForestryAPI; +import forestry.api.core.IErrorLogic; +import forestry.core.network.IStreamable; import forestry.greenhouse.api.climate.GreenhouseState; import forestry.greenhouse.api.climate.IClimateContainer; import forestry.greenhouse.api.greenhouse.IGreenhouseLimits; import forestry.greenhouse.api.greenhouse.IGreenhouseProvider; import forestry.greenhouse.api.greenhouse.IGreenhouseProviderListener; -import forestry.core.network.IStreamable; -import forestry.greenhouse.multiblock.blocks.GreenhouseException; public abstract class GreenhouseProvider implements IGreenhouseProvider, IStreamable { @@ -32,13 +33,14 @@ public abstract class GreenhouseProvider implements IGreenhouseProvider, IStream protected final GreenhouseBlockStorage storage; protected final World world; protected final IClimateContainer container; + private final IErrorLogic errorLogic; - @Nullable - protected GreenhouseException lastNotClosedException; protected BlockPos centerPos; protected boolean ready; protected GreenhouseState state; + @Nullable protected IGreenhouseLimits limits; + @Nullable protected IGreenhouseLimits usedLimits; protected int size; @@ -49,12 +51,14 @@ public abstract class GreenhouseProvider implements IGreenhouseProvider, IStream this.container = container; this.state = GreenhouseState.UNREADY; this.storage = new GreenhouseBlockStorage(this, world); + this.errorLogic = ForestryAPI.errorStateRegistry.createErrorLogic(); } public abstract void create(); - public GreenhouseException getLastNotClosedException() { - return lastNotClosedException; + @Override + public IErrorLogic getErrorLogic() { + return errorLogic; } @Override @@ -86,14 +90,6 @@ public abstract class GreenhouseProvider implements IGreenhouseProvider, IStream ready = false; } - @Override - public String getLastNotClosedError() { - if (lastNotClosedException == null) { - return null; - } - return lastNotClosedException.getMessage(); - } - @Override public boolean hasUnloadedChunks() { return state == GreenhouseState.UNLOADED_CHUNK; diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProviderClient.java b/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProviderClient.java index 837e83a43..698f4b6d5 100644 --- a/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProviderClient.java +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProviderClient.java @@ -18,15 +18,15 @@ import net.minecraft.client.Minecraft; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import forestry.greenhouse.api.climate.GreenhouseState; -import forestry.greenhouse.api.climate.IClimateContainer; +import forestry.api.core.IErrorState; import forestry.api.greenhouse.IClimateHousing; -import forestry.greenhouse.api.greenhouse.IGreenhouseBlockHandler; -import forestry.greenhouse.api.greenhouse.Position2D; import forestry.api.multiblock.IGreenhouseController; import forestry.core.network.PacketBufferForestry; +import forestry.greenhouse.api.climate.GreenhouseState; +import forestry.greenhouse.api.climate.IClimateContainer; +import forestry.greenhouse.api.greenhouse.IGreenhouseBlockHandler; +import forestry.greenhouse.api.greenhouse.Position2D; import forestry.greenhouse.multiblock.GreenhouseLimits; -import forestry.greenhouse.multiblock.blocks.GreenhouseException; import forestry.greenhouse.multiblock.blocks.client.ClientBlockHandler; public class GreenhouseProviderClient extends GreenhouseProvider { @@ -60,6 +60,7 @@ public class GreenhouseProviderClient extends GreenhouseProvider { if (data.readBoolean()) { usedLimits = new GreenhouseLimits(data); } + getErrorLogic().readData(data); } @Override @@ -82,7 +83,8 @@ public class GreenhouseProviderClient extends GreenhouseProvider { } @Override - public void checkPosition(BlockPos position) throws GreenhouseException { + public IErrorState checkPosition(BlockPos position) { + return null; } @Override diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProviderServer.java b/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProviderServer.java index a87e1780a..4549dae02 100644 --- a/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProviderServer.java +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/storage/GreenhouseProviderServer.java @@ -14,25 +14,26 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.Stack; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; -import net.minecraft.util.text.TextComponentString; import net.minecraft.world.World; +import forestry.api.core.IErrorLogic; +import forestry.api.core.IErrorState; import forestry.api.greenhouse.IClimateHousing; import forestry.api.multiblock.IGreenhouseController; +import forestry.core.errors.EnumErrorCode; import forestry.core.network.PacketBufferForestry; import forestry.core.utils.NetworkUtil; -import forestry.core.utils.Translator; import forestry.greenhouse.api.climate.GreenhouseState; import forestry.greenhouse.api.climate.IClimateContainer; import forestry.greenhouse.api.greenhouse.IBlankBlock; @@ -42,7 +43,6 @@ import forestry.greenhouse.api.greenhouse.IGreenhouseLimits; import forestry.greenhouse.api.greenhouse.Position2D; import forestry.greenhouse.multiblock.GreenhouseLimits; import forestry.greenhouse.multiblock.GreenhouseLimitsBuilder; -import forestry.greenhouse.multiblock.blocks.GreenhouseException; import forestry.greenhouse.multiblock.blocks.blank.BlankBlockHandler; import forestry.greenhouse.multiblock.blocks.wall.WallBlockHandler; import forestry.greenhouse.multiblock.blocks.world.GreenhouseBlockManager; @@ -58,7 +58,6 @@ public class GreenhouseProviderServer extends GreenhouseProvider { private Position2D maxSize; private Position2D minSize; private boolean needReload; - private boolean needUpdate; private long previousUpdateTick; public GreenhouseProviderServer(World world, IClimateContainer container) { @@ -119,6 +118,7 @@ public class GreenhouseProviderServer extends GreenhouseProvider { } else { data.writeBoolean(false); } + getErrorLogic().writeData(data); } @Override @@ -135,7 +135,7 @@ public class GreenhouseProviderServer extends GreenhouseProvider { @Override public void onUnloadChunk(long chunkPos) { unloadedChunks.add(chunkPos); - lastNotClosedException = new GreenhouseException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.space.unloaded")); + getErrorLogic().setCondition(true, EnumErrorCode.NOT_LOADED); state = GreenhouseState.UNLOADED_CHUNK; } @@ -148,18 +148,19 @@ public class GreenhouseProviderServer extends GreenhouseProvider { } } - public void checkPosition(BlockPos position) throws GreenhouseException { + public IErrorState checkPosition(BlockPos position) { if (maxSize.getX() < position.getX() || maxSize.getZ() < position.getZ() || minSize.getX() > position.getX() || minSize.getZ() > position.getZ()) { - throw new GreenhouseException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.space.notclosed", position.getX(), position.getZ())).setPos(position); + return EnumErrorCode.NOT_CLOSED; } if (!world.isBlockLoaded(position)) { unloadedChunks.add(ChunkPos.asLong(position.getX() >> 4, position.getZ() >> 4)); - throw new GreenhouseException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.space.unloaded", position.getX(), position.getZ())); + return EnumErrorCode.NOT_LOADED; } + return null; } @Override @@ -193,10 +194,6 @@ public class GreenhouseProviderServer extends GreenhouseProvider { Stack blocksToCheck = new Stack(); blocksToCheck.add(BlankBlockHandler.getInstance().createBlock(storage, null, null, centerPos)); checkState(checkBlocks(blocksToCheck)); - EntityPlayer player = world.getClosestPlayer(centerPos.getX(), centerPos.getY(), centerPos.getZ(), 100000.0D, false); - if (!world.isRemote && lastNotClosedException != null && player != null) { - player.sendMessage(new TextComponentString(lastNotClosedException.getMessage())); - } } private void checkState(GreenhouseState state) { @@ -207,75 +204,63 @@ public class GreenhouseProviderServer extends GreenhouseProvider { * Check all internal blocks. */ private GreenhouseState checkBlocks(Collection blocks) { - try { - if (minSize == null || maxSize == null || minSize == Position2D.NULL_POSITION || maxSize == Position2D.NULL_POSITION) { - checkMinMax(); - } - int greenhouseHeight = centerPos.getY(); - int greenhouseDepth = centerPos.getY(); - int height = 0; - int depth = 0; - int maximalHeight = ((IGreenhouseController) container.getParent()).getCenterCoordinates().getY() + limits.getHeight(); - GreenhouseLimitsBuilder builder = new GreenhouseLimitsBuilder(); - Stack blocksToCheck = new Stack(); - blocksToCheck.addAll(blocks); - while (!blocksToCheck.isEmpty()) { - IGreenhouseBlock blockToCheck = blocksToCheck.pop(); - if (blockToCheck != null) { - BlockPos position = blockToCheck.getPos(); - IGreenhouseBlockHandler handler = blockToCheck.getHandler(); - builder.recalculate(position); - List newBlocksToCheck = handler.checkNeighborBlocks(storage, blockToCheck); - blocksToCheck.addAll(newBlocksToCheck); - if (blockToCheck instanceof IBlankBlock) { - int positionHeight = getHeight(position, maximalHeight); - int positionDepth = getDepth(position); - if (positionHeight == -1) { - throw new GreenhouseException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.roof.notclosed", position.getX(), position.getY(), position.getZ())).setPos(position); - } - if (positionHeight > greenhouseHeight) { - greenhouseHeight = positionHeight; - } - height += positionHeight - centerPos.getY(); - if (positionDepth < greenhouseDepth) { - greenhouseDepth = positionDepth; - } - depth += centerPos.getY() - positionDepth; + IErrorLogic errorLogic = getErrorLogic(); + errorLogic.clearErrors(); + if (minSize == null || maxSize == null || minSize == Position2D.NULL_POSITION || maxSize == Position2D.NULL_POSITION) { + Position2D maxCoordinates = limits.getMaximumCoordinates(); + maxSize = maxCoordinates.add(1, 1).add(centerPos.getX(), centerPos.getZ()); + + Position2D minCoordinates = limits.getMinimumCoordinates(); + minSize = minCoordinates.add(-1, -1).add(centerPos.getX(), centerPos.getZ()); + } + int greenhouseHeight = centerPos.getY(); + int greenhouseDepth = centerPos.getY(); + int height = 0; + int depth = 0; + int maximalHeight = ((IGreenhouseController) container.getParent()).getCenterCoordinates().getY() + limits.getHeight(); + GreenhouseLimitsBuilder builder = new GreenhouseLimitsBuilder(); + Stack blocksToCheck = new Stack(); + blocksToCheck.addAll(blocks); + while (!blocksToCheck.isEmpty()) { + IGreenhouseBlock blockToCheck = blocksToCheck.pop(); + if (blockToCheck != null) { + BlockPos position = blockToCheck.getPos(); + IGreenhouseBlockHandler handler = blockToCheck.getHandler(); + builder.recalculate(position); + List newBlocksToCheck = new LinkedList<>(); + IErrorState errorState = handler.checkNeighborBlocks(storage, blockToCheck, newBlocksToCheck); + if(errorState != null){ + errorLogic.setCondition(true, errorState); + } + blocksToCheck.addAll(newBlocksToCheck); + if (blockToCheck instanceof IBlankBlock) { + int positionHeight = getHeight(position, maximalHeight); + int positionDepth = getDepth(position); + if (positionHeight == -1) { + errorLogic.setCondition(true, EnumErrorCode.NOT_CLOSED); + //throw new GreenhouseException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.roof.notclosed", position.getX(), position.getY(), position.getZ())).setPos(position); } + if (positionHeight > greenhouseHeight) { + greenhouseHeight = positionHeight; + } + height += positionHeight - centerPos.getY(); + if (positionDepth < greenhouseDepth) { + greenhouseDepth = positionDepth; + } + depth += centerPos.getY() - positionDepth; } } - this.size = height + depth + storage.getBlockCount(); - lastNotClosedException = null; - usedLimits = builder.build(greenhouseHeight, greenhouseDepth); - return GreenhouseState.CLOSED; - } catch (GreenhouseException exception) { - lastNotClosedException = exception; - if (!unloadedChunks.isEmpty()) { - return GreenhouseState.UNLOADED_CHUNK; - } + } + if (!unloadedChunks.isEmpty()) { + errorLogic.setCondition(true, EnumErrorCode.NOT_LOADED); + return GreenhouseState.UNLOADED_CHUNK; + } + if(errorLogic.hasErrors()){ return GreenhouseState.OPEN; } - } - - private void checkMinMax() throws GreenhouseException { - if (limits == null) { - minSize = maxSize = null; - throw new GreenhouseException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.edges")); - } - if (limits.getMaximumCoordinates() != null) { - Position2D edge = limits.getMaximumCoordinates(); - maxSize = edge.add(1, 1).add(centerPos.getX(), centerPos.getZ()); - } else { - maxSize = null; - throw new GreenhouseException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.edge")); - } - if (limits.getMinimumCoordinates() != null) { - Position2D edge = limits.getMinimumCoordinates(); - minSize = edge.add(-1, -1).add(centerPos.getX(), centerPos.getZ()); - } else { - minSize = null; - throw new GreenhouseException(Translator.translateToLocalFormatted("for.multiblock.greenhouse.error.edge")); - } + this.size = height + depth + storage.getBlockCount(); + usedLimits = builder.build(greenhouseHeight, greenhouseDepth); + return GreenhouseState.CLOSED; } public int getHeight(BlockPos pos, int maximalHeight) { diff --git a/src/main/java/forestry/greenhouse/multiblock/blocks/wall/WallBlockHandler.java b/src/main/java/forestry/greenhouse/multiblock/blocks/wall/WallBlockHandler.java index e4d90a26f..e05d73a3a 100644 --- a/src/main/java/forestry/greenhouse/multiblock/blocks/wall/WallBlockHandler.java +++ b/src/main/java/forestry/greenhouse/multiblock/blocks/wall/WallBlockHandler.java @@ -11,7 +11,6 @@ package forestry.greenhouse.multiblock.blocks.wall; import javax.annotation.Nullable; -import java.util.Collections; import java.util.List; import net.minecraft.block.Block; @@ -21,6 +20,7 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import forestry.api.core.IErrorState; import forestry.greenhouse.api.greenhouse.IBlankBlock; import forestry.greenhouse.api.greenhouse.IGreenhouseBlock; import forestry.greenhouse.api.greenhouse.IGreenhouseBlockHandler; @@ -28,7 +28,6 @@ import forestry.greenhouse.api.greenhouse.IGreenhouseBlockStorage; import forestry.greenhouse.api.greenhouse.IGreenhouseProvider; import forestry.greenhouse.api.greenhouse.IGreenhouseProviderListener; import forestry.greenhouse.api.greenhouse.IWallBlock; -import forestry.greenhouse.multiblock.blocks.GreenhouseException; public class WallBlockHandler implements IGreenhouseBlockHandler { @@ -63,8 +62,8 @@ public class WallBlockHandler implements IGreenhouseBlockHandler checkNeighborBlocks(IGreenhouseBlockStorage storage, IWallBlock blockToCheck) throws GreenhouseException { - return Collections.emptyList(); + public IErrorState checkNeighborBlocks(IGreenhouseBlockStorage storage, IWallBlock blockToCheck, List newBlocks) { + return null; } @Override diff --git a/src/main/resources/assets/forestry/textures/gui/errors/not_closed.png b/src/main/resources/assets/forestry/textures/gui/errors/not_closed.png new file mode 100644 index 000000000..296f15347 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/gui/errors/not_closed.png differ diff --git a/src/main/resources/assets/forestry/textures/gui/errors/not_loaded.png b/src/main/resources/assets/forestry/textures/gui/errors/not_loaded.png new file mode 100644 index 000000000..1609c6fc3 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/gui/errors/not_loaded.png differ diff --git a/src/main/resources/assets/forestry/textures/gui/errors/too_large.png b/src/main/resources/assets/forestry/textures/gui/errors/too_large.png new file mode 100644 index 000000000..4e13b0c99 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/gui/errors/too_large.png differ diff --git a/src/main/resources/assets/forestry/textures/gui/greenhouse.png b/src/main/resources/assets/forestry/textures/gui/greenhouse.png index 098a78772..bd7c9a599 100644 Binary files a/src/main/resources/assets/forestry/textures/gui/greenhouse.png and b/src/main/resources/assets/forestry/textures/gui/greenhouse.png differ