Jump to content

[1.16.5] Trying to open invalid screen with name


RInventor7

Recommended Posts

I was about to test my GUI in game, but when I right clicked on the block I got this following message. Any idea what have I done wrong and where? Thanks!

[Render thread/WARN] [minecraft/ScreenManager]: Trying to open invalid screen with name: ticket_container

Block class

package com.rinventor.transportmod.objects.tileentities.ticket_machine;


import com.rinventor.transportmod.init.ModTileEntities;
import com.rinventor.transportmod.objects.blocks.BBDirectionalOp;

import io.netty.buffer.Unpooled;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.network.PacketBuffer;
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.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkHooks;

public class TicketMachineBlock extends BBDirectionalOp  {

	public TicketMachineBlock() {
		super(Properties.create(Material.IRON)
				.sound(SoundType.METAL)
				.setLightLevel(s -> 15)
		);
	}
	
	@Override
	public boolean hasTileEntity(BlockState state) {
		return true;
	}
	
	@Override
	public TileEntity createTileEntity(BlockState state, IBlockReader world) {
		return ModTileEntities.TICKET_MACHINE.get().create();
	}

	@Override
	public int getOpacity(BlockState state, IBlockReader worldIn, BlockPos pos) {
		return 15;
	}
	
	@Override
	public ActionResultType onBlockActivated(BlockState blockstate, World world, BlockPos pos, PlayerEntity entity, Hand hand, BlockRayTraceResult hit) {
		super.onBlockActivated(blockstate, world, pos, entity, hand, hit);
		int x = pos.getX();
		int y = pos.getY();
		int z = pos.getZ();
		if (entity instanceof ServerPlayerEntity) {
			NetworkHooks.openGui((ServerPlayerEntity) entity, new INamedContainerProvider() {
				@Override
				public ITextComponent getDisplayName() {
					return new StringTextComponent("ticket_container");
				}

				@Override
				public Container createMenu(int id, PlayerInventory inventory, PlayerEntity player) {
					return new TicketContainer(id, inventory, new PacketBuffer(Unpooled.buffer()).writeBlockPos(new BlockPos(x, y, z)));
				}
			}, new BlockPos(x, y, z));
		}
		return ActionResultType.SUCCESS;

	}

	@Override
	public INamedContainerProvider getContainer(BlockState state, World worldIn, BlockPos pos) {
		TileEntity tileEntity = worldIn.getTileEntity(pos);
		return tileEntity instanceof INamedContainerProvider ? (INamedContainerProvider) tileEntity : null;
	}

	@Override
	public boolean eventReceived(BlockState state, World world, BlockPos pos, int eventID, int eventParam) {
		super.eventReceived(state, world, pos, eventID, eventParam);
		TileEntity tileentity = world.getTileEntity(pos);
		return tileentity == null ? false : tileentity.receiveClientEvent(eventID, eventParam);
	}

	@SuppressWarnings("deprecation")
	@Override
	public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) {
		if (state.getBlock() != newState.getBlock()) {
			TileEntity tileentity = world.getTileEntity(pos);
			if (tileentity instanceof TicketMachineTile) {
				InventoryHelper.dropInventoryItems(world, pos, (IInventory) tileentity);
				world.updateComparatorOutputLevel(pos, this);
			}
			super.onReplaced(state, world, pos, newState, isMoving);
		}
	}

	@Override
	public boolean hasComparatorInputOverride(BlockState state) {
		return true;
	}

	@Override
	public int getComparatorInputOverride(BlockState blockState, World world, BlockPos pos) {
		TileEntity tileentity = world.getTileEntity(pos);
		if (tileentity instanceof TicketMachineTile)
			return Container.calcRedstoneFromInventory((IInventory) tileentity);
		else
			return 0;
	}

}

TileEntity class

package com.rinventor.transportmod.objects.tileentities.ticket_machine;

import java.util.stream.IntStream;

import javax.annotation.Nullable;

import com.rinventor.transportmod.init.ModTileEntities;

import io.netty.buffer.Unpooled;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.inventory.container.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
import net.minecraft.tileentity.LockableLootTileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.SidedInvWrapper;

public class TicketMachineTile extends LockableLootTileEntity implements ISidedInventory {
	
	private NonNullList<ItemStack> stacks = NonNullList.<ItemStack>withSize(3, ItemStack.EMPTY);

