use of icbm.classic.lib.capability.ex.CapabilityExplosiveStack in project ICBM-Classic by BuiltBrokenModding.
the class ItemMissile method initCapabilities.
@Override
@Nullable
public net.minecraftforge.common.capabilities.ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) {
ItemStackCapProvider provider = new ItemStackCapProvider(stack);
// provider.add("missile", ICBMClassicAPI.MISSILE_CAPABILITY, new CapabilityMissile()); //TODO create an itemstack version
provider.add(NBTConstants.EXPLOSIVE, ICBMClassicAPI.EXPLOSIVE_CAPABILITY, new CapabilityExplosiveStack(stack));
return provider;
}
use of icbm.classic.lib.capability.ex.CapabilityExplosiveStack in project ICBM-Classic by BuiltBrokenModding.
the class EntityExplosiveDataFixer method fixTagCompound.
@Override
public NBTTagCompound fixTagCompound(NBTTagCompound compound) {
// Match to entity, we get all entity tags as input
if (compound.hasKey(NBTConstants.ID) && compound.getString(NBTConstants.ID).equalsIgnoreCase(ICBMEntities.BLOCK_EXPLOSIVE.toString())) {
// Fix explosive ID save
if (compound.hasKey(NBTConstants.EXPLOSIVE_ID)) {
int id = compound.getInteger(NBTConstants.EXPLOSIVE_ID);
// Generate stack so we can serialize off it
final ItemStack stack = new ItemStack(BlockReg.blockExplosive, 1, id);
// Handle custom explosive data
final IExplosive ex = stack.getCapability(ICBMClassicAPI.EXPLOSIVE_CAPABILITY, null);
if (ex instanceof CapabilityExplosiveStack) {
if (compound.hasKey(NBTConstants.DATA)) {
((CapabilityExplosiveStack) ex).setCustomData(compound.getCompoundTag(NBTConstants.DATA));
}
}
// Remove old tags
compound.removeTag(NBTConstants.EXPLOSIVE_ID);
compound.removeTag(NBTConstants.DATA);
// Save stack
compound.setTag(NBTConstants.EXPLOSIVE_STACK, stack.serializeNBT());
}
}
return compound;
}
use of icbm.classic.lib.capability.ex.CapabilityExplosiveStack in project ICBM-Classic by BuiltBrokenModding.
the class TileEntityExplosive method readFromNBT.
/**
* Reads a tile entity from NBT.
*/
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
capabilityExplosive = new CapabilityExplosiveStack(new ItemStack((NBTTagCompound) nbt.getTag(NBTConstants.EXPLOSIVE_STACK)));
}
use of icbm.classic.lib.capability.ex.CapabilityExplosiveStack in project ICBM-Classic by BuiltBrokenModding.
the class BlockExplosive method onBlockPlacedBy.
/**
* Called when the block is placed in the world.
*/
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase entityLiving, ItemStack itemStack) {
final TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityExplosive) {
TileEntityExplosive explosive = (TileEntityExplosive) tile;
explosive.capabilityExplosive = new CapabilityExplosiveStack(itemStack.copy());
if (world.getRedstonePowerFromNeighbors(pos) > 0) {
BlockExplosive.triggerExplosive(world, pos, false);
}
// If so, then detonate.
for (EnumFacing rotation : EnumFacing.HORIZONTALS) {
Pos position = new Pos(pos).add(rotation);
Block blockId = position.getBlock(world);
if (blockId == Blocks.FIRE || blockId == Blocks.FLOWING_LAVA || blockId == Blocks.LAVA) {
BlockExplosive.triggerExplosive(world, pos, true);
break;
}
}
if (entityLiving != null) {
// TODO turn into event and logger
ICBMClassic.logger().info("ICBMClassic>>BlockExplosive#onBlockPlacedBy: " + entityLiving.getName() + " placed " + explosive.capabilityExplosive.getExplosiveData().getRegistryName() + " in: " + pos);
}
}
}
Aggregations