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.

PlainPlaying

Members
  • Joined

  • Last visited

  1. I am aware of ,get(), but i have absoulutely no clue on how to make the code work on EntityType instead of RegistryObject
  2. I understand the code, It's just that I don't understand how to make the code work
  3. I am trying to make a spawn egg that spawns the wither, I am using a custom ModSpawnEggItem class: package com.plainplaying.test.items; import io.netty.handler.codec.http2.Http2FrameLogger; import net.minecraft.block.DispenserBlock; import net.minecraft.dispenser.DefaultDispenseItemBehavior; import net.minecraft.dispenser.IBlockSource; import net.minecraft.entity.EntityType; import net.minecraft.entity.SpawnReason; import net.minecraft.item.ItemStack; import net.minecraft.item.SpawnEggItem; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.Direction; import net.minecraftforge.common.util.Lazy; import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import java.util.ArrayList; import java.util.List; import java.util.Map; public class ModSpawnEggItem extends SpawnEggItem { protected static final List<ModSpawnEggItem> UNADDED_EGGS = new ArrayList<>(); private final Lazy<? extends EntityType<?>> entityTypeSupplier; public ModSpawnEggItem(final RegistryObject<? extends EntityType<?>> entityTypeSupplier, int primaryColorIn, int secondaryColorIn, Properties builder) { super(null, primaryColorIn, secondaryColorIn, builder); this.entityTypeSupplier = Lazy.of(entityTypeSupplier::get); UNADDED_EGGS.add(this); } public static void initSpawnEggs(){ final Map<EntityType<?>, SpawnEggItem> EGGS = ObfuscationReflectionHelper.getPrivateValue(SpawnEggItem.class, null, "field_195987_b"); DefaultDispenseItemBehavior dispenseBehavior = new DefaultDispenseItemBehavior() { @Override protected ItemStack dispenseStack(IBlockSource source, ItemStack stack) { Direction direction = source.getBlockState().get(DispenserBlock.FACING); EntityType<?> type = ((SpawnEggItem) stack.getItem()).getType(stack.getTag()); if (direction == Direction.WEST){ type.spawn(source.getWorld(), stack, null, source.getBlockPos().add(-1,0,0), SpawnReason.DISPENSER,direction!= Direction.UP, false); } else if (direction == Direction.EAST){ type.spawn(source.getWorld(), stack, null, source.getBlockPos().add(1,0,0), SpawnReason.DISPENSER,direction!= Direction.UP, false); } else if (direction == Direction.NORTH){ type.spawn(source.getWorld(), stack, null, source.getBlockPos().add(0,0,-1), SpawnReason.DISPENSER,direction!= Direction.UP, false); } else if (direction == Direction.SOUTH){ type.spawn(source.getWorld(), stack, null, source.getBlockPos().add(0,0,1), SpawnReason.DISPENSER,true, false); } else if (direction == Direction.DOWN){ type.spawn(source.getWorld(), stack, null, source.getBlockPos().add(0,-1,0), SpawnReason.DISPENSER,true, false); }else{ type.spawn(source.getWorld(), stack, null, source.getBlockPos().add(0,1,0), SpawnReason.DISPENSER,true, false); } stack.shrink(1); return stack; } }; for (final SpawnEggItem spawnEgg : UNADDED_EGGS){ EGGS.put(spawnEgg.getType(null), spawnEgg); DispenserBlock.registerDispenseBehavior(spawnEgg, dispenseBehavior); } UNADDED_EGGS.clear(); } @Override public EntityType<?> getType(CompoundNBT nbt) { return this.entityTypeSupplier.get(); } } I am creating the spawn egg like this: public static final RegistryObject<SpawnEggItem> WITHER_SPAWN_EGG = ITEMS.register("wither_spawn_egg", () -> new ModSpawnEggItem(EntityType.WITHER, 0xF1BF7B, 0x705128,new Item.Properties().group(TestMod.TAB))); and I get an error saying that I need an RegistryObject instead of EntityType, and I understand why, but I don't know how to fix. I want it to work with registry object, so i though maybe I can use .get() on the registry object, but I don't know how to make ModSpawnEggItem be compatible with EntityType, Can somone help me?
  4. i define all the variables at the start of the class, but wouldn't it say <PLAYER> fell out of the world?
  5. I am trying to make it so that when you eat an item, after 5 seconds you die, I use the TickEvent for it, when i do event.player.setHealth(0), the death screen comes up, but the player doesn't die, meaning the respawn button doesn't work and the player can die whilst in the death menu, here's the code that I am using (I added a food item called hog_meat, hogCurse is a global boolean that turns on when you eat the hog_meat, and hog_timer is a global timer that starts when you eat hog_meat): @SubscribeEvent public static void onTick(TickEvent.PlayerTickEvent event){ if (event.player.getEntityWorld().isRemote) { if (hogCurse) { if (hogCurseTimer < 5 * 40) { hogCurseTimer++; if (hogCurseTimer % 40 == 0) { String msg = TextFormatting.RED + "You have " + (6 - hogCurseTimer / 40) + " Seconds left until you DIE!"; event.player.sendMessage(new StringTextComponent(msg), event.player.getUniqueID()); } } else { if (event.player.isAlive()) { String msg = TextFormatting.RED + "You didn't eat bread, now DIE!"; event.player.sendMessage(new StringTextComponent(msg), event.player.getUniqueID()); event.player.setHealth(0); hogCurse = false; hogCurseTimer = 0; } } } } } What can I do to make it work?

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.