	public TicketMachineTile(TileEntityType<?> typeIn) {
		super(typeIn);
	}
	
	public TicketMachineTile() {
		this(ModTileEntities.TICKET_MACHINE.get());
	}
	
	@Override
	public void read(BlockState state, CompoundNBT compound) {
		super.read(state, compound);
		if (!this.checkLootAndRead(compound)) {
			this.stacks = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY);
		}
		ItemStackHelper.loadAllItems(compound, this.stacks);

	}
	
	@Override
	public CompoundNBT write(CompoundNBT compound) {
		super.write(compound);
		if (!this.checkLootAndWrite(compound)) {
			ItemStackHelper.saveAllItems(compound, this.stacks);
		}
		return compound;
	}
	
	@Override
	public SUpdateTileEntityPacket getUpdatePacket() {
		return new SUpdateTileEntityPacket(this.pos, 0, this.getUpdateTag());
	}

	@Override
	public CompoundNBT getUpdateTag() {
		return this.write(new CompoundNBT());
	}

	@Override
	public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) {
		this.read(this.getBlockState(), pkt.getNbtCompound());
	}

	@Override
	public int getSizeInventory() {
		return stacks.size();
	}

	@Override
	public boolean isEmpty() {
		for (ItemStack itemstack : this.stacks)
			if (!itemstack.isEmpty())
				return false;
		return true;
	}

	@Override
	public ITextComponent getDefaultName() {
		return new StringTextComponent("ticket_container");
	}

	@Override
	public int getInventoryStackLimit() {
		return 64;
	}

	@Override
	public Container createMenu(int id, PlayerInventory player) {
		return new TicketContainer(id, player, new PacketBuffer(Unpooled.buffer()).writeBlockPos(this.getPos()));
	}

	@Override
	public ITextComponent getDisplayName() {
		return new TranslationTextComponent("block.transportmod.ticket_machine");
	}

	@Override
	protected NonNullList<ItemStack> getItems() {
		return this.stacks;
	}

	@Override
	protected void setItems(NonNullList<ItemStack> stacks) {
		this.stacks = stacks;
	}

	@Override
	public boolean isItemValidForSlot(int index, ItemStack stack) {
		return true;
	}

	@Override
	public int[] getSlotsForFace(Direction side) {
		return IntStream.range(0, this.getSizeInventory()).toArray();
	}

	@Override
	public boolean canInsertItem(int index, ItemStack stack, @Nullable Direction direction) {
		return this.isItemValidForSlot(index, stack);
	}

	@Override
	public boolean canExtractItem(int index, ItemStack stack, Direction direction) {
		return true;
	}

	private final LazyOptional<? extends IItemHandler>[] handlers = SidedInvWrapper.create(this, Direction.values());

	@Override
	public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Direction facing) {
		if (!this.removed && facing != null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
			return handlers[facing.ordinal()].cast();
		return super.getCapability(capability, facing);
	}

	@Override
	public void remove() {
		super.remove();
		for (LazyOptional<? extends IItemHandler> handler : handlers)
			handler.invalidate();
	}
	
}

Container class

package com.rinventor.transportmod.objects.tileentities.ticket_machine;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

import com.rinventor.transportmod.accessibility.TransportDBG;
import com.rinventor.transportmod.init.ModNetwork;
import com.rinventor.transportmod.network.ticket_machine.TicketSlotMessage;

import net.minecraft.block.Blocks;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
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.ItemStackHandler;
import net.minecraftforge.items.SlotItemHandler;

public class TicketContainer extends Container implements Supplier<Map<Integer, Slot>> {
	private final PlayerEntity playerEntity;
	private IItemHandler internal;
	World world;
	PlayerEntity entity;
	int x, y, z;
	private Map<Integer, Slot> customSlots = new HashMap<>();
	private boolean bound = false;

