Added ship core explosion on breaking after first jump
This commit is contained in:
parent
c1cc62cd83
commit
b457bca934
3 changed files with 75 additions and 20 deletions
|
@ -10,6 +10,7 @@ import net.minecraft.block.material.Material;
|
|||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -95,14 +96,16 @@ public abstract class BlockAbstractContainer extends BlockContainer implements I
|
|||
|
||||
@Override
|
||||
protected void dropBlockAsItem(World world, int x, int y, int z, ItemStack itemStack) {
|
||||
itemStack.setItemDamage(getDamageValue(world, x, y, z));
|
||||
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
||||
if (tileEntity == null) {
|
||||
WarpDrive.logger.error("Missing tile entity for " + this + " at " + world + " " + x + " " + y + " " + z);
|
||||
} else if (tileEntity instanceof TileEntityAbstractBase) {
|
||||
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
||||
((TileEntityAbstractBase) tileEntity).writeItemDropNBT(nbtTagCompound);
|
||||
itemStack.setTagCompound(nbtTagCompound);
|
||||
if (itemStack.getItem() == Item.getItemFromBlock(this)) {
|
||||
itemStack.setItemDamage(getDamageValue(world, x, y, z));
|
||||
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
||||
if (tileEntity == null) {
|
||||
WarpDrive.logger.error("Missing tile entity for " + this + " at " + world + " " + x + " " + y + " " + z);
|
||||
} else if (tileEntity instanceof TileEntityAbstractBase) {
|
||||
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
||||
((TileEntityAbstractBase) tileEntity).writeItemDropNBT(nbtTagCompound);
|
||||
itemStack.setTagCompound(nbtTagCompound);
|
||||
}
|
||||
}
|
||||
world.setBlockToAir(x, y, z);
|
||||
super.dropBlockAsItem(world, x, y, z, itemStack);
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package cr0s.warpdrive.block.movement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
import cr0s.warpdrive.data.EnumComponentType;
|
||||
import cr0s.warpdrive.item.ItemComponent;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.item.EntityTNTPrimed;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
@ -74,25 +78,51 @@ public class BlockShipCore extends BlockAbstractContainer {
|
|||
return new TileEntityShipCore();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the quantity of items to drop on block destruction.
|
||||
*/
|
||||
@Override
|
||||
public int quantityDropped(Random par1Random) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID of the items to drop on destruction.
|
||||
*/
|
||||
@Override
|
||||
public Item getItemDropped(int par1, Random par2Random, int par3) {
|
||||
return Item.getItemFromBlock(this);
|
||||
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
|
||||
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
||||
if (tileEntity instanceof TileEntityShipCore) {
|
||||
if (((TileEntityShipCore)tileEntity).jumpCount == 0) {
|
||||
return super.getDrops(world, x, y, z, metadata, fortune);
|
||||
}
|
||||
}
|
||||
// trigger explosion
|
||||
EntityTNTPrimed entityTNTPrimed = new EntityTNTPrimed(world, x + 0.5F, y + 0.5F, z + 0.5F, null);
|
||||
entityTNTPrimed.fuse = 10 + world.rand.nextInt(10);
|
||||
world.spawnEntityInWorld(entityTNTPrimed);
|
||||
|
||||
// get a chance to get the drops
|
||||
ArrayList<ItemStack> itemStacks = new ArrayList<>();
|
||||
itemStacks.add(ItemComponent.getItemStackNoCache(EnumComponentType.CAPACITIVE_CRYSTAL, 1));
|
||||
if (fortune > 0 && world.rand.nextBoolean()) {
|
||||
itemStacks.add(ItemComponent.getItemStackNoCache(EnumComponentType.CAPACITIVE_CRYSTAL, 1));
|
||||
}
|
||||
if (fortune > 1 && world.rand.nextBoolean()) {
|
||||
itemStacks.add(ItemComponent.getItemStackNoCache(EnumComponentType.CAPACITIVE_CRYSTAL, 1));
|
||||
}
|
||||
if (fortune > 1 & world.rand.nextBoolean()) {
|
||||
itemStacks.add(ItemComponent.getItemStackNoCache(EnumComponentType.POWER_INTERFACE, 1));
|
||||
}
|
||||
return itemStacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPlayerRelativeBlockHardness(EntityPlayer entityPlayer, World world, int x, int y, int z) {
|
||||
boolean willBreak = true;
|
||||
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
||||
if (tileEntity instanceof TileEntityShipCore) {
|
||||
if (((TileEntityShipCore)tileEntity).jumpCount == 0) {
|
||||
willBreak = false;
|
||||
}
|
||||
}
|
||||
return (willBreak ? 0.02F : 1.0F) * super.getPlayerRelativeBlockHardness(entityPlayer, world, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called upon block activation (right click on the block.)
|
||||
*/
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) {
|
||||
if (world.isRemote) {
|
||||
|
|
|
@ -10,6 +10,9 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
|||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
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.potion.Potion;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
@ -86,6 +89,8 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy {
|
|||
public double isolationRate = 0.0D;
|
||||
private int isolationUpdateTicks = 0;
|
||||
|
||||
public int jumpCount = 0;
|
||||
|
||||
public TileEntityShipController controller;
|
||||
|
||||
private boolean soundPlayed = false;
|
||||
|
@ -329,6 +334,7 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy {
|
|||
cooldownTime = Math.max(1, WarpDriveConfig.SHIP_COOLDOWN_INTERVAL_SECONDS * 20);
|
||||
isCooldownReported = false;
|
||||
controller.setJumpFlag(false);
|
||||
jumpCount++;
|
||||
} else {
|
||||
warmupTime = 0;
|
||||
}
|
||||
|
@ -1139,6 +1145,7 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy {
|
|||
shipName = tag.getString("corefrequency") + tag.getString("shipName"); // coreFrequency is the legacy tag name
|
||||
isolationBlocksCount = tag.getInteger("isolation");
|
||||
cooldownTime = tag.getInteger("cooldownTime");
|
||||
jumpCount = tag.getInteger("jumpCount");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1151,6 +1158,21 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy {
|
|||
tag.setString("shipName", shipName);
|
||||
tag.setInteger("isolation", isolationBlocksCount);
|
||||
tag.setInteger("cooldownTime", cooldownTime);
|
||||
tag.setInteger("jumpCount", jumpCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
writeToNBT(tagCompound);
|
||||
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, -1, tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager networkManager, S35PacketUpdateTileEntity packet) {
|
||||
NBTTagCompound tagCompound = packet.func_148857_g();
|
||||
readFromNBT(tagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue