From 02de4bce7fc74dfed9e482b820a8b3f14b9631ff Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 15 Feb 2020 13:07:43 +0100 Subject: [PATCH] Also apply the spawn lamp fix in 1.15 Closes #77 --- .../naturesaura/blocks/BlockSpawnLamp.java | 17 +++++++-------- .../blocks/tiles/TileEntitySpawnLamp.java | 21 +++++++++++++++++++ .../ellpeck/naturesaura/misc/WorldData.java | 7 +++---- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockSpawnLamp.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockSpawnLamp.java index 9af43d86..2ec46d29 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockSpawnLamp.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockSpawnLamp.java @@ -1,10 +1,11 @@ package de.ellpeck.naturesaura.blocks; -import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; +import de.ellpeck.naturesaura.api.misc.IWorldData; import de.ellpeck.naturesaura.api.render.IVisualizable; import de.ellpeck.naturesaura.blocks.tiles.TileEntitySpawnLamp; import de.ellpeck.naturesaura.data.BlockStateGenerator; +import de.ellpeck.naturesaura.misc.WorldData; import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.reg.ICustomBlockState; @@ -53,17 +54,15 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable, return; IWorld world = event.getWorld(); BlockPos pos = new BlockPos(event.getX(), event.getY(), event.getZ()); - Helper.getTileEntitiesInArea(world, pos, 48, tile -> { - if (!(tile instanceof TileEntitySpawnLamp)) - return false; - TileEntitySpawnLamp lamp = (TileEntitySpawnLamp) tile; + WorldData data = (WorldData) IWorldData.getWorldData((World) world); + for (TileEntitySpawnLamp lamp : data.spawnLamps) { int range = lamp.getRadius(); if (range <= 0) - return false; + continue; BlockPos lampPos = lamp.getPos(); if (!new AxisAlignedBB(lampPos).grow(range).contains(new Vec3d(pos))) - return false; + continue; MobEntity entity = (MobEntity) event.getEntityLiving(); if (entity.canSpawn(world, event.getSpawnReason()) && entity.isNotColliding(world)) { @@ -75,8 +74,8 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable, } event.setResult(Event.Result.DENY); - return true; - }); + break; + } } @Override diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntitySpawnLamp.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntitySpawnLamp.java index 600b219b..b8d8b302 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntitySpawnLamp.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntitySpawnLamp.java @@ -1,5 +1,8 @@ package de.ellpeck.naturesaura.blocks.tiles; +import de.ellpeck.naturesaura.api.misc.IWorldData; +import de.ellpeck.naturesaura.misc.WorldData; + public class TileEntitySpawnLamp extends TileEntityImpl { public TileEntitySpawnLamp() { @@ -10,6 +13,24 @@ public class TileEntitySpawnLamp extends TileEntityImpl { return this.redstonePower * 3; } + @Override + public void validate() { + super.validate(); + if (!this.world.isRemote) { + WorldData data = (WorldData) IWorldData.getWorldData(this.world); + data.spawnLamps.add(this); + } + } + + @Override + public void remove() { + super.remove(); + if (!this.world.isRemote) { + WorldData data = (WorldData) IWorldData.getWorldData(this.world); + data.spawnLamps.remove(this); + } + } + @Override public void onRedstonePowerChange(int newPower) { super.onRedstonePowerChange(newPower); diff --git a/src/main/java/de/ellpeck/naturesaura/misc/WorldData.java b/src/main/java/de/ellpeck/naturesaura/misc/WorldData.java index 69cf35e5..c9551179 100644 --- a/src/main/java/de/ellpeck/naturesaura/misc/WorldData.java +++ b/src/main/java/de/ellpeck/naturesaura/misc/WorldData.java @@ -6,6 +6,7 @@ import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.misc.IWorldData; import de.ellpeck.naturesaura.blocks.tiles.ItemStackHandlerNA; +import de.ellpeck.naturesaura.blocks.tiles.TileEntitySpawnLamp; import de.ellpeck.naturesaura.items.ModItems; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; @@ -23,15 +24,13 @@ import net.minecraftforge.common.util.LazyOptional; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class WorldData implements IWorldData { public final ListMultimap> effectPowders = ArrayListMultimap.create(); public final List recentlyConvertedMossStones = new ArrayList<>(); private final Map enderStorages = new HashMap<>(); + public final Set spawnLamps = new HashSet<>(); @Nullable @Override