use of icbm.classic.api.data.IWorldPosition in project ICBM-Classic by BuiltBrokenModding.
the class ExplosiveInit method enderBlockCoordSet.
private static boolean enderBlockCoordSet(World world, BlockPos pos, EntityPlayer entityPlayer, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
final ItemStack heldItem = entityPlayer.getHeldItem(hand);
if (heldItem.getItem() instanceof IWorldPosItem) {
final IWorldPosItem posItem = ((IWorldPosItem) heldItem.getItem());
final IWorldPosition link = posItem.getLocation(heldItem);
if (link instanceof Location) {
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity.hasCapability(ICBMClassicAPI.EXPLOSIVE_CAPABILITY, facing)) {
IExplosive explosive = tileEntity.getCapability(ICBMClassicAPI.EXPLOSIVE_CAPABILITY, facing);
if (explosive != null) {
NBTTagCompound tag = new NBTTagCompound();
((Location) link).writeIntNBT(tag);
explosive.getCustomBlastData().setTag("", tag);
if (!world.isRemote) {
// entityPlayer.sendMessage(new TextComponentString("Synced coordinate with " + this.getExplosiveName())); //TODO translate
}
return true;
}
}
}
}
return false;
}
use of icbm.classic.api.data.IWorldPosition in project ICBM-Classic by BuiltBrokenModding.
the class BlockLaunchScreen method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (!world.isRemote) {
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof TileLauncherScreen) {
TileLauncherScreen screen = (TileLauncherScreen) tileEntity;
ItemStack stack = player.getHeldItem(hand);
if (stack.getItem() == Items.REDSTONE) {
if ((screen._tier == EnumTier.ONE && !ConfigLauncher.LAUNCHER_REDSTONE_TIER1) || (screen._tier == EnumTier.TWO && !ConfigLauncher.LAUNCHER_REDSTONE_TIER2) || (screen._tier == EnumTier.THREE && !ConfigLauncher.LAUNCHER_REDSTONE_TIER3)) {
return false;
}
if (// canLaunch is called in launch and launch returns false if cannot launch
!screen.launch()) {
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.failedToFire")));
String translation = LanguageUtility.getLocal("chat.launcher.status");
translation = translation.replace("%s", screen.getStatus());
player.sendMessage(new TextComponentString(translation));
}
} else if (stack.getItem() instanceof ItemRemoteDetonator) {
((ItemRemoteDetonator) stack.getItem()).setBroadCastHz(stack, screen.getFrequency());
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.toolFrequencySet").replace("%s", "" + screen.getFrequency())));
} else if (stack.getItem() instanceof ItemLaserDetonator) {
((ItemLaserDetonator) stack.getItem()).setBroadCastHz(stack, screen.getFrequency());
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.toolFrequencySet").replace("%s", "" + screen.getFrequency())));
} else if (stack.getItem() instanceof IWorldPosItem) {
IWorldPosition location = ((IWorldPosItem) stack.getItem()).getLocation(stack);
if (location != null) {
if (location.world() == world) {
screen.setTarget(new Pos(location.x(), location.y(), location.z()));
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.toolTargetSet")));
} else {
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.toolWorldNotMatch")));
}
} else {
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.noTargetInTool")));
}
} else if (screen.launcherBase == null || !screen.launcherBase.tryInsertMissile(player, hand, player.getHeldItem(hand))) {
player.openGui(ICBMClassic.INSTANCE, 0, world, pos.getX(), pos.getY(), pos.getZ());
}
}
}
return true;
}
use of icbm.classic.api.data.IWorldPosition in project ICBM-Classic by BuiltBrokenModding.
the class BlockCruiseLauncher method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (!world.isRemote) {
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof TileCruiseLauncher) {
TileCruiseLauncher launcher = (TileCruiseLauncher) tileEntity;
ItemStack stack = player.getHeldItem(hand);
if (stack.getItem() == Items.REDSTONE) {
if (// canLaunch is called in launch and launch returns false if cannot launch
!launcher.launch()) {
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.failedToFire")));
String translation = LanguageUtility.getLocal("chat.launcher.status");
translation = translation.replace("%s", launcher.getStatus());
player.sendMessage(new TextComponentString(translation));
}
} else if (stack.getItem() instanceof ItemRemoteDetonator) {
((ItemRemoteDetonator) stack.getItem()).setBroadCastHz(stack, launcher.getFrequency());
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.toolFrequencySet").replace("%s", "" + launcher.getFrequency())));
} else if (stack.getItem() instanceof ItemLaserDetonator) {
((ItemLaserDetonator) stack.getItem()).setBroadCastHz(stack, launcher.getFrequency());
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.toolFrequencySet").replace("%s", "" + launcher.getFrequency())));
} else if (stack.getItem() instanceof IWorldPosItem) {
IWorldPosition location = ((IWorldPosItem) stack.getItem()).getLocation(stack);
if (location != null) {
if (location.world() == world) {
launcher.setTarget(new Pos(location.x(), location.y(), location.z()));
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.toolTargetSet")));
} else {
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.toolWorldNotMatch")));
}
} else {
player.sendMessage(new TextComponentString(LanguageUtility.getLocal("chat.launcher.noTargetInTool")));
}
} else {
player.openGui(ICBMClassic.INSTANCE, 0, world, pos.getX(), pos.getY(), pos.getZ());
}
}
}
return true;
}
use of icbm.classic.api.data.IWorldPosition 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;
}
Aggregations