160 lines
3.7 KiB
Java
160 lines
3.7 KiB
Java
![]() |
package WayofTime.bloodmagic.tile;
|
||
|
|
||
|
import lombok.Getter;
|
||
|
import lombok.Setter;
|
||
|
import net.minecraft.block.state.IBlockState;
|
||
|
import net.minecraft.nbt.NBTTagCompound;
|
||
|
import net.minecraft.network.NetworkManager;
|
||
|
import net.minecraft.network.Packet;
|
||
|
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||
|
import net.minecraft.tileentity.TileEntity;
|
||
|
import net.minecraft.util.BlockPos;
|
||
|
import net.minecraft.util.ITickable;
|
||
|
import net.minecraft.util.MathHelper;
|
||
|
import net.minecraft.world.World;
|
||
|
import WayofTime.bloodmagic.api.soul.DemonWillHolder;
|
||
|
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
|
||
|
import WayofTime.bloodmagic.api.soul.IDemonWillConduit;
|
||
|
|
||
|
public class TileDemonCrystal extends TileEntity implements ITickable, IDemonWillConduit
|
||
|
{
|
||
|
public DemonWillHolder holder = new DemonWillHolder();
|
||
|
public final int maxWill = 100;
|
||
|
public final double drainRate = 1;
|
||
|
|
||
|
@Getter
|
||
|
@Setter
|
||
|
public int crystalCount = 1;
|
||
|
|
||
|
public TileDemonCrystal()
|
||
|
{
|
||
|
this.crystalCount = 1;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void update()
|
||
|
{
|
||
|
if (worldObj.isRemote)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (worldObj.getWorldTime() % 200 == 0)
|
||
|
{
|
||
|
crystalCount = Math.min(crystalCount + 1, 7);
|
||
|
worldObj.markBlockForUpdate(pos);
|
||
|
|
||
|
System.out.println("" + crystalCount);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public int getCrystalCountForRender()
|
||
|
{
|
||
|
return MathHelper.clamp_int(crystalCount - 1, 0, 6);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void readFromNBT(NBTTagCompound tag)
|
||
|
{
|
||
|
super.readFromNBT(tag);
|
||
|
|
||
|
holder.readFromNBT(tag, "Will");
|
||
|
crystalCount = tag.getInteger("crystalCount");
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void writeToNBT(NBTTagCompound tag)
|
||
|
{
|
||
|
super.writeToNBT(tag);
|
||
|
|
||
|
holder.writeToNBT(tag, "Will");
|
||
|
tag.setInteger("crystalCount", crystalCount);
|
||
|
}
|
||
|
|
||
|
// IDemonWillConduit
|
||
|
|
||
|
@Override
|
||
|
public int getWeight()
|
||
|
{
|
||
|
return 10;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public double fillDemonWill(EnumDemonWillType type, double amount, boolean doFill)
|
||
|
{
|
||
|
if (amount <= 0)
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
if (!canFill(type))
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
if (!doFill)
|
||
|
{
|
||
|
return Math.min(maxWill - holder.getWill(type), amount);
|
||
|
}
|
||
|
|
||
|
return holder.addWill(type, amount, maxWill);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public double drainDemonWill(EnumDemonWillType type, double amount, boolean doDrain)
|
||
|
{
|
||
|
double drained = amount;
|
||
|
double current = holder.getWill(type);
|
||
|
if (current < drained)
|
||
|
{
|
||
|
drained = current;
|
||
|
}
|
||
|
|
||
|
if (doDrain)
|
||
|
{
|
||
|
return holder.drainWill(type, amount);
|
||
|
}
|
||
|
|
||
|
return drained;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean canFill(EnumDemonWillType type)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean canDrain(EnumDemonWillType type)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public double getCurrentWill(EnumDemonWillType type)
|
||
|
{
|
||
|
return holder.getWill(type);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState)
|
||
|
{
|
||
|
return oldState.getBlock() != newState.getBlock();
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public Packet getDescriptionPacket()
|
||
|
{
|
||
|
NBTTagCompound nbt = new NBTTagCompound();
|
||
|
writeToNBT(nbt);
|
||
|
return new S35PacketUpdateTileEntity(getPos(), -999, nbt);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
|
||
|
{
|
||
|
super.onDataPacket(net, pkt);
|
||
|
readFromNBT(pkt.getNbtCompound());
|
||
|
worldObj.markBlockRangeForRenderUpdate(getPos(), getPos());
|
||
|
}
|
||
|
}
|