Created
November 30, 2014 09:12
-
-
Save thomas15v/d4b30aa3eee3b7866e54 to your computer and use it in GitHub Desktop.
C4 exploding block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package apoc.c4.tileentity; | |
import net.minecraft.client.Minecraft; | |
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.world.World; | |
public class TileEntityC4 extends TileEntity { | |
private boolean Activated; | |
private int Time = 100; | |
public boolean isActivated() { | |
return Activated; | |
} | |
public void setActivated(boolean activated) { | |
Activated = activated; | |
} | |
@Override | |
public void updateEntity() { | |
if (Activated){ | |
if (!this.worldObj.isRemote){ | |
Time--; | |
if (Time < 0){ | |
explode(); | |
Activated = false; | |
Time = 100; | |
} | |
} | |
} | |
} | |
private void explode() | |
{ | |
float f = 4.0F; | |
this.worldObj.setBlockToAir(this.xCoord, this.yCoord, this.zCoord); | |
this.worldObj.createExplosion(null, this.xCoord, this.yCoord, this.zCoord, f, true); | |
} | |
@Override | |
public void writeToNBT(NBTTagCompound tagCompound) { | |
tagCompound.setBoolean("Activated", Activated); | |
super.writeToNBT(tagCompound); | |
} | |
@Override | |
public void readFromNBT(NBTTagCompound tagCompound) { | |
Activated = tagCompound.getBoolean("Activated"); | |
super.readFromNBT(tagCompound); | |
} | |
@Override | |
public Packet getDescriptionPacket() { | |
NBTTagCompound tagCompound = new NBTTagCompound(); | |
writeToNBT(tagCompound); | |
return new S35PacketUpdateTileEntity(this.xCoord,this.yCoord,this.zCoord, 1, tagCompound); | |
} | |
@Override | |
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { | |
readFromNBT(pkt.func_148857_g()); | |
super.onDataPacket(net, pkt); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment