mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-12-04 16:28:33 +01:00
parent
0602e3928b
commit
074f0b9ab9
3 changed files with 33 additions and 9 deletions
|
@ -1,9 +1,10 @@
|
||||||
package de.ellpeck.naturesaura.blocks;
|
package de.ellpeck.naturesaura.blocks;
|
||||||
|
|
||||||
import de.ellpeck.naturesaura.Helper;
|
|
||||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
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.api.render.IVisualizable;
|
||||||
import de.ellpeck.naturesaura.blocks.tiles.TileEntitySpawnLamp;
|
import de.ellpeck.naturesaura.blocks.tiles.TileEntitySpawnLamp;
|
||||||
|
import de.ellpeck.naturesaura.misc.WorldData;
|
||||||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||||
import de.ellpeck.naturesaura.packet.PacketParticles;
|
import de.ellpeck.naturesaura.packet.PacketParticles;
|
||||||
import net.minecraft.block.SoundType;
|
import net.minecraft.block.SoundType;
|
||||||
|
@ -44,17 +45,15 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable
|
||||||
return;
|
return;
|
||||||
World world = event.getWorld();
|
World world = event.getWorld();
|
||||||
BlockPos pos = new BlockPos(event.getX(), event.getY(), event.getZ());
|
BlockPos pos = new BlockPos(event.getX(), event.getY(), event.getZ());
|
||||||
Helper.getTileEntitiesInArea(world, pos, 48, tile -> {
|
WorldData data = (WorldData) IWorldData.getWorldData(world);
|
||||||
if (!(tile instanceof TileEntitySpawnLamp))
|
for (TileEntitySpawnLamp lamp : data.spawnLamps) {
|
||||||
return false;
|
|
||||||
TileEntitySpawnLamp lamp = (TileEntitySpawnLamp) tile;
|
|
||||||
int range = lamp.getRadius();
|
int range = lamp.getRadius();
|
||||||
if (range <= 0)
|
if (range <= 0)
|
||||||
return false;
|
continue;
|
||||||
|
|
||||||
BlockPos lampPos = lamp.getPos();
|
BlockPos lampPos = lamp.getPos();
|
||||||
if (!new AxisAlignedBB(lampPos).grow(range).contains(new Vec3d(pos)))
|
if (!new AxisAlignedBB(lampPos).grow(range).contains(new Vec3d(pos)))
|
||||||
return false;
|
continue;
|
||||||
|
|
||||||
EntityLiving entity = (EntityLiving) event.getEntityLiving();
|
EntityLiving entity = (EntityLiving) event.getEntityLiving();
|
||||||
if (entity.getCanSpawnHere() && entity.isNotColliding()) {
|
if (entity.getCanSpawnHere() && entity.isNotColliding()) {
|
||||||
|
@ -66,8 +65,8 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable
|
||||||
}
|
}
|
||||||
|
|
||||||
event.setResult(Event.Result.DENY);
|
event.setResult(Event.Result.DENY);
|
||||||
return true;
|
break;
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,11 +1,32 @@
|
||||||
package de.ellpeck.naturesaura.blocks.tiles;
|
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 class TileEntitySpawnLamp extends TileEntityImpl {
|
||||||
|
|
||||||
public int getRadius() {
|
public int getRadius() {
|
||||||
return this.redstonePower * 3;
|
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
|
@Override
|
||||||
public void onRedstonePowerChange(int newPower) {
|
public void onRedstonePowerChange(int newPower) {
|
||||||
super.onRedstonePowerChange(newPower);
|
super.onRedstonePowerChange(newPower);
|
||||||
|
|
|
@ -6,6 +6,7 @@ import de.ellpeck.naturesaura.Helper;
|
||||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||||
import de.ellpeck.naturesaura.api.misc.IWorldData;
|
import de.ellpeck.naturesaura.api.misc.IWorldData;
|
||||||
import de.ellpeck.naturesaura.blocks.tiles.ItemStackHandlerNA;
|
import de.ellpeck.naturesaura.blocks.tiles.ItemStackHandlerNA;
|
||||||
|
import de.ellpeck.naturesaura.blocks.tiles.TileEntitySpawnLamp;
|
||||||
import de.ellpeck.naturesaura.items.ModItems;
|
import de.ellpeck.naturesaura.items.ModItems;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTBase;
|
import net.minecraft.nbt.NBTBase;
|
||||||
|
@ -20,11 +21,14 @@ import net.minecraftforge.common.capabilities.Capability;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class WorldData implements IWorldData {
|
public class WorldData implements IWorldData {
|
||||||
private final Map<String, ItemStackHandlerNA> enderStorages = new HashMap<>();
|
private final Map<String, ItemStackHandlerNA> enderStorages = new HashMap<>();
|
||||||
public final ListMultimap<ResourceLocation, Tuple<Vec3d, Integer>> effectPowders = ArrayListMultimap.create();
|
public final ListMultimap<ResourceLocation, Tuple<Vec3d, Integer>> effectPowders = ArrayListMultimap.create();
|
||||||
|
public final Set<TileEntitySpawnLamp> spawnLamps = new HashSet<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||||
|
|
Loading…
Reference in a new issue