From 9282c08df97a73bcd0332de166ca706f40bcfac0 Mon Sep 17 00:00:00 2001 From: bruberu <80226372+bruberu@users.noreply.github.com> Date: Mon, 30 Sep 2024 18:38:24 -0500 Subject: [PATCH] fix: sprinklers being forever active & maybe the mob extractor --- .../java/gregtechfoodoption/GTFOValues.java | 1 + .../covers/CoverSprinkler.java | 34 +++++++++++++++---- .../machines/MetaTileEntityMobExtractor.java | 25 +++++++++----- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/main/java/gregtechfoodoption/GTFOValues.java b/src/main/java/gregtechfoodoption/GTFOValues.java index 99b4f266..0c1451f0 100644 --- a/src/main/java/gregtechfoodoption/GTFOValues.java +++ b/src/main/java/gregtechfoodoption/GTFOValues.java @@ -28,6 +28,7 @@ public class GTFOValues { public static final int UPDATE_OPERATION_POS = assignId(); public static final int UPDATE_SPRINKLER_DATA = assignId(); + public static final int UPDATE_SPRINKLER_EXISTENCE = assignId(); public static final int UPDATE_FARMER_OUTPUT_FACING = assignId(); public static final int UPDATE_KITCHEN_STATUS = assignId(); public static final int UPDATE_KITCHEN_ORDER = assignId(); diff --git a/src/main/java/gregtechfoodoption/covers/CoverSprinkler.java b/src/main/java/gregtechfoodoption/covers/CoverSprinkler.java index 4a8439e6..aa483e60 100644 --- a/src/main/java/gregtechfoodoption/covers/CoverSprinkler.java +++ b/src/main/java/gregtechfoodoption/covers/CoverSprinkler.java @@ -38,6 +38,7 @@ import org.jetbrains.annotations.NotNull; import static gregtechfoodoption.GTFOValues.UPDATE_SPRINKLER_DATA; +import static gregtechfoodoption.GTFOValues.UPDATE_SPRINKLER_EXISTENCE; import static net.minecraft.block.BlockFarmland.MOISTURE; public class CoverSprinkler extends CoverBase implements ITickable { @@ -69,6 +70,21 @@ public void renderCover(CCRenderState renderState, Matrix4 translation, IVertexO GTFOClientHandler.SPRINKLER_OVERLAY.renderSided(this.getAttachedSide(), plateBox, renderState, pipeline, translation); } + @Override + public void onRemoval() { + super.onRemoval(); + writeCustomData(UPDATE_SPRINKLER_EXISTENCE, packetBuffer -> { + packetBuffer.writeBoolean(false); + }); + } + + @SideOnly(Side.CLIENT) + private void turnOffParticles() { + if (sprinkleMaker != null) { + sprinkleMaker.setExpired(); + } + } + public boolean canShowSprinkles() { return wasWorking && showsSprinkles; } @@ -171,12 +187,18 @@ private void syncAllData() { @Override public void readCustomData(int id, PacketBuffer packetBuffer) { super.readCustomData(id, packetBuffer); - if (id == UPDATE_SPRINKLER_DATA && this.getWorld().isRemote) { - this.operationPosition = new BlockPos.MutableBlockPos(packetBuffer.readBlockPos()); - this.sprinkleColor = packetBuffer.readInt(); - this.wasWorking = packetBuffer.readBoolean(); - this.showsSprinkles = packetBuffer.readBoolean(); - this.scheduleRenderUpdate(); + if (this.getWorld().isRemote) { + if (id == UPDATE_SPRINKLER_DATA) { + this.operationPosition = new BlockPos.MutableBlockPos(packetBuffer.readBlockPos()); + this.sprinkleColor = packetBuffer.readInt(); + this.wasWorking = packetBuffer.readBoolean(); + this.showsSprinkles = packetBuffer.readBoolean(); + this.scheduleRenderUpdate(); + } else if (id == UPDATE_SPRINKLER_EXISTENCE) { + if (!packetBuffer.readBoolean()) { + turnOffParticles(); + } + } } } diff --git a/src/main/java/gregtechfoodoption/machines/MetaTileEntityMobExtractor.java b/src/main/java/gregtechfoodoption/machines/MetaTileEntityMobExtractor.java index e026466a..26f246d9 100644 --- a/src/main/java/gregtechfoodoption/machines/MetaTileEntityMobExtractor.java +++ b/src/main/java/gregtechfoodoption/machines/MetaTileEntityMobExtractor.java @@ -48,18 +48,22 @@ protected RecipeLogicEnergy createWorkable(RecipeMap recipeMap) { protected boolean checkRecipe(@Nonnull Recipe recipe) { ResourceLocation entityRequired = recipe.getProperty(MobOnTopProperty.getInstance(), null); - if (this.nearbyEntities == null || this.getOffsetTimer() % 5 == 0) + if (entityRequired == null) + return true; + + if (this.attackableTarget == null || this.getOffsetTimer() % 5 == 0) { this.nearbyEntities = getEntitiesInProximity(); - for (Entity entity : nearbyEntities) { - if (EntityList.isMatchingName(entity, entityRequired)) { - if (entity instanceof EntityLivingBase) // Prepare to cause damage if needed. - attackableTarget = (EntityLivingBase) entity; - else - attackableTarget = null; - return true; + for (Entity entity : nearbyEntities) { + if (EntityList.isMatchingName(entity, entityRequired)) { + if (entity instanceof EntityLivingBase) // Prepare to cause damage if needed. + attackableTarget = (EntityLivingBase) entity; + else + attackableTarget = null; + return true; + } } } - return false; + return attackableTarget != null; } protected List getEntitiesInProximity() { @@ -73,6 +77,9 @@ protected void damageEntity(Recipe recipe) { float damage = recipe.getProperty(CauseDamageProperty.getInstance(), 0f); if (damage > 0) { attackableTarget.attackEntityFrom(GTFODamageSources.EXTRACTION, damage); + if (attackableTarget.isDead) { + attackableTarget = null; + } } } }