Search in sources :

Example 1 with IWorldPosition

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IWorldPosition(icbm.classic.api.data.IWorldPosition) IExplosive(icbm.classic.api.caps.IExplosive) ItemStack(net.minecraft.item.ItemStack) IWorldPosItem(icbm.classic.api.items.IWorldPosItem) Location(icbm.classic.lib.transform.vector.Location) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 2 with IWorldPosition

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ItemLaserDetonator(icbm.classic.content.items.ItemLaserDetonator) Pos(icbm.classic.lib.transform.vector.Pos) BlockPos(net.minecraft.util.math.BlockPos) IWorldPosition(icbm.classic.api.data.IWorldPosition) TextComponentString(net.minecraft.util.text.TextComponentString) ItemStack(net.minecraft.item.ItemStack) IWorldPosItem(icbm.classic.api.items.IWorldPosItem) TextComponentString(net.minecraft.util.text.TextComponentString) ItemRemoteDetonator(icbm.classic.content.items.ItemRemoteDetonator)

Example 3 with IWorldPosition

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ItemLaserDetonator(icbm.classic.content.items.ItemLaserDetonator) Pos(icbm.classic.lib.transform.vector.Pos) BlockPos(net.minecraft.util.math.BlockPos) IWorldPosition(icbm.classic.api.data.IWorldPosition) TextComponentString(net.minecraft.util.text.TextComponentString) ItemStack(net.minecraft.item.ItemStack) IWorldPosItem(icbm.classic.api.items.IWorldPosItem) TextComponentString(net.minecraft.util.text.TextComponentString) ItemRemoteDetonator(icbm.classic.content.items.ItemRemoteDetonator)

Example 4 with IWorldPosition

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;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IWorldPosition(icbm.classic.api.data.IWorldPosition) IExplosive(icbm.classic.api.caps.IExplosive) ItemStack(net.minecraft.item.ItemStack) IWorldPosItem(icbm.classic.api.items.IWorldPosItem) Location(icbm.classic.lib.transform.vector.Location) ResourceLocation(net.minecraft.util.ResourceLocation) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

IWorldPosition (icbm.classic.api.data.IWorldPosition)4 IWorldPosItem (icbm.classic.api.items.IWorldPosItem)4 ItemStack (net.minecraft.item.ItemStack)4 TileEntity (net.minecraft.tileentity.TileEntity)3 TextComponentString (net.minecraft.util.text.TextComponentString)3 IExplosive (icbm.classic.api.caps.IExplosive)2 ItemLaserDetonator (icbm.classic.content.items.ItemLaserDetonator)2 ItemRemoteDetonator (icbm.classic.content.items.ItemRemoteDetonator)2 Location (icbm.classic.lib.transform.vector.Location)2 Pos (icbm.classic.lib.transform.vector.Pos)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 BlockPos (net.minecraft.util.math.BlockPos)2