Posted February 27, 20214 yr Hi there i have problem with my mod. I create this mod for learning forge. Mod adds new item to minecraft and in the overided method "OnBlockDestroyed" i give to player 2 diamonds but when i click on this item in inventory dissapear or when i drop this item. Code: package com.example.examplemod; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.util.datafix.fixes.ItemStackUUID; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.ToolType; import net.minecraftforge.fml.common.registry.GameRegistry; public class Hammer extends Item { public Hammer() { super(new Item.Properties().group(ItemGroup.TOOLS).maxStackSize(4).addToolType(ToolType.AXE, 3).defaultMaxDamage(100).maxDamage(200)); } @Override public boolean onBlockDestroyed(ItemStack itemStack, World world, BlockState blockState, BlockPos blockPos, LivingEntity livingEntity) { ClientPlayerEntity clientPlayerEntity = Minecraft.getInstance().player; clientPlayerEntity.sendChatMessage("You destroy: "+ blockState.getBlock().getRegistryName()); clientPlayerEntity.inventory.addItemStackToInventory(new ItemStack(Items.DIAMOND, 2)); return super.onBlockDestroyed(itemStack, world, blockState, blockPos, livingEntity); } }
February 27, 20214 yr Author 12 minutes ago, diesieben07 said: You are reaching across logical sides. You need to use the living entity given to you and also check World#isRemote to ensure you only modify the inventory on the server. Ok thanks, it works. I still have a question, how can I download "ServerPlayerEntity" in my case I convert "LivingEntity" to "ServerPlayerEntity" but is there any way to get "ServerPlayerEntity" from anywhere
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.