Search in sources :

Example 1 with IWorldPosItem

use of com.builtbroken.mc.api.items.tools.IWorldPosItem in project ICBM-Classic by BuiltBrokenModding.

the class TileLauncherScreen method onPlayerActivated.

@Override
public boolean onPlayerActivated(EntityPlayer player, int side, Pos hit) {
    if (isServer()) {
        boolean notNull = player.getHeldItem() != null;
        if (notNull && player.getHeldItem().getItem() == Items.redstone) {
            if (canLaunch()) {
                launch();
            } else {
                player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.failedToFire")));
                String translation = LanguageUtility.getLocal("chat.launcher.status");
                translation = translation.replace("%1", getStatus());
                player.addChatComponentMessage(new ChatComponentText(translation));
            }
        } else if (notNull && player.getHeldItem().getItem() instanceof ItemRemoteDetonator) {
            ((ItemRemoteDetonator) player.getHeldItem().getItem()).setBroadCastHz(player.getHeldItem(), getFrequency());
            player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.toolFrequencySet").replace("%1", "" + getFrequency())));
        } else if (notNull && player.getHeldItem().getItem() instanceof IWorldPosItem) {
            IWorldPosition location = ((IWorldPosItem) player.getHeldItem().getItem()).getLocation(player.getHeldItem());
            if (location != null) {
                if (location.world() == world()) {
                    setTarget(new Pos(location.x(), location.y(), location.z()));
                    player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.toolTargetSet")));
                } else {
                    player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.toolWorldNotMatch")));
                }
            } else {
                player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.noTargetInTool")));
            }
        } else {
            player.openGui(ICBMClassic.INSTANCE, 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
        }
    }
    return true;
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) IWorldPosition(com.builtbroken.mc.api.IWorldPosition) IWorldPosItem(com.builtbroken.mc.api.items.tools.IWorldPosItem) ChatComponentText(net.minecraft.util.ChatComponentText) ItemRemoteDetonator(icbm.classic.content.items.ItemRemoteDetonator)

Example 2 with IWorldPosItem

use of com.builtbroken.mc.api.items.tools.IWorldPosItem in project ICBM-Classic by BuiltBrokenModding.

the class GuiMissileCoordinator method drawGuiContainerForegroundLayer.

/** Draw the foreground layer for the GuiContainer (everything in front of the items) */
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
    this.fontRendererObj.drawString("ยง7" + tileEntity.getInventoryName(), 48, 6, 4210752);
    this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.sim"), 50, 20, 4210752);
    this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.from"), 13, 30, 4210752);
    this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.to"), 134, 30, 4210752);
    if (this.tileEntity.getStackInSlot(0) != null && this.tileEntity.getStackInSlot(1) != null) {
        if (this.tileEntity.getStackInSlot(0).getItem() instanceof IWorldPosItem && this.tileEntity.getStackInSlot(1).getItem() instanceof IWorldPosItem) {
            Location pos1 = new Location((IWorldPosition) ((IWorldPosItem) this.tileEntity.getStackInSlot(0).getItem()).getLocation(this.tileEntity.getStackInSlot(0)));
            Location pos2 = new Location((IWorldPosition) ((IWorldPosItem) this.tileEntity.getStackInSlot(1).getItem()).getLocation(this.tileEntity.getStackInSlot(1)));
            double displacement = pos1.distance(pos2);
            this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.displace").replaceAll("%p", "" + UnitDisplay.roundDecimals(displacement)), 13, 65, 4210752);
            double w = pos1.toVector2().distance(pos2.toVector2());
            double h = 160 + (w * 3) - pos1.y();
            double distance = 0.5 * Math.sqrt(16 * (h * h) + (w * w)) + (((w * w) / (8 * h)) * (Math.log(4 * h + Math.sqrt(16 * (h * h) + (w * w))) - Math.log(w)));
            this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.arc").replaceAll("%p", "" + UnitDisplay.roundDecimals(distance)), 13, 75, 4210752);
            this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.time").replaceAll("%p", "" + UnitDisplay.roundDecimals(Math.max(100, 2 * displacement) / 20)), 13, 85, 4210752);
            Location delta = pos1.subtract(pos2);
            double rotation = MathHelper.wrapAngleTo180_double(Math.toDegrees(Math.atan2(delta.z(), delta.x()))) - 90;
            int heading = MathHelper.floor_double(rotation * 4.0F / 360.0F + 0.5D) & 3;
            this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.direction") + " " + UnitDisplay.roundDecimals(rotation) + " (" + Direction.directions[heading] + ")", 13, 95, 4210752);
        }
    }
    //this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.coordinator.wip"), 13, 120, 4210752);
    super.drawGuiContainerForegroundLayer(mouseX, mouseY);
}
Also used : IWorldPosItem(com.builtbroken.mc.api.items.tools.IWorldPosItem) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 3 with IWorldPosItem

use of com.builtbroken.mc.api.items.tools.IWorldPosItem in project ICBM-Classic by BuiltBrokenModding.

the class TileCruiseLauncher method onPlayerActivated.

@Override
public boolean onPlayerActivated(EntityPlayer player, int side, Pos hit) {
    if (isServer()) {
        boolean notNull = player.getHeldItem() != null;
        if (notNull && player.getHeldItem().getItem() == Items.redstone) {
            if (canLaunch()) {
                launch();
            } else {
                player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.failedToFire")));
                String translation = LanguageUtility.getLocal("chat.launcher.status");
                translation = translation.replace("%1", getStatus());
                player.addChatComponentMessage(new ChatComponentText(translation));
            }
        } else if (notNull && player.getHeldItem().getItem() instanceof IWorldPosItem) {
            IWorldPosition location = ((IWorldPosItem) player.getHeldItem().getItem()).getLocation(player.getHeldItem());
            if (location != null) {
                if (location.world() == world()) {
                    setTarget(new Pos(location.x(), location.y(), location.z()));
                    player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.toolTargetSet")));
                } else {
                    player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.toolWorldNotMatch")));
                }
            } else {
                player.addChatComponentMessage(new ChatComponentText(LanguageUtility.getLocal("chat.launcher.noTargetInTool")));
            }
        } else {
            player.openGui(ICBMClassic.INSTANCE, 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
        }
    }
    return true;
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) IWorldPosition(com.builtbroken.mc.api.IWorldPosition) IWorldPosItem(com.builtbroken.mc.api.items.tools.IWorldPosItem) ChatComponentText(net.minecraft.util.ChatComponentText)

Aggregations

IWorldPosItem (com.builtbroken.mc.api.items.tools.IWorldPosItem)3 IWorldPosition (com.builtbroken.mc.api.IWorldPosition)2 Pos (com.builtbroken.mc.imp.transform.vector.Pos)2 ChatComponentText (net.minecraft.util.ChatComponentText)2 Location (com.builtbroken.mc.imp.transform.vector.Location)1 ItemRemoteDetonator (icbm.classic.content.items.ItemRemoteDetonator)1