	@SuppressWarnings("unchecked")
	public TicketContainer(int id, PlayerInventory inv, PacketBuffer extraData) {
		super(new ContainerType<>(new TicketContainerFactory()), id);
		this.entity = inv.player;
		this.world = inv.player.world;
		this.internal = new ItemStackHandler(3);
		BlockPos pos = null;
		if (extraData != null) {
			pos = extraData.readBlockPos();
			this.x = pos.getX();
			this.y = pos.getY();
			this.z = pos.getZ();
		}
		if (pos != null) {
			if (extraData.readableBytes() == 1) { // bound to item
				byte hand = extraData.readByte();
				ItemStack itemstack;
				if (hand == 0)
					itemstack = this.entity.getHeldItemMainhand();
				else
					itemstack = this.entity.getHeldItemOffhand();
				itemstack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).ifPresent(capability -> {
					this.internal = capability;
					this.bound = true;
				});
			} else if (extraData.readableBytes() > 1) {
				extraData.readByte(); // drop padding
				Entity entity = world.getEntityByID(extraData.readVarInt());
				if (entity != null)
					entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).ifPresent(capability -> {
						this.internal = capability;
						this.bound = true;
					});
			} else { // might be bound to block
				TileEntity ent = inv.player != null ? inv.player.world.getTileEntity(pos) : null;
				if (ent != null) {
					ent.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).ifPresent(capability -> {
						this.internal = capability;
						this.bound = true;
					});
				}
			}
		}
		this.customSlots.put(0, this.addSlot(new SlotItemHandler(internal, 0, 15, 21) {
			@Override
			public void onSlotChanged() {
				super.onSlotChanged();
				TicketContainer.this.slotChanged(0, 0, 0);
			}

			@Override
			public boolean isItemValid(ItemStack stack) {
				return (Blocks.DIAMOND_BLOCK.asItem() == stack.getItem());
			}
		}));
		this.customSlots.put(1, this.addSlot(new SlotItemHandler(internal, 1, 39, 21) {
			@Override
			public void onSlotChanged() {
				super.onSlotChanged();
				TicketContainer.this.slotChanged(1, 0, 0);
			}

			@Override
			public ItemStack onTake(PlayerEntity entity, ItemStack stack) {
				ItemStack retval = super.onTake(entity, stack);
				TicketContainer.this.slotChanged(1, 1, 0);
				return retval;
			}

			@Override
			public boolean isItemValid(ItemStack stack) {
				return false;
			}
		}));
		this.customSlots.put(2, this.addSlot(new SlotItemHandler(internal, 2, 127, 21) {
			@Override
			public boolean canTakeStack(PlayerEntity player) {
				return false;
			}

			@Override
			public boolean isItemValid(ItemStack stack) {
				return false;
			}
		}));
		this.playerEntity = inv.player;

		int si;
		int sj;
		for (si = 0; si < 3; ++si)
			for (sj = 0; sj < 9; ++sj)
				this.addSlot(new Slot(inv, sj + (si + 1) * 9, 0 + 8 + sj * 18, 0 + 84 + si * 18));
		for (si = 0; si < 9; ++si)
			this.addSlot(new Slot(inv, si, 0 + 8 + si * 18, 0 + 142));
	}

	@Override
	public boolean canInteractWith(PlayerEntity player) {
		return true;
	}

    private static final int HOTBAR_SLOT_COUNT = 9;
    private static final int PLAYER_INVENTORY_ROW_COUNT = 3;
    private static final int PLAYER_INVENTORY_COLUMN_COUNT = 9;
    private static final int PLAYER_INVENTORY_SLOT_COUNT = PLAYER_INVENTORY_COLUMN_COUNT * PLAYER_INVENTORY_ROW_COUNT;
    private static final int VANILLA_SLOT_COUNT = HOTBAR_SLOT_COUNT + PLAYER_INVENTORY_SLOT_COUNT;
    private static final int VANILLA_FIRST_SLOT_INDEX = 0;
    private static final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;
    private static final int TE_INVENTORY_SLOT_COUNT = 3;  // must match TileEntityInventoryBasic.NUMBER_OF_SLOTS

    @Override
    public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) {
        Slot sourceSlot = inventorySlots.get(index);
        if (sourceSlot == null || !sourceSlot.getHasStack()) return ItemStack.EMPTY;  //EMPTY_ITEM
        ItemStack sourceStack = sourceSlot.getStack();
        ItemStack copyOfSourceStack = sourceStack.copy();

        // Check if the slot clicked is one of the vanilla container slots
        if (index < VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT) {
            // This is a vanilla container slot so merge the stack into the tile inventory
            if (!mergeItemStack(sourceStack, TE_INVENTORY_FIRST_SLOT_INDEX, TE_INVENTORY_FIRST_SLOT_INDEX
                    + TE_INVENTORY_SLOT_COUNT, false)) {
                return ItemStack.EMPTY;  // EMPTY_ITEM
            }
        } else if (index < TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT) {
            // This is a TE slot so merge the stack into the players inventory
            if (!mergeItemStack(sourceStack, VANILLA_FIRST_SLOT_INDEX, VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT, false)) {
                return ItemStack.EMPTY;
            }
        } else {
            TransportDBG.Dbg("Invalid slotIndex:" + index);
            return ItemStack.EMPTY;
        }
        // If stack size == 0 (the entire stack was moved) set slot contents to null
        if (sourceStack.getCount() == 0) {
            sourceSlot.putStack(ItemStack.EMPTY);
        } else {
            sourceSlot.onSlotChanged();
        }
        sourceSlot.onTake(playerEntity, sourceStack);
        return copyOfSourceStack;
    }

    public Map<Integer, Slot> get() {
		return customSlots;
	}

    @Override
	protected boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection) {
		boolean flag = false;
		int i = startIndex;
		if (reverseDirection) {
			i = endIndex - 1;
		}
		if (stack.isStackable()) {
		while (!stack.isEmpty()) {
			if (reverseDirection) {
				if (i < startIndex) {
					break;
				}
			} else if (i >= endIndex) {
				break;
			}
			Slot slot = this.inventorySlots.get(i);
			ItemStack itemstack = slot.getStack();
			if (slot.isItemValid(itemstack) && !itemstack.isEmpty() && areItemsAndTagsEqual(stack, itemstack)) {
				int j = itemstack.getCount() + stack.getCount();
				int maxSize = Math.min(slot.getSlotStackLimit(), stack.getMaxStackSize());
				if (j <= maxSize) {
					stack.setCount(0);
					itemstack.setCount(j);
					slot.putStack(itemstack);
					flag = true;
				} 
				else if (itemstack.getCount() < maxSize) {
					stack.shrink(maxSize - itemstack.getCount());
					itemstack.setCount(maxSize);
					slot.putStack(itemstack);
					flag = true;
				}
			}
			if (reverseDirection) { --i; } 
			else { ++i; }
		}
	}
	if (!stack.isEmpty()) {
		if (reverseDirection) { i = endIndex - 1; } 
		else { i = startIndex; }
		while (true) {
			if (reverseDirection) {
				if (i < startIndex) {
					break;
				}
			} else if (i >= endIndex) {
				break;
			}
			Slot slot1 = this.inventorySlots.get(i);
			ItemStack itemstack1 = slot1.getStack();
			if (itemstack1.isEmpty() && slot1.isItemValid(stack)) {
				if (stack.getCount() > slot1.getSlotStackLimit()) {
					slot1.putStack(stack.split(slot1.getSlotStackLimit()));
				} else {
					slot1.putStack(stack.split(stack.getCount()));
				}
				slot1.onSlotChanged();
				flag = true;
				break;
			}
			if (reverseDirection) { --i; } 
			else { ++i; }
		}
	}
	return flag;
	}
	
    @Override
	public void onContainerClosed(PlayerEntity playerIn) {
		super.onContainerClosed(playerIn);
		if (!bound && (playerIn instanceof ServerPlayerEntity)) {
			if (!playerIn.isAlive() || playerIn instanceof ServerPlayerEntity && ((ServerPlayerEntity) playerIn).hasDisconnected()) {
				for (int j = 0; j < internal.getSlots(); ++j) {
					playerIn.dropItem(internal.extractItem(j, internal.getStackInSlot(j).getCount(), false), false);
				}
			} else {
				for (int i = 0; i < internal.getSlots(); ++i) {
					playerIn.inventory.placeItemBackInInventory(playerIn.world,
							internal.extractItem(i, internal.getStackInSlot(i).getCount(), false));
				}
			}
		}
	}

	private void slotChanged(int slotid, int ctype, int meta) {
		if (this.world != null && this.world.isRemote()) {
			ModNetwork.PACKET_HANDLER.sendToServer(new TicketSlotMessage(slotid, x, y, z, ctype, meta));
			TicketMachineEvents.slotItemChanged(slotid, this.world, x, y, z, entity);
		}
	}

	
}

