Search in sources :

Example 1 with MessageItemRename

use of net.silentchaos512.gems.network.message.MessageItemRename in project SilentGems by SilentChaos512.

the class ToolHelper method onUpdate.

public static void onUpdate(ItemStack toolOrArmor, World world, Entity entity, int itemSlot, boolean isSelected) {
    // Tick tool souls
    if (entity instanceof EntityPlayer) {
        ToolSoul soul = SoulManager.getSoul(toolOrArmor);
        if (soul != null) {
            soul.updateTick(toolOrArmor, (EntityPlayer) entity);
        }
    }
    if (!world.isRemote) {
        // Randomize tools with no data.
        if (hasNoConstruction(toolOrArmor)) {
            ItemStack newTool = ToolRandomizer.INSTANCE.randomize(toolOrArmor);
        }
        // If the player gave him/herself a tool via JEI or creative, remove the example tag.
        if (isExampleItem(toolOrArmor)) {
            // tool.getTagCompound().setBoolean(NBT_EXAMPLE_TOOL, false);
            toolOrArmor.getTagCompound().removeTag(NBT_EXAMPLE_TOOL);
        }
        initRootTag(toolOrArmor);
        // Generate UUID if tool does not have one.
        if (!hasUUID(toolOrArmor)) {
            toolOrArmor.getTagCompound().setUniqueId(NBT_UUID, UUID.randomUUID());
        }
        return;
    }
    // Client-side name generation
    if (world.getTotalWorldTime() % CHECK_NAME_FREQUENCY == 0 && entity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entity;
        if (toolOrArmor.hasTagCompound() && toolOrArmor.getTagCompound().hasKey(NBT_TEMP_PARTLIST)) {
            NBTTagCompound compound = toolOrArmor.getTagCompound().getCompoundTag(NBT_TEMP_PARTLIST);
            int i = 0;
            String key = "part" + i;
            List<ItemStack> parts = Lists.newArrayList();
            // Load part stacks.
            do {
                NBTTagCompound tag = compound.getCompoundTag(key);
                parts.add(StackHelper.loadFromNBT(tag));
                key = "part" + ++i;
            } while (compound.hasKey(key));
            // Create name on the client.
            String displayName = createToolName(toolOrArmor.getItem(), parts);
            // tool.setStackDisplayName(displayName);
            // Send to the server.
            MessageItemRename message = new MessageItemRename(player.getName(), itemSlot, displayName, toolOrArmor);
            String line = String.format("%s crafted \"%s\"", player.getName(), displayName);
            SilentGems.logHelper.info(line);
            NetworkHandler.INSTANCE.sendToServer(message);
        }
    }
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) MessageItemRename(net.silentchaos512.gems.network.message.MessageItemRename) ItemStack(net.minecraft.item.ItemStack)

Aggregations

EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 ToolSoul (net.silentchaos512.gems.lib.soul.ToolSoul)1 MessageItemRename (net.silentchaos512.gems.network.message.MessageItemRename)1