Jump to content

Recommended Posts

Posted (edited)

Hello, i got an issue registering my Screen Container.
I followed Jorrit Tybergheins Tutorial on creating a GUI. Again, everything works just fine but the GUI doesnt show up.

After checking the logs, i found the error:

[m[1;31m[21:24:18] [Server thread/FATAL] [minecraft/ThreadTaskExecutor]: Error executing task on Server
java.lang.UnsupportedOperationException: Unable to construct this menu by type
	at net.minecraft.inventory.container.Container.getType(Container.java:52) ~[?:?] {re:classloading}
	at net.minecraftforge.fml.network.NetworkHooks.openGui(NetworkHooks.java:207) ~[?:?] {re:classloading}
	at net.minecraftforge.fml.network.NetworkHooks.openGui(NetworkHooks.java:172) ~[?:?] {re:classloading}
	at com.kahmi.elementcrops.objects.blocks.DungInfuserBlock.onBlockActivated(DungInfuserBlock.java:65) ~[?:?] {re:classloading}
	at net.minecraft.block.BlockState.onBlockActivated(BlockState.java:294) ~[?:?] {re:classloading}
	at net.minecraft.server.management.PlayerInteractionManager.func_219441_a(PlayerInteractionManager.java:343) ~[?:?] {re:classloading}
	at net.minecraft.network.play.ServerPlayNetHandler.processTryUseItemOnBlock(ServerPlayNetHandler.java:881) ~[?:?] {re:classloading}
	at net.minecraft.network.play.client.CPlayerTryUseItemOnBlockPacket.processPacket(CPlayerTryUseItemOnBlockPacket.java:45) ~[?:?] {re:classloading}
	at net.minecraft.network.play.client.CPlayerTryUseItemOnBlockPacket.processPacket(CPlayerTryUseItemOnBlockPacket.java:12) ~[?:?] {re:classloading}
	at net.minecraft.network.PacketThreadUtil.lambda$checkThreadAndEnqueue$0(PacketThreadUtil.java:19) ~[?:?] {re:classloading}
	at net.minecraft.util.concurrent.TickDelayedTask.run(TickDelayedTask.java:20) ~[?:?] {re:classloading}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.run(ThreadTaskExecutor.java:140) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.RecursiveEventLoop.run(RecursiveEventLoop.java:22) [?:?] {re:classloading}
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:759) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:141) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.driveOne(ThreadTaskExecutor.java:110) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.driveOneInternal(MinecraftServer.java:742) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.driveOne(MinecraftServer.java:736) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.driveUntil(ThreadTaskExecutor.java:123) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.runScheduledTasks(MinecraftServer.java:722) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:666) [?:?] {re:classloading,pl:accesstransformer:B}
	at java.lang.Thread.run(Unknown Source) [?:1.8.0_241] {}

After hours of searching for a solution, i came to the point that it must be failing at the registration of my Container, but i cant get why it doesnt work.


Here is my Registry Class:

package com.kahmi.elementcrops.init;

import com.kahmi.elementcrops.ElementCrops;
import com.kahmi.elementcrops.objects.container.DungInfuserBlockContainer;

import net.minecraft.inventory.container.ContainerType;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.extensions.IForgeContainerType;
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;

@Mod.EventBusSubscriber(modid = ElementCrops.MOD_ID, bus = Bus.MOD)
@ObjectHolder(ElementCrops.MOD_ID)
public class ContainerInitializer {
	@SubscribeEvent
	public static void registerContainer(final RegistryEvent.Register<ContainerType<?>> pEvent) {
		pEvent.getRegistry().register(IForgeContainerType.create((pWindowID, pInventory, pData) -> {
			BlockPos pos = pData.readBlockPos();
			return new DungInfuserBlockContainer(pWindowID, ElementCrops.PROXY.getClientWorld(), pos, pInventory, ElementCrops.PROXY.getClientPlayer());
		}).setRegistryName("dunginfuser"));
	}
}

 

Here is my Container Class:

package com.kahmi.elementcrops.objects.container;

