Skip to content

Commit

Permalink
fix: sprinklers being forever active & maybe the mob extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
bruberu committed Sep 30, 2024
1 parent c9060c9 commit 9282c08
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/main/java/gregtechfoodoption/GTFOValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
34 changes: 28 additions & 6 deletions src/main/java/gregtechfoodoption/covers/CoverSprinkler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entity> getEntitiesInProximity() {
Expand All @@ -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;
}
}
}
}
Expand Down

0 comments on commit 9282c08

Please sign in to comment.