Also apply the spawn lamp fix in 1.15

Closes #77
This commit is contained in:
Ellpeck 2020-02-15 13:07:43 +01:00
parent 90e93bdb35
commit 02de4bce7f
3 changed files with 32 additions and 13 deletions

View file

@ -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

View file

@ -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);

View file

@ -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<ResourceLocation, Tuple<Vec3d, Integer>> effectPowders = ArrayListMultimap.create();
public final List<BlockPos> recentlyConvertedMossStones = new ArrayList<>();
private final Map<String, ItemStackHandlerNA> enderStorages = new HashMap<>();
public final Set<TileEntitySpawnLamp> spawnLamps = new HashSet<>();
@Nullable
@Override