import com.kahmi.elementcrops.ElementCrops;
import com.kahmi.elementcrops.objects.blocks.Blocks;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IWorldPosCallable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;
import net.minecraftforge.items.wrapper.InvWrapper;
import net.minecraftforge.registries.ObjectHolder;

@ObjectHolder(ElementCrops.MOD_ID)
public class DungInfuserBlockContainer extends Container {
	private TileEntity mEntity;
	private PlayerEntity mPlayer;
	private IItemHandler mPlayerInventory;
	
	public DungInfuserBlockContainer(int pId, World pWorld, BlockPos pPos, PlayerInventory pInventory, PlayerEntity pPlayer) {
		super(Containers.DUNGINFUSERBLOCK_CONTAINER, pId);
		this.mEntity = pWorld.getTileEntity(pPos);
		this.mPlayer = pPlayer;
		this.mPlayerInventory = new InvWrapper(mPlayer.inventory);
		this.mEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(h -> {
			 addSlot(h, 0, 13, 34);
			 addSlot(h, 1, 34, 34);
			 addSlotRange(h, 2, 55, 34, 3, 18);
			 addSlot(h, 5, 141, 34);
		});
		layoutPlayerInventorySlots(7, 83);
	}
	
	@Override
	public boolean canInteractWith(PlayerEntity pPlayerIn) {
		return isWithinUsableDistance(IWorldPosCallable.of(mEntity.getWorld(), mEntity.getPos()), pPlayerIn, Blocks.DUNGINFUSER);
	}
	
	private void addSlot(IItemHandler pItemHandler, int pIndex, int pX, int pY) {
		addSlot(new SlotItemHandler(pItemHandler, pIndex, pX, pY));
	}
	
	private int addSlotRange(IItemHandler pItemHandler, int pIndex, int pX, int pY, int pAmount, int pDistanceX) {
		for (int i = 0; i < pAmount; i++) {
			addSlot(pItemHandler, pIndex, pX, pY);
			pX += pDistanceX;
			pIndex++;
		}
		return pIndex;
	}
	
	private int addSlotBox(IItemHandler pItemHandler, int pIndex, int pX, int pY, int pColumns, int pDistanceX, int pRows, int pDistanceY) {
		for (int i = 0; i < pRows; i++) {
			pIndex = addSlotRange(pItemHandler, pIndex, pX, pY, pColumns, pDistanceX);
			pY += pDistanceY;
		}
		return pIndex;
	}
	
	private void layoutPlayerInventorySlots(int pX, int pY) {
		addSlotBox(this.mPlayerInventory, 9, pX, pY, 9, 18, 3, 18);
		
		pY += 58;
		addSlotRange(this.mPlayerInventory, 0, pX, pY, 9, 18);
	}
}


Here is my Block Class:

package com.kahmi.elementcrops.objects.blocks;

import javax.annotation.Nullable;

import com.kahmi.elementcrops.objects.entities.DungInfuserTileEntity;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.pathfinding.PathType;
import net.minecraft.state.IntegerProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.shapes.IBooleanFunction;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkHooks;

public class DungInfuserBlock extends Block {
	public static final IntegerProperty LEVEL = IntegerProperty.create("level", 0, 5);
	private static final VoxelShape INSIDE = makeCuboidShape(2.0D, 4.0D, 2.0D, 14.0D, 16.0D, 14.0D);
	private static final VoxelShape SHAPE = VoxelShapes.combineAndSimplify(VoxelShapes.fullCube(), VoxelShapes.or(makeCuboidShape(0.0D, 0.0D, 4.0D, 16.0D, 3.0D, 12.0D), makeCuboidShape(4.0D, 0.0D, 0.0D, 12.0D, 3.0D, 16.0D), makeCuboidShape(2.0D, 0.0D, 2.0D, 14.0D, 3.0D, 14.0D), INSIDE), IBooleanFunction.ONLY_FIRST);
	
	public DungInfuserBlock(Properties pProperties) {
	   super(pProperties);
	   this.setDefaultState(this.stateContainer.getBaseState().with(LEVEL, Integer.valueOf(0)));
	}
	
