Posted April 6, 20205 yr In older versions of Minecraft, the World.spawnEntityInWorld method could be used in order to spawn dropped ItemEntity like that (If I'm not misunderstanding): ItemEntity item = new ItemEntity(world, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), new ItemStack(Items.SOME_ITEM, QUANTITY)); world.spawnEntityInWorld(item); But in newer version, there is no such method. So, what's the alternative to that which works in newer versions of Minecraft? Edited April 6, 20205 yr by evjeny.23 accidentally typed wrong parameter
April 6, 20205 yr 1 minute ago, evjeny.23 said: So, what's the alternative to that which works in newer versions of Minecraft? World::addEntity VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
April 6, 20205 yr Author 8 minutes ago, Animefan8888 said: World::addEntity It doesn't work somewhy. No errors and no item.
April 6, 20205 yr 18 minutes ago, evjeny.23 said: It doesn't work somewhy. No errors and no item. Post more of your code. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
April 6, 20205 yr Author 1 minute ago, Animefan8888 said: Post more of your code. package com.eugeny.mobscountmod.init; import java.util.List; import com.eugeny.mobscountmod.MobsCountMod; import com.mojang.datafixers.FunctionType.Instance; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.monster.MonsterEntity; 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.potion.EffectInstance; import net.minecraft.potion.Effects; import net.minecraft.util.ActionResult; import net.minecraft.util.DamageSource; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; import net.minecraftforge.registries.ObjectHolder; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @Mod.EventBusSubscriber(modid = MobsCountMod.MOD_ID, bus = Bus.MOD) @ObjectHolder(MobsCountMod.MOD_ID) public class ItemInit { @ObjectHolder(MobsCountMod.MOD_ID + "some_item") private static final Item some_item = null; @SubscribeEvent public static void registerItems(final RegistryEvent.Register<Item> event) { event.getRegistry().register(new Item(new Item.Properties().group(ItemGroup.COMBAT)) { @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { MobsCountMod.LOGGER.info("RIGHT CLICK"); if (!playerIn.addItemStackToInventory(new ItemStack(Blocks.BEDROCK, 1))) { ItemEntity item = new ItemEntity(worldIn, playerPos.getX(), playerPos.getY(), playerPos.getZ(), new ItemStack(Items.BEDROCK, 1)); worldIn.addEntity(item); } return super.onItemRightClick(worldIn, playerIn, handIn); }; }.setRegistryName("some_item")); } } P.S. It logs "RIGHT CLICK".
April 6, 20205 yr 14 minutes ago, evjeny.23 said: P.S. It logs "RIGHT CLICK". Are you testing in creative mode? If you are PlayerEntity::addItemStackToInventory returns true even if the players inventory is full. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
April 6, 20205 yr Author 16 hours ago, Animefan8888 said: Are you testing in creative mode? If you are PlayerEntity::addItemStackToInventory returns true even if the players inventory is full. Thanks! Didn't know about that. In survival mode it is fully working.
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.