Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.jlgm.projfact.tileentity;
- import java.util.Random;
- import javax.annotation.Nullable;
- import com.jlgm.projfact.block.BlockOreCluster;
- import com.jlgm.projfact.lib.ProjFactInventoryHelper;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.network.play.server.SPacketUpdateTileEntity;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.ITickable;
- public class TileEntityMiner extends TileEntity implements ITickable{
- private int cooldown = 10;
- private int drillHeadDamage = 0;
- public float ticks;
- public float finalSpeed;
- public float degrees;
- public boolean doAnimation;
- public String drillHeadType;
- public int color;
- public void saveTileEntity(){
- IBlockState state = this.worldObj.getBlockState(pos);
- this.worldObj.notifyBlockUpdate(pos, state, state, 3);
- }
- @Override
- public NBTTagCompound writeToNBT(NBTTagCompound tagCompound){
- super.writeToNBT(tagCompound);
- System.out.println("writeToNBT() DrillHeadDamage: " + this.drillHeadDamage);
- System.out.println("writeToNBT() Color: " + this.color);
- System.out.println("writeToNBT() DoAnimation: " + this.doAnimation);
- tagCompound.setInteger("DrillHeadDamage", this.drillHeadDamage);
- tagCompound.setInteger("Color", this.color);
- tagCompound.setBoolean("DoAnimation", this.doAnimation);
- return tagCompound;
- }
- @Override
- public void readFromNBT(NBTTagCompound tagCompound){
- super.readFromNBT(tagCompound);
- this.drillHeadDamage = tagCompound.getInteger("DrillHeadDamage");
- this.color = tagCompound.getInteger("Color");
- this.doAnimation = tagCompound.getBoolean("DoAnimation");
- System.out.println("readFromNBT() DrillHeadDamage: " + tagCompound.getInteger("DrillHeadDamage"));
- System.out.println("readFromNBT() Color: " + tagCompound.getInteger("Color"));
- System.out.println("readFromNBT() DoAnimation: " + tagCompound.getBoolean("DoAnimation"));
- }
- @Override
- @Nullable
- public SPacketUpdateTileEntity getUpdatePacket(){
- NBTTagCompound tagCompound = new NBTTagCompound();
- writeToNBT(tagCompound);
- System.out.println("getUpdatePacket() DrillHeadDamage: " + tagCompound.getInteger("DrillHeadDamage"));
- System.out.println("getUpdatePacket() Color: " + tagCompound.getInteger("Color"));
- System.out.println("getUpdatePacket() DoAnimation: " + tagCompound.getBoolean("DoAnimation"));
- System.out.println("getUpdatePacket()");
- return new SPacketUpdateTileEntity(this.pos, this.getBlockMetadata(), tagCompound);
- }
- @Override
- public void onDataPacket(net.minecraft.network.NetworkManager net, net.minecraft.network.play.server.SPacketUpdateTileEntity pkt){
- NBTTagCompound tag = pkt.getNbtCompound();
- System.out.println("onDataPacket() DrillHeadDamage: " + tag.getInteger("DrillHeadDamage"));
- System.out.println("onDataPacket() Color: " + tag.getInteger("Color"));
- System.out.println("onDataPacket() DoAnimation: " + tag.getBoolean("DoAnimation"));
- readFromNBT(tag);
- System.out.println("onDataPacket()");
- }
- public TileEntityMiner(){
- Random rand = new Random();
- this.ticks = rand.nextInt(10000);
- this.finalSpeed = 0;
- this.degrees = rand.nextInt(359);
- this.doAnimation = false;
- }
- @Override
- public void update() {
- if(doAnimation){
- ticks++;
- finalSpeed = (float) (ticks * 0.025);
- degrees = (float) (degrees + (20 + (Math.sin(finalSpeed) * 20)));
- if (this.worldObj != null && !this.worldObj.isRemote){
- if(this.worldObj.getBlockState(pos.down()).getBlock() instanceof BlockOreCluster){
- BlockOreCluster blockOreCluster = (BlockOreCluster) this.worldObj.getBlockState(pos.down()).getBlock();
- if(drillHeadDamage < 1000){
- if(cooldown <= 1){
- IInventory iinventory = ProjFactInventoryHelper.getInventoryAtPosition(this.worldObj, pos.getX(), pos.getY() + 1, pos.getZ());
- if(ProjFactInventoryHelper.addItemStackToInventory(iinventory, EnumFacing.DOWN, new ItemStack(blockOreCluster.getOre()))){
- drillHeadDamage++;
- }
- cooldown = 10;
- }else{
- --cooldown;
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement