Search in sources :

Example 1 with WaystoneEntry

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

the class PlayerWaystoneHelper method store.

public static void store(EntityPlayer player, WaystoneEntry[] entries, long lastFreeWarp, long lastWarpStoneUse) {
    NBTTagCompound tagCompound = getOrCreateWaystonesTag(player);
    NBTTagList tagList = new NBTTagList();
    for (WaystoneEntry entry : entries) {
        tagList.appendTag(entry.writeToNBT());
    }
    tagCompound.setTag(WAYSTONE_LIST, tagList);
    tagCompound.setLong(LAST_FREE_WARP, lastFreeWarp);
    tagCompound.setLong(LAST_WARP_STONE_USE, lastWarpStoneUse);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 2 with WaystoneEntry

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

the class PlayerWaystoneData method fromPlayer.

public static PlayerWaystoneData fromPlayer(EntityPlayer player) {
    NBTTagCompound tagCompound = PlayerWaystoneHelper.getWaystonesTag(player);
    NBTTagList tagList = tagCompound.getTagList(PlayerWaystoneHelper.WAYSTONE_LIST, Constants.NBT.TAG_COMPOUND);
    WaystoneEntry[] entries = new WaystoneEntry[tagList.tagCount()];
    for (int i = 0; i < entries.length; i++) {
        entries[i] = WaystoneEntry.read(tagList.getCompoundTagAt(i));
    }
    long lastFreeWarp = tagCompound.getLong(PlayerWaystoneHelper.LAST_FREE_WARP);
    long lastWarpStoneUse = tagCompound.getLong(PlayerWaystoneHelper.LAST_WARP_STONE_USE);
    return new PlayerWaystoneData(entries, lastFreeWarp, lastWarpStoneUse);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 3 with WaystoneEntry

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

the class WaystoneManager method checkAndUpdateWaystone.

public static boolean checkAndUpdateWaystone(EntityPlayer player, WaystoneEntry waystone) {
    NBTTagCompound tagCompound = PlayerWaystoneHelper.getWaystonesTag(player);
    NBTTagList tagList = tagCompound.getTagList(PlayerWaystoneHelper.WAYSTONE_LIST, Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < tagList.tagCount(); i++) {
        NBTTagCompound entryCompound = tagList.getCompoundTagAt(i);
        if (WaystoneEntry.read(entryCompound).equals(waystone)) {
            TileWaystone tileEntity = getWaystoneInWorld(waystone);
            if (tileEntity != null) {
                if (!entryCompound.getString("Name").equals(tileEntity.getWaystoneName())) {
                    entryCompound.setString("Name", tileEntity.getWaystoneName());
                    sendPlayerWaystones(player);
                }
                return true;
            } else {
                if (waystone.isGlobal()) {
                    GlobalWaystones.get(player.world).removeGlobalWaystone(waystone);
                }
                removePlayerWaystone(player, waystone);
                sendPlayerWaystones(player);
            }
            return false;
        }
    }
    return false;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TileWaystone(net.blay09.mods.waystones.block.TileWaystone)

Example 4 with WaystoneEntry

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

the class BlockWaystone 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 (player.isSneaking() && (player.capabilities.isCreativeMode || !WaystoneConfig.general.creativeModeOnly)) {
        if (!world.isRemote) {
            TileWaystone tileWaystone = getTileWaystone(world, pos);
            if (tileWaystone == null) {
                return true;
            }
            if (WaystoneConfig.general.restrictRenameToOwner && !tileWaystone.isOwner(player)) {
                player.sendStatusMessage(new TextComponentTranslation("waystones:notTheOwner"), true);
                return true;
            }
            if (tileWaystone.isGlobal() && !player.capabilities.isCreativeMode && !WaystoneConfig.general.allowEveryoneGlobal) {
                player.sendStatusMessage(new TextComponentTranslation("waystones:creativeRequired"), true);
                return true;
            }
            player.openGui(Waystones.instance, 1, world, pos.getX(), pos.getY(), pos.getZ());
        }
        return true;
    }
    TileWaystone tileWaystone = getTileWaystone(world, pos);
    if (tileWaystone == null) {
        return true;
    }
    WaystoneEntry knownWaystone = world.isRemote ? ClientWaystones.getKnownWaystone(tileWaystone.getWaystoneName()) : null;
    if (knownWaystone != null) {
        Waystones.proxy.openWaystoneSelection(WarpMode.WAYSTONE, EnumHand.MAIN_HAND, knownWaystone);
    } else if (!world.isRemote) {
        WaystoneEntry waystone = new WaystoneEntry(tileWaystone);
        if (!WaystoneManager.checkAndUpdateWaystone(player, waystone)) {
            TextComponentString nameComponent = new TextComponentString(tileWaystone.getWaystoneName());
            nameComponent.getStyle().setColor(TextFormatting.WHITE);
            TextComponentTranslation chatComponent = new TextComponentTranslation("waystones:activatedWaystone", nameComponent);
            chatComponent.getStyle().setColor(TextFormatting.YELLOW);
            player.sendMessage(chatComponent);
            player.addStat(WAYSTONE_ACTIVATED);
            WaystoneManager.addPlayerWaystone(player, waystone);
            WaystoneManager.sendPlayerWaystones(player);
        }
        if (WaystoneConfig.general.setSpawnPoint) {
            EnumFacing blockFacing = state.getValue(FACING);
            player.setSpawnPoint(new BlockPos(tileWaystone.getPos().offset(blockFacing)), true);
        }
    } else {
        Waystones.proxy.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, pos, 1f);
        for (int i = 0; i < 32; i++) {
            world.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, pos.getX() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, pos.getY() + 3, pos.getZ() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, 0, -5, 0);
            world.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, pos.getX() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, pos.getY() + 4, pos.getZ() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, 0, -5, 0);
        }
    }
    return true;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 5 with WaystoneEntry

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

the class ClientProxy method openWaystoneSelection.

@Override
public void openWaystoneSelection(WarpMode mode, EnumHand hand, @Nullable WaystoneEntry fromWaystone) {
    WaystoneEntry[] waystones = PlayerWaystoneData.fromPlayer(FMLClientHandler.instance().getClientPlayerEntity()).getWaystones();
    Minecraft.getMinecraft().displayGuiScreen(new GuiWaystoneList(waystones, mode, hand, fromWaystone));
}
Also used : WaystoneEntry(net.blay09.mods.waystones.util.WaystoneEntry) GuiWaystoneList(net.blay09.mods.waystones.client.gui.GuiWaystoneList)

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