use of icbm.classic.api.caps.IExplosive in project ICBM-Classic by BuiltBrokenModding.
the class ExplosiveInit method enderMissileCoordSet.
private static boolean enderMissileCoordSet(Entity entity, EntityPlayer player, EnumHand hand) {
if (entity.hasCapability(ICBMClassicAPI.EXPLOSIVE_CAPABILITY, null)) {
final IExplosive provider = entity.getCapability(ICBMClassicAPI.EXPLOSIVE_CAPABILITY, null);
final NBTTagCompound tag = provider.getCustomBlastData();
if (tag != null) {
final ItemStack heldItem = player.getHeldItem(hand);
if (heldItem.getItem() instanceof IWorldPosItem) {
final IWorldPosItem posItem = ((IWorldPosItem) heldItem.getItem());
final IWorldPosition link = posItem.getLocation(heldItem);
if (link instanceof Location) {
((Location) link).writeIntNBT(tag);
if (!entity.world.isRemote) {
// TODO translate
player.sendMessage(new TextComponentString("Coordinates encoded into entity"));
}
return true;
}
}
}
}
return false;
}
use of icbm.classic.api.caps.IExplosive 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;
}
Aggregations