Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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.

  • Author
8 minutes ago, Animefan8888 said:

World::addEntity

It doesn't work somewhy. No errors and no item.

  • 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".

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.

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.