From 6938e1030dd678b739f1fc66daecc7c0488ebb39 Mon Sep 17 00:00:00 2001 From: LemADEC Date: Fri, 10 Nov 2017 01:19:08 +0100 Subject: [PATCH] Improved laser tree farm accessibility Players are tempted to place the farming block below soil while it should be level with it. To address that, the machine will be 'jammed' with some particles when misplaced. --- .../collection/TileEntityLaserTreeFarm.java | 27 ++++++++++++++++--- .../network/MessageSpawnParticle.java | 26 +++++++++++++++++- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/main/java/cr0s/warpdrive/block/collection/TileEntityLaserTreeFarm.java b/src/main/java/cr0s/warpdrive/block/collection/TileEntityLaserTreeFarm.java index 50c5ec3f..f4cf7955 100644 --- a/src/main/java/cr0s/warpdrive/block/collection/TileEntityLaserTreeFarm.java +++ b/src/main/java/cr0s/warpdrive/block/collection/TileEntityLaserTreeFarm.java @@ -139,11 +139,30 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner { return; } } else if (currentState == STATE_SCAN) { - int energyCost = TREE_FARM_ENERGY_PER_SURFACE * (1 + 2 * radiusX) * (1 + 2 * radiusZ); + final int energyCost = TREE_FARM_ENERGY_PER_SURFACE * (1 + 2 * radiusX) * (1 + 2 * radiusZ); if (delayTicks == 1) { if (WarpDriveConfig.LOGGING_COLLECTION) { WarpDrive.logger.debug("Scan pre-tick"); } + + // validate environment: clearance above + final Block blockAbove = worldObj.getBlock(xCoord, yCoord + 1, zCoord); + if ( !isLog(blockAbove) + && !isLeaf(blockAbove) + && !blockAbove.isAir(worldObj, xCoord, yCoord + 1, zCoord) ) { + PacketHandler.sendSpawnParticlePacket(worldObj, "jammed", (byte) 5, new Vector3(this).translate(0.5F), + new Vector3(0.0D, 0.0D, 0.0D), + 1.0F, 1.0F, 1.0F, + 1.0F, 1.0F, 1.0F, + 32); + + currentState = STATE_WARMUP; // going back to warmup state to show the animation when it'll be back online + delayTicks = 0; + delayTargetTicks = TREE_FARM_LOW_POWER_DELAY_TICKS; + updateMetadata(BlockLaserTreeFarm.ICON_SCANNING_LOW_POWER); + return; + } + // check power level enoughPower = consumeEnergyFromLaserMediums(energyCost, true); if (!enoughPower) { @@ -254,7 +273,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner { } // consume power - int energyCost = TREE_FARM_ENERGY_PER_WET_SPOT; + final int energyCost = TREE_FARM_ENERGY_PER_WET_SPOT; enoughPower = consumeEnergyFromLaserMediums(energyCost, false); if (!enoughPower) { delayTargetTicks = TREE_FARM_LOW_POWER_DELAY_TICKS; @@ -415,8 +434,8 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner { } // consume power - double energyCost = TREE_FARM_ENERGY_PER_SAPLING; - enoughPower = consumeEnergyFromLaserMediums((int) Math.round(energyCost), false); + final int energyCost = TREE_FARM_ENERGY_PER_SAPLING; + enoughPower = consumeEnergyFromLaserMediums(energyCost, false); if (!enoughPower) { delayTargetTicks = TREE_FARM_LOW_POWER_DELAY_TICKS; updateMetadata(BlockLaserTreeFarm.ICON_PLANTING_LOW_POWER); diff --git a/src/main/java/cr0s/warpdrive/network/MessageSpawnParticle.java b/src/main/java/cr0s/warpdrive/network/MessageSpawnParticle.java index 8a5a37d9..43b4c5bc 100644 --- a/src/main/java/cr0s/warpdrive/network/MessageSpawnParticle.java +++ b/src/main/java/cr0s/warpdrive/network/MessageSpawnParticle.java @@ -1,5 +1,6 @@ package cr0s.warpdrive.network; +import cr0s.warpdrive.Commons; import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.config.WarpDriveConfig; import cr0s.warpdrive.data.Vector3; @@ -14,6 +15,7 @@ import net.minecraft.client.particle.EntityExplodeFX; import net.minecraft.client.particle.EntityFX; import net.minecraft.client.particle.EntityFireworkSparkFX; import net.minecraft.client.particle.EntityFlameFX; +import net.minecraft.client.particle.EntityHeartFX; import net.minecraft.client.particle.EntitySnowShovelFX; import net.minecraft.client.particle.EntitySpellParticleFX; import net.minecraft.init.Items; @@ -25,6 +27,7 @@ import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.minecraftforge.common.util.ForgeDirection; public class MessageSpawnParticle implements IMessage, IMessageHandler { @@ -115,7 +118,7 @@ public class MessageSpawnParticle implements IMessage, IMessageHandler= 0.0F && baseGreen >= 0.0F && baseBlue >= 0.0F) { effect.setRBGColorF(baseRed, baseGreen, baseBlue);