Jump to content

Recommended Posts

Posted (edited)

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 by evjeny.23
accidentally typed wrong parameter
Posted
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".

Posted
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.

Posted
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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.