ContainerFactory class

package com.rinventor.transportmod.objects.tileentities.ticket_machine;

import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.network.IContainerFactory;

public class TicketContainerFactory implements IContainerFactory {

	public TicketContainer create(int id, PlayerInventory inv, PacketBuffer extraData) {
		return new TicketContainer(id, inv, extraData);
	}
	
}

Screen class

package com.rinventor.transportmod.objects.tileentities.ticket_machine;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import com.rinventor.transportmod.init.ModNetwork;
import com.rinventor.transportmod.network.ticket_machine.TicketButtonMessage;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent;

public class TicketScreen extends ContainerScreen<TicketContainer> {
	private static final ResourceLocation texture = new ResourceLocation("transportmod:textures/ticket_menu.png");
	private int x, y, z;
	private PlayerEntity entity;


	public TicketScreen(TicketContainer container, PlayerInventory inventory, ITextComponent titleIn) {
		super(container, inventory, titleIn);
		this.x = container.x;
		this.y = container.y;
		this.z = container.z;
		this.entity = container.entity;
		this.xSize = 176;
		this.ySize = 166;
	}
	
	@Override
	public void render(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
		this.renderBackground(ms);
		super.render(ms, mouseX, mouseY, partialTicks);
		this.renderHoveredTooltip(ms, mouseX, mouseY);
	}
	
