2019-03-19 17:21:06 +01:00
|
|
|
package de.ellpeck.naturesaura.blocks.tiles;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraft.tileentity.ITickableTileEntity;
|
2019-03-19 17:21:06 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.MathHelper;
|
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
// TODO chunk loader
|
|
|
|
public class TileEntityChunkLoader extends TileEntityImpl implements ITickableTileEntity {
|
2020-01-22 01:32:26 +01:00
|
|
|
public TileEntityChunkLoader() {
|
|
|
|
super(ModTileEntities.CHUNK_LOADER);
|
2020-01-21 21:04:44 +01:00
|
|
|
}
|
2019-03-19 17:21:06 +01:00
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
//private Ticket ticket;
|
|
|
|
/*
|
2019-03-19 17:21:06 +01:00
|
|
|
@Override
|
|
|
|
public void validate() {
|
|
|
|
super.validate();
|
|
|
|
if (!this.world.isRemote && this.ticket == null) {
|
|
|
|
Ticket ticket = ForgeChunkManager.requestTicket(NaturesAura.instance, this.world, Type.NORMAL);
|
|
|
|
this.updateTicket(ticket);
|
|
|
|
ticket.getModData().setLong("pos", this.pos.toLong());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void invalidate() {
|
|
|
|
super.invalidate();
|
|
|
|
if (!this.world.isRemote)
|
|
|
|
this.updateTicket(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRedstonePowerChange(int newPower) {
|
|
|
|
super.onRedstonePowerChange(newPower);
|
|
|
|
if (!this.world.isRemote) {
|
|
|
|
this.loadChunks();
|
|
|
|
this.sendToClients();
|
|
|
|
}
|
2020-01-21 21:04:44 +01:00
|
|
|
}*/
|
2019-03-19 17:21:06 +01:00
|
|
|
|
|
|
|
public int range() {
|
|
|
|
return this.redstonePower * 2;
|
|
|
|
}
|
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
/*public void updateTicket(Ticket ticket) {
|
2019-03-19 17:21:06 +01:00
|
|
|
if (this.ticket != null)
|
|
|
|
ForgeChunkManager.releaseTicket(this.ticket);
|
|
|
|
this.ticket = ticket;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void loadChunks() {
|
|
|
|
if (this.ticket == null)
|
|
|
|
return;
|
|
|
|
Set<ChunkPos> before = new HashSet<>(this.ticket.getChunkList());
|
|
|
|
int range = this.range();
|
|
|
|
if (range > 0) {
|
|
|
|
for (int x = (this.pos.getX() - range) >> 4; x <= (this.pos.getX() + range) >> 4; x++) {
|
|
|
|
for (int z = (this.pos.getZ() - range) >> 4; z <= (this.pos.getZ() + range) >> 4; z++) {
|
|
|
|
ChunkPos pos = new ChunkPos(x, z);
|
|
|
|
if (!before.contains(pos))
|
|
|
|
ForgeChunkManager.forceChunk(this.ticket, pos);
|
|
|
|
else
|
|
|
|
before.remove(pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (ChunkPos pos : before)
|
|
|
|
ForgeChunkManager.unforceChunk(this.ticket, pos);
|
2020-01-21 21:04:44 +01:00
|
|
|
}*/
|
2019-03-19 17:21:06 +01:00
|
|
|
|
|
|
|
@Override
|
2020-01-21 21:04:44 +01:00
|
|
|
public void tick() {
|
2019-03-19 17:21:06 +01:00
|
|
|
if (!this.world.isRemote) {
|
2020-01-21 21:04:44 +01:00
|
|
|
if (this.world.getGameTime() % 20 != 0)
|
2019-03-19 17:21:06 +01:00
|
|
|
return;
|
|
|
|
int toUse = MathHelper.ceil(this.range() / 2F);
|
|
|
|
if (toUse > 0) {
|
|
|
|
BlockPos spot = IAuraChunk.getHighestSpot(this.world, this.pos, 35, this.pos);
|
|
|
|
IAuraChunk.getAuraChunk(this.world, spot).drainAura(spot, toUse);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|