NaturesAura/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityFurnaceHeater.java

101 lines
4.1 KiB
Java
Raw Normal View History

2018-10-26 15:01:48 +02:00
package de.ellpeck.naturesaura.blocks.tiles;
2018-11-11 13:26:19 +01:00
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.blocks.BlockFurnaceHeater;
2018-10-26 15:01:48 +02:00
import net.minecraft.item.ItemStack;
2019-10-20 22:30:49 +02:00
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.FurnaceTileEntity;
2020-01-21 21:04:44 +01:00
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
2019-10-20 22:30:49 +02:00
import net.minecraft.util.Direction;
2018-10-26 15:01:48 +02:00
import net.minecraft.util.math.BlockPos;
2020-01-21 21:04:44 +01:00
public class TileEntityFurnaceHeater extends TileEntityImpl implements ITickableTileEntity {
2018-10-26 15:01:48 +02:00
public boolean isActive;
2020-01-22 01:32:26 +01:00
public TileEntityFurnaceHeater() {
super(ModTileEntities.FURNACE_HEATER);
2020-01-21 21:04:44 +01:00
}
2018-10-26 15:01:48 +02:00
@Override
2020-01-21 21:04:44 +01:00
public void tick() {
if (!this.world.isRemote && this.world.getGameTime() % 5 == 0) {
2018-10-26 15:01:48 +02:00
boolean did = false;
2020-01-21 21:04:44 +01:00
Direction facing = this.world.getBlockState(this.pos).get(BlockFurnaceHeater.FACING);
BlockPos tilePos = this.pos.offset(facing.getOpposite());
TileEntity tile = this.world.getTileEntity(tilePos);
2019-10-20 22:30:49 +02:00
if (tile instanceof FurnaceTileEntity) {
FurnaceTileEntity furnace = (FurnaceTileEntity) tile;
2018-10-26 15:01:48 +02:00
if (isReady(furnace)) {
2020-01-21 21:04:44 +01:00
// TODO furnace heater
/* int time = furnace.getField(0);
2018-10-26 15:01:48 +02:00
if (time <= 0)
2019-10-20 22:30:49 +02:00
FurnaceBlock.setState(true, this.world, furnace.getPos());
2018-10-26 15:01:48 +02:00
furnace.setField(0, 200);
//if set higher than 199, it'll never finish because the furnace does ++ and then ==
2020-01-21 21:04:44 +01:00
furnace.setField(2, Math.min(199, furnace.getField(2) + 5));*/
2018-10-26 15:01:48 +02:00
BlockPos spot = IAuraChunk.getHighestSpot(this.world, this.pos, 20, this.pos);
2018-11-11 13:26:19 +01:00
IAuraChunk chunk = IAuraChunk.getAuraChunk(this.world, spot);
2020-01-21 21:04:44 +01:00
//chunk.drainAura(spot, MathHelper.ceil((200 - time) * 16.6F));
2018-10-26 15:01:48 +02:00
did = true;
2020-01-21 21:04:44 +01:00
if (this.world.getGameTime() % 15 == 0) {
// TODO particles
/*PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticleStream(
2018-10-26 15:01:48 +02:00
this.pos.getX() + (float) this.world.rand.nextGaussian() * 5F,
this.pos.getY() + 1 + this.world.rand.nextFloat() * 5F,
this.pos.getZ() + (float) this.world.rand.nextGaussian() * 5F,
tilePos.getX() + this.world.rand.nextFloat(),
tilePos.getY() + this.world.rand.nextFloat(),
tilePos.getZ() + this.world.rand.nextFloat(),
2018-11-13 00:36:47 +01:00
this.world.rand.nextFloat() * 0.07F + 0.07F, IAuraType.forWorld(this.world).getColor(), this.world.rand.nextFloat() + 0.5F
2020-01-21 21:04:44 +01:00
));*/
}
2018-10-26 15:01:48 +02:00
}
}
2018-11-04 16:38:09 +01:00
if (did != this.isActive) {
2018-10-26 15:01:48 +02:00
this.isActive = did;
this.sendToClients();
}
}
}
2019-10-20 22:30:49 +02:00
private static boolean isReady(FurnaceTileEntity furnace) {
2018-10-26 15:01:48 +02:00
if (!furnace.getStackInSlot(1).isEmpty())
return false;
ItemStack input = furnace.getStackInSlot(0);
if (!input.isEmpty()) {
2020-01-21 21:04:44 +01:00
/*ItemStack output = FurnaceRecipes.instance().getSmeltingResult(input);
if (output.isEmpty())*/
return false;
2018-10-26 15:01:48 +02:00
2020-01-21 21:04:44 +01:00
/*ItemStack currOutput = furnace.getStackInSlot(2);
return currOutput.isEmpty() ||
2020-01-21 21:04:44 +01:00
Helper.areItemsEqual(currOutput, output, true) && currOutput.getCount() + output.getCount() <= output.getMaxStackSize();*/
2018-10-26 15:01:48 +02:00
} else
return false;
}
@Override
2019-10-20 22:30:49 +02:00
public void writeNBT(CompoundNBT compound, SaveType type) {
2018-11-04 16:38:09 +01:00
super.writeNBT(compound, type);
2018-10-26 15:01:48 +02:00
2018-11-04 16:38:09 +01:00
if (type == SaveType.SYNC)
2020-01-21 21:04:44 +01:00
compound.putBoolean("active", this.isActive);
2018-10-26 15:01:48 +02:00
}
@Override
2019-10-20 22:30:49 +02:00
public void readNBT(CompoundNBT compound, SaveType type) {
2018-11-04 16:38:09 +01:00
super.readNBT(compound, type);
2018-10-26 15:01:48 +02:00
2018-11-04 16:38:09 +01:00
if (type == SaveType.SYNC)
2018-10-26 15:01:48 +02:00
this.isActive = compound.getBoolean("active");
}
}