Search in sources :

Example 16 with WaystoneEntry

use of net.blay09.mods.waystones.util.WaystoneEntry in project Waystones by blay09.

the class BlockWaystone method breakBlock.

@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
    TileWaystone tileWaystone = getTileWaystone(world, pos);
    if (tileWaystone != null) {
        WaystoneEntry entry = new WaystoneEntry(tileWaystone);
        if (tileWaystone.isGlobal()) {
            GlobalWaystones.get(world).removeGlobalWaystone(entry);
        }
        for (EntityPlayer player : world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(pos).grow(64, 64, 64))) {
            WaystoneManager.removePlayerWaystone(player, entry);
            WaystoneManager.sendPlayerWaystones(player);
        }
    }
    super.breakBlock(world, pos, state);
    if (world.getBlockState(pos.up()).getBlock() == this) {
        world.setBlockToAir(pos.up());
    } else if (world.getBlockState(pos.down()).getBlock() == this) {
        world.setBlockToAir(pos.down());
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 17 with WaystoneEntry

use of net.blay09.mods.waystones.util.WaystoneEntry in project Waystones by blay09.

the class GlobalWaystones method writeToNBT.

@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
    NBTTagList tagList = new NBTTagList();
    for (WaystoneEntry entry : globalWaystones.values()) {
        tagList.appendTag(entry.writeToNBT());
    }
    tagCompound.setTag(TAG_LIST_NAME, tagList);
    return tagCompound;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry)

Example 18 with WaystoneEntry

use of net.blay09.mods.waystones.util.WaystoneEntry in project Waystones by blay09.

the class HandlerSortWaystone method onMessage.

@Override
@Nullable
public IMessage onMessage(final MessageSortWaystone message, final MessageContext ctx) {
    NetworkHandler.getThreadListener(ctx).addScheduledTask(() -> {
        PlayerWaystoneData waystoneData = PlayerWaystoneData.fromPlayer(ctx.getServerHandler().player);
        WaystoneEntry[] entries = waystoneData.getWaystones();
        int index = message.getIndex();
        int otherIndex = message.getOtherIndex();
        if (index < 0 || index >= entries.length || otherIndex < 0 || otherIndex >= entries.length) {
            return;
        }
        WaystoneEntry swap = entries[index];
        entries[index] = entries[otherIndex];
        entries[otherIndex] = swap;
        waystoneData.store(ctx.getServerHandler().player);
        WaystoneManager.sendPlayerWaystones(ctx.getServerHandler().player);
    });
    return null;
}
Also used : PlayerWaystoneData(net.blay09.mods.waystones.PlayerWaystoneData) WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) Nullable(javax.annotation.Nullable)

Example 19 with WaystoneEntry

use of net.blay09.mods.waystones.util.WaystoneEntry 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)17 Nullable (javax.annotation.Nullable)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)5 NBTTagList (net.minecraft.nbt.NBTTagList)5 TileWaystone (net.blay09.mods.waystones.block.TileWaystone)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 PlayerWaystoneData (net.blay09.mods.waystones.PlayerWaystoneData)2 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)2 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 GlobalWaystones (net.blay09.mods.waystones.GlobalWaystones)1 GuiWaystoneList (net.blay09.mods.waystones.client.gui.GuiWaystoneList)1 MessageConfig (net.blay09.mods.waystones.network.message.MessageConfig)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 GuiInventory (net.minecraft.client.gui.inventory.GuiInventory)1 ItemStack (net.minecraft.item.ItemStack)1