	@Override
	protected void drawGuiContainerBackgroundLayer(MatrixStack ms, float partialTicks, int gx, int gy) {
		RenderSystem.color4f(1, 1, 1, 1);
		RenderSystem.enableBlend();
		RenderSystem.defaultBlendFunc();
		Minecraft.getInstance().getTextureManager().bindTexture(texture);
		int k = (this.width - this.xSize) / 2;
		int l = (this.height - this.ySize) / 2;
		TicketScreen.blit(ms, k, l, 0, 0, this.xSize, this.ySize, this.xSize, this.ySize);
		RenderSystem.disableBlend();
	}

	@Override
	public boolean keyPressed(int key, int b, int c) {
		if (key == 256) {
			this.minecraft.player.closeScreen();
			return true;
		}
		return super.keyPressed(key, b, c);
	}

	@Override
	public void tick() {
		super.tick();
	}

	@Override
	protected void drawGuiContainerForegroundLayer(MatrixStack ms, int mouseX, int mouseY) {
		this.font.drawString(ms, new TranslationTextComponent("transportmod.ticket_machine.tickets").toString(), 119, 9, -12829636);
		this.font.drawString(ms, new TranslationTextComponent("transportmod.transport_factory.price").toString(), 15, 9, -12829636);
		this.font.drawString(ms, new TranslationTextComponent("container.inventory").toString(), 7, 61, -12829636);
	}

	@Override
	public void onClose() {
		super.onClose();
		Minecraft.getInstance().keyboardListener.enableRepeatEvents(false);
	}

	@Override
	public void init(Minecraft minecraft, int width, int height) {
		super.init(minecraft, width, height);
		minecraft.keyboardListener.enableRepeatEvents(true);
		this.addButton(new Button(this.guiLeft + 75, this.guiTop + 20, 40, 20, new StringTextComponent("->"), e -> {
			if (true) {
				ModNetwork.PACKET_HANDLER.sendToServer(new TicketButtonMessage(0, x, y, z));
				TicketButtonMessage.handleButtonAction(entity, 0, x, y, z);
			}
		}));
	}
	
}

Container registring

package com.rinventor.transportmod.init;

import com.rinventor.transportmod.TransportMod;
import com.rinventor.transportmod.objects.tileentities.ticket_machine.TicketContainer;

import io.netty.buffer.Unpooled;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.extensions.IForgeContainerType;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public class ModContainers {
	
	public static final DeferredRegister<ContainerType<?>> CONTAINERS = DeferredRegister.create(ForgeRegistries.CONTAINERS, TransportMod.MOD_ID);
	
	public static final RegistryObject<ContainerType<TicketContainer>> TICKET_CONTAINER = CONTAINERS.register("ticket_container", 
			() -> IForgeContainerType.create(((windowId, inv, data) -> {
				BlockPos pos = data.readBlockPos();
				return new TicketContainer(windowId, inv, new PacketBuffer(Unpooled.buffer()).writeBlockPos(pos));
			})));
	
}