	@Override
	public boolean hasTileEntity(BlockState pState) {
		return true;
	}
	
	@Nullable
	@Override
	public TileEntity createTileEntity(BlockState pState, IBlockReader pWorld) {
		return new DungInfuserTileEntity();
	}
	
	@Override
	public VoxelShape getShape(BlockState pState, IBlockReader pWorldIn, BlockPos pPos, ISelectionContext pContext) {
		return SHAPE;
	}
	
	@Override
	public VoxelShape getRaytraceShape(BlockState pState, IBlockReader pWworldIn, BlockPos pPos) {
		return INSIDE;
	}

	@Override
	public ActionResultType onBlockActivated(BlockState pState, World pWorldIn, BlockPos pPos, PlayerEntity pPlayer, Hand pHandIn, BlockRayTraceResult pResult) {
		if (!pWorldIn.isRemote) {
			TileEntity entity = pWorldIn.getTileEntity(pPos);
			if (entity instanceof INamedContainerProvider) {
				NetworkHooks.openGui((ServerPlayerEntity)pPlayer, (INamedContainerProvider)entity, entity.getPos());
			} else {
				throw new IllegalStateException("Our named container provider is missing!");
			}
			return ActionResultType.SUCCESS;
		}
		return super.onBlockActivated(pState, pWorldIn, pPos, pPlayer, pHandIn, pResult);
	}

	
	public void setContentLevel(World pWorldIn, BlockPos pPos, BlockState pState, int pLevel) {
		pWorldIn.setBlockState(pPos, pState.with(LEVEL, Integer.valueOf(MathHelper.clamp(pLevel, 0, 5))), 2);
		pWorldIn.updateComparatorOutputLevel(pPos, this);
	}

	/**
	* @deprecated call via {@link IBlockState#hasComparatorInputOverride()} whenever possible. Implementing/overriding
	* is fine.
	*/
	public boolean hasComparatorInputOverride(BlockState pState) {
		return true;
	}

	/**
	* @deprecated call via {@link IBlockState#getComparatorInputOverride(World,BlockPos)} whenever possible.
	* Implementing/overriding is fine.
	*/
	public int getComparatorInputOverride(BlockState pBlockState, World pWorldIn, BlockPos pPos) {
		return pBlockState.get(LEVEL);
	}

	protected void fillStateContainer(StateContainer.Builder<Block, BlockState> pBuilder) {
		pBuilder.add(LEVEL);
	}

	public boolean allowsMovement(BlockState pState, IBlockReader pWorldIn, BlockPos pPos, PathType pType) {
		return false;
	}
}


if you need more code, i will setup github tomorrow.

Thanks in advance!

EDIT: this is my GitHub

Edited by SW Raki
Posted
3 hours ago, SW Raki said:

TileEntity entity = pWorldIn.getTileEntity(pPos);

if (entity instanceof INamedContainerProvider)

Show your TE class.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Here is my Tile Entity Class

package com.kahmi.elementcrops.objects.entities;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.kahmi.elementcrops.objects.container.DungInfuserBlockContainer;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.INBTSerializable;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;

public class DungInfuserTileEntity extends TileEntity implements INamedContainerProvider {
	//private DungInfuserItemStackHandler handler = new DungInfuserItemStackHandler();
	private LazyOptional<IItemHandler> mHandler = LazyOptional.of(this::createHandler);
	
	public DungInfuserTileEntity() {
		super(TileEntities.DUNGINFUSERTILEENTITY);
	}
	
	public DungInfuserItemStackHandler createHandler() {
		return new DungInfuserItemStackHandler();
	}
	
	@Override
	public void read(CompoundNBT pCompound) {
		CompoundNBT inventory = pCompound.getCompound("inv");
		this.mHandler.ifPresent(h -> ((INBTSerializable<CompoundNBT>)h).deserializeNBT(inventory));
		super.read(pCompound);
	}

	@Override
	public CompoundNBT write(CompoundNBT pCompound) {
		this.mHandler.ifPresent(h -> {
			CompoundNBT inventory = ((INBTSerializable<CompoundNBT>)h).serializeNBT();
			pCompound.put("inv", inventory);
		});
		return super.write(pCompound);
	}

	@Nonnull
	@Override
	public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> pCapability, @Nullable Direction pSide) {
		if (pCapability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
			return mHandler.cast();
		}
		return super.getCapability(pCapability, pSide);
	}

	@Nullable
	@Override
	public Container createMenu(int pId, PlayerInventory pInventory, PlayerEntity pPlayer) {
		return new DungInfuserBlockContainer(pId, world, pos, pInventory, pPlayer);
	}

	@Override
	public ITextComponent getDisplayName() {
		return new StringTextComponent(getType().getRegistryName().getPath());
	}
}

 

Posted
4 hours ago, diesieben07 said:

This is null.

Well, that was unfortunate. in the tutorial video, it was actually null. i just shifted the IForgeContainerType.create method to the declaration section of my containertype, and now it works.
I Dont know why my GUI is rendering completely in grey, but thats another issue i might get handled myself.
Thanks.

Posted

Use a DeferredRegistry or @ObjectHolder annotations.

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
2 minutes ago, Draco18s said:

Use a DeferredRegistry or @ObjectHolder annotations.

I have yet to look up how to use DeferredRegistry. For now, i will finish implementing the core mechanics of my mod and will then start to clean up things. I last modded like 1.7.10, so i have to refresh my knowledge, but thanks for pointing that out!

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello! There is an issue with my world(Chocolate Edition modpack), after joining the world all creatures are frozen and the game is not responding or the game crashes after short period of time. Reproduction Steps: Turn on the game Join the world Game crashes immediately or after short period of time. Additional info: Crash log saying that an entity crashed the game is created after the crash(not the logs that I posted, different file from crash-logs, game crashed 3x by Snail, 1x by Small Snail, 1x by Tortoise) Specification: CPU: i5-13600KF GPU: GTX 1070 RAM: 32GB 3200MhZ - allocated 10GB Log links: latest.log: https://mclo.gs/Lp8zlsv crash-reports/crash: https://mclo.gs/XhtyJQI Minecraft version: 1.19.2 Modpack Version: Chocolate Edition 1.9 OS: Windows 10 Java Version: 22.0.2 Minecraft Java: Java 17
    • Hello, for several days I've been trying to find a way to add my animations in this style. @Override public void setupAnim(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { }   My current public class is : public class FakePlayerModelWithAnim<T extends FakePlayerEntity> extends EntityModel<EntityRenderState>   But i can't do that :  public class FakePlayerModelWithAnim<T extends FakePlayerEntity> extends EntityModel<T> Type parameter 'T' is not within its bound; should extend 'net.minecraft.client.renderer.entity.state.EntityRenderState' But with EntityRenderState it ok and it work !   But my setupAnim look like this :  @Override public void setupAnim(EntityRenderState p_370046_) { super.setupAnim(p_370046_); }   I don't have any access to my entity ! Look like 1.21.1 : @Override public void setupAnim(FakePlayerEntity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { this.root().getAllParts().forEach(ModelPart::resetPose); this.applyHeadRotation(netHeadYaw, headPitch); this.animateWalk(FakePlayerEntityAnimations.ANIM_PLAYERS_WALKING, limbSwing, limbSwingAmount, 2f, 2.5f); this.animate(entity.idleAnimationState, FakePlayerEntityAnimations.ANIM_PLAYERS_IDLE, ageInTicks, 1f); } But i'm stuck with new version of Forge...
    • Looks like an issue with abyssalsovereigns - this mod has functions that are not working on a server (client-side-only mod)
    • I added some new mods and updated old ones to my forge server and they will run successfully but the moment I try to join ill briefly load into the world and get booted with the message, internal server error. The mods in question work fine on singleplayer and removing too many from the server causes it to stop working so I cant be sure which one is causing the problem... any ideas? server log: https://pastebin.com/hGH8UUjm client log (from modrinth app): https://mclo.gs/a3oOUGY
    • The level.dat contains an invalid tag ID (115) Try to load the world in singleplayer - then test this world on the server
  • Topics

×
×
  • Create New...

Important Information

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