Search in sources :

Example 1 with MessageTeleportToWaystone

use of net.blay09.mods.waystones.network.message.MessageTeleportToWaystone in project Waystones by blay09.

the class GuiWaystoneList method actionPerformed.

@Override
protected void actionPerformed(GuiButton button) {
    if (button == btnNextPage) {
        pageOffset++;
        updateList();
    } else if (button == btnPrevPage) {
        pageOffset--;
        updateList();
    } else if (button instanceof GuiButtonWaystoneEntry) {
        NetworkHandler.channel.sendToServer(new MessageTeleportToWaystone(((GuiButtonWaystoneEntry) button).getWaystone(), warpMode, hand, fromWaystone));
        mc.displayGuiScreen(null);
    } else if (button instanceof GuiButtonSortWaystone) {
        WaystoneEntry waystoneEntry = ((GuiButtonSortWaystone) button).getWaystone();
        int index = ArrayUtils.indexOf(entries, waystoneEntry);
        int sortDir = ((GuiButtonSortWaystone) button).getSortDir();
        int otherIndex = index + sortDir;
        if (index == -1 || otherIndex < 0 || otherIndex >= entries.length) {
            return;
        }
        WaystoneEntry swap = entries[index];
        entries[index] = entries[otherIndex];
        entries[otherIndex] = swap;
        NetworkHandler.channel.sendToServer(new MessageSortWaystone(index, otherIndex));
        updateList();
    } else if (button instanceof GuiButtonRemoveWaystone) {
        WaystoneEntry waystoneEntry = ((GuiButtonRemoveWaystone) button).getWaystone();
        int index = ArrayUtils.indexOf(entries, waystoneEntry);
        entries = ArrayUtils.remove(entries, index);
        NetworkHandler.channel.sendToServer(new MessageRemoveWaystone(index));
        updateList();
    }
}
Also used : WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) MessageRemoveWaystone(net.blay09.mods.waystones.network.message.MessageRemoveWaystone) MessageTeleportToWaystone(net.blay09.mods.waystones.network.message.MessageTeleportToWaystone) MessageSortWaystone(net.blay09.mods.waystones.network.message.MessageSortWaystone)

Example 2 with MessageTeleportToWaystone

use of net.blay09.mods.waystones.network.message.MessageTeleportToWaystone in project Waystones by blay09.

the class HandlerTeleportToWaystone method onMessage.

@Override
@Nullable
public IMessage onMessage(final MessageTeleportToWaystone message, final MessageContext ctx) {
    NetworkHandler.getThreadListener(ctx).addScheduledTask(() -> {
        EntityPlayer player = ctx.getServerHandler().player;
        int dist = (int) Math.sqrt(player.getDistanceSqToCenter(message.getWaystone().getPos()));
        int xpLevelCost = WaystoneConfig.general.blocksPerXPLevel > 0 ? MathHelper.clamp(dist / WaystoneConfig.general.blocksPerXPLevel, 0, WaystoneConfig.general.maximumXpCost) : 0;
        ItemStack heldItem = player.getHeldItem(message.getHand());
        switch(message.getWarpMode()) {
            case INVENTORY_BUTTON:
                if (!WaystoneConfig.general.teleportButtonReturnOnly && (!WaystoneConfig.general.inventoryButtonXpCost || player.experienceLevel < xpLevelCost)) {
                    return;
                }
                if (!WaystoneConfig.general.teleportButton || WaystoneConfig.general.teleportButtonReturnOnly || !PlayerWaystoneHelper.canFreeWarp(ctx.getServerHandler().player)) {
                    return;
                }
                break;
            case WARP_SCROLL:
                if (heldItem.isEmpty() || heldItem.getItem() != Waystones.itemWarpScroll) {
                    return;
                }
                break;
            case WARP_STONE:
                if (WaystoneConfig.general.warpStoneXpCost && player.experienceLevel < xpLevelCost) {
                    return;
                }
                if (heldItem.isEmpty() || heldItem.getItem() != Waystones.itemWarpStone) {
                    return;
                }
                if (!PlayerWaystoneHelper.canUseWarpStone(player)) {
                    return;
                }
                break;
            case WAYSTONE:
                if (WaystoneConfig.general.waystoneXpCost && player.experienceLevel < xpLevelCost) {
                    return;
                }
                WaystoneEntry fromWaystone = message.getFromWaystone();
                if (fromWaystone == null || WaystoneManager.getWaystoneInWorld(fromWaystone) == null) {
                    return;
                }
                break;
        }
        if (WaystoneManager.teleportToWaystone(ctx.getServerHandler().player, message.getWaystone())) {
            boolean shouldCooldown = !(message.getWaystone().isGlobal() && WaystoneConfig.general.globalNoCooldown);
            switch(message.getWarpMode()) {
                case INVENTORY_BUTTON:
                    if (shouldCooldown) {
                        PlayerWaystoneHelper.setLastFreeWarp(ctx.getServerHandler().player, System.currentTimeMillis());
                    }
                    if (WaystoneConfig.general.inventoryButtonXpCost) {
                        player.addExperienceLevel(-xpLevelCost);
                    }
                    break;
                case WARP_SCROLL:
                    heldItem.shrink(1);
                    break;
                case WARP_STONE:
                    if (WaystoneConfig.general.warpStoneXpCost) {
                        player.addExperienceLevel(-xpLevelCost);
                    }
                    if (shouldCooldown) {
                        PlayerWaystoneHelper.setLastWarpStoneUse(ctx.getServerHandler().player, System.currentTimeMillis());
                    }
                    break;
                case WAYSTONE:
                    if (WaystoneConfig.general.waystoneXpCost) {
                        player.addExperienceLevel(-xpLevelCost);
                    }
                    break;
            }
        }
        WaystoneManager.sendPlayerWaystones(ctx.getServerHandler().player);
    });
    return null;
}
Also used : WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Aggregations

WaystoneEntry (net.blay09.mods.waystones.util.WaystoneEntry)2 Nullable (javax.annotation.Nullable)1 MessageRemoveWaystone (net.blay09.mods.waystones.network.message.MessageRemoveWaystone)1 MessageSortWaystone (net.blay09.mods.waystones.network.message.MessageSortWaystone)1 MessageTeleportToWaystone (net.blay09.mods.waystones.network.message.MessageTeleportToWaystone)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1