Main class

 public TransportMod() 
    {
    	final IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();

    	ModBlocks.BLOCKS.register(bus);
    	ModTileEntities.TILE_ENTITIES.register(bus);
    	ModContainers.CONTAINERS.register(bus);
    	ModEntities.ENTITIES.register(bus);
    	
    	instance_m = this;
    	MinecraftForge.EVENT_BUS.register(this);
    }
    
    @SubscribeEvent
    public static void onRegisterEntities(final RegistryEvent.Register<EntityType<?>> event) {
    }
    
	
	@SubscribeEvent
	public void clientSetup(final FMLClientSetupEvent event) {
    	event.enqueueWork(() -> {
        	ScreenManager.registerFactory(ModContainers.TICKET_CONTAINER.get(), TicketScreen::new);
    	});
    }

 

Link to comment
Share on other sites

It's still giving the same error. Maybe I'm still registring my screen wrong?

@Mod("transportmod")
@Mod.EventBusSubscriber(modid = TransportMod.MOD_ID, bus = Bus.MOD)
public class TransportMod
{
    public static final String MOD_ID = "transportmod";
    public static TransportMod instance_m;

    public TransportMod() 
    {
    	final IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
    	
    	bus.addListener(this::commonSetup);
    	bus.addListener(this::clientSetup);
    	
    	ModItems.ITEMS.register(bus);
    	ModBlocks.BLOCKS.register(bus);
    	ModTileEntities.TILE_ENTITIES.register(bus);
    	ModContainers.CONTAINERS.register(bus);
    	
    	instance_m = this;
    	MinecraftForge.EVENT_BUS.register(this);
    }
    
    @SubscribeEvent
	public void commonSetup(final FMLCommonSetupEvent event) {
		event.enqueueWork(ModNetwork::init);
    }
	
	@SubscribeEvent
	public void clientSetup(final FMLClientSetupEvent event) {
    	event.enqueueWork(() -> {
        	ScreenManager.registerFactory(ModContainers.TICKET_CONTAINER.get(), TicketScreen::new);
    	});
    }

 

Link to comment
Share on other sites

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! I am trying to make custom dimensions for a modpack I am making in an older minecraft version, 1.16.5. I like that version and it has a few other mods that have not been updated that I would still like to use. Anyway, I am having a terrible time with getting my dimension to work and have tried using code from other peoples projects to at least figure out what I'm supposed to be doing but it has not been as helpful as I would have liked. If anyone could help that would be greatly appreciated! Here is my github with all the code as I am using it: https://github.com/BladeColdsteel/InvigoratedDimensionsMod I have also included the last log, https://pastebin.com/zX9vsDSq, I had when I tried to load up a world, let me know if there is anything else I should send though, thank you!
    • Whether you are a fan of Hypixel Bedwars, SkyWars and PvP gamemodes like that, well you would enjoy this server! We have a very fun and unique style of PvP that a lot of our players really enjoy and we want to bring this server to more players like you! Yes you reading this post haha. Introducing, the Minezone Network, home of SUPER CRAFT BLOCKS. We've been working on this server for over 4 years now. Here is what we have to offer: SUPER CRAFT BLOCKS: This has 3 different gamemodes you can play, Classic, Duels and Frenzy. Each mode offers over 60 kits to choose from, along with a total of over 60 maps, allowing for various different playstyles on each map. There are also random powerups that spawn on the map which can include Health Pots, Bazookas, Nukes, Extra Lives and way way more! There is also double jump in this gamemode as well, which makes PvP a lot more fun & unique. You only need a minimum of 2 players to start any mode! Classic: Choose a kit, 5 lives for each player, fight it out and claim the #1 spot! Look out for lightning as they can spawn powerups to really give you an advantage in the game! Duels: Fight against another random player or one of your friends and see who is the best! Frenzy: Your kit is randomly selected for you, each life you will have a different kit. You can fight with up to 100 players in this mode and lets see who will be the best out of that 100! All the other stuff from Classic/Duels apply to this mode as well like powerups. We have 2 ranks on this server too, VIP and CAPTAIN which has a bunch of different perks for SCB and other things like Cosmetics and more.   SERVER IP: If this server has caught your interest in any way, please consider joining and you will NOT regret it! Bring some of your friends online for an even better experience and join in on the fun at: IP: minezone.club Hope to see you online!   SERVER TRAILER: https://www.youtube.com/watch?v=0phpMgu1mH0
    • The mod give new blocks  
    • I will a Mode for 1.21 in this Mod give new block, items and dimensions   
  • Topics

×
×
  • Create New...

Important Information

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