fixed spawn lamps using unnecessary resources

Closes #77
This commit is contained in:
Ellpeck 2020-02-15 13:03:48 +01:00
parent 0602e3928b
commit 074f0b9ab9
3 changed files with 33 additions and 9 deletions

View file

@ -1,9 +1,10 @@
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.misc.WorldData;
import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.block.SoundType;
@ -44,17 +45,15 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable
return;
World 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);
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;
EntityLiving entity = (EntityLiving) event.getEntityLiving();
if (entity.getCanSpawnHere() && entity.isNotColliding()) {
@ -66,8 +65,8 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable
}
event.setResult(Event.Result.DENY);
return true;
});
break;
}
}
@Override

View file

@ -1,11 +1,32 @@
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 int getRadius() {
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 invalidate() {
super.invalidate();
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.NBTBase;
@ -20,11 +21,14 @@ import net.minecraftforge.common.capabilities.Capability;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class WorldData implements IWorldData {
private final Map<String, ItemStackHandlerNA> enderStorages = new HashMap<>();
public final ListMultimap<ResourceLocation, Tuple<Vec3d, Integer>> effectPowders = ArrayListMultimap.create();
public final Set<TileEntitySpawnLamp> spawnLamps = new HashSet<>();
@Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {