Jump to content

knoxi

Members
  • Posts

    11
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

knoxi's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Idk, i was just trying to make it work
  2. Ty, I've tried to use slotchangedcraftinggrid() before but it didn't work but this is very helpful tysm
  3. I've Made A Mod With Custom Items And Instead Of Letting People Craft Them In The Crafting Table I want To Make My Own Custom Workbench, I'm Using Mostly Just The Crafting Table Code But I'm Struggling To Create Something To Make A Result. Here Is My Code: TableOfMagic: public class TableOfMagic extends Block { private static final Component CONTAINER_TITLE = Component.translatable("container.crafting"); public TableOfMagic(Properties p_49795_) { super(p_49795_); } @Override public InteractionResult use(BlockState p_60503_, Level p_60504_, BlockPos p_60505_, Player p_60506_, InteractionHand p_60507_, BlockHitResult p_60508_) { if (p_60504_.isClientSide) { return InteractionResult.SUCCESS; } else { p_60506_.openMenu(p_60503_.getMenuProvider(p_60504_, p_60505_)); return InteractionResult.CONSUME; } } @Nullable @Override public MenuProvider getMenuProvider(BlockState p_60563_, Level p_60564_, BlockPos p_60565_) { return new SimpleMenuProvider((p_52229_, p_52230_, p_52231_) -> new TableOfMagicMenu(p_52229_, p_52230_), CONTAINER_TITLE); } } TableOfMagicMenu: public class TableOfMagicMenu extends AbstractContainerMenu implements Container { private final ContainerLevelAccess access; private final Player player; private final CraftingContainer craftSlots = new CraftingContainer(this, 3, 3); private final ResultContainer resultSlots = new ResultContainer(); public TableOfMagicMenu(int p_39353_, Inventory p_39354_) { this(p_39353_, p_39354_, ContainerLevelAccess.NULL); } public TableOfMagicMenu(int p_39356_, Inventory p_39357_, ContainerLevelAccess p_39358_) { super(ModBlockContainers.TABLE_OF_MAGIC.get(), p_39356_); this.access = p_39358_; this.player = p_39357_.player; this.addSlot(new ResultSlot(p_39357_.player, this.craftSlots, this.resultSlots, 0, 124, 35)); for(int i = 0; i < 3; ++i) { for(int j = 0; j < 3; ++j) { this.addSlot(new Slot(this.craftSlots, j + i * 3, 30 + j * 18, 17 + i * 18)); } } for(int k = 0; k < 3; ++k) { for(int i1 = 0; i1 < 9; ++i1) { this.addSlot(new Slot(p_39357_, i1 + k * 9 + 9, 8 + i1 * 18, 84 + k * 18)); } } for(int l = 0; l < 9; ++l) { this.addSlot(new Slot(p_39357_, l, 8 + l * 18, 142)); } } @Override public ItemStack quickMoveStack(Player p_39391_, int p_39392_) { ItemStack itemstack = ItemStack.EMPTY; Slot slot = this.slots.get(p_39392_); if (slot != null && slot.hasItem()) { ItemStack itemstack1 = slot.getItem(); itemstack = itemstack1.copy(); if (p_39392_ == 0) { this.access.execute((p_39378_, p_39379_) -> { itemstack1.getItem().onCraftedBy(itemstack1, p_39378_, p_39391_); }); if (!this.moveItemStackTo(itemstack1, 10, 46, true)) { return ItemStack.EMPTY; } slot.onQuickCraft(itemstack1, itemstack); } else if (p_39392_ >= 10 && p_39392_ < 46) { if (!this.moveItemStackTo(itemstack1, 1, 10, false)) { if (p_39392_ < 37) { if (!this.moveItemStackTo(itemstack1, 37, 46, false)) { return ItemStack.EMPTY; } } else if (!this.moveItemStackTo(itemstack1, 10, 37, false)) { return ItemStack.EMPTY; } } } else if (!this.moveItemStackTo(itemstack1, 10, 46, false)) { return ItemStack.EMPTY; } if (itemstack1.isEmpty()) { slot.set(ItemStack.EMPTY); } else { slot.setChanged(); } if (itemstack1.getCount() == itemstack.getCount()) { return ItemStack.EMPTY; } slot.onTake(p_39391_, itemstack1); if (p_39392_ == 0) { p_39391_.drop(itemstack1, false); } } return itemstack; } @Override public int getContainerSize() { return 9; } @Override public boolean isEmpty() { return craftSlots.isEmpty(); } @Override public ItemStack getItem(int p_18941_) { return craftSlots.getItem(p_18941_); } @Override public ItemStack removeItem(int p_18942_, int p_18943_) { return removeItem(p_18942_, p_18943_); } @Override public ItemStack removeItemNoUpdate(int p_18951_) { return removeItemNoUpdate(p_18951_); } @Override public void setItem(int p_18944_, ItemStack p_18945_) { setItem(p_18944_, p_18945_); } @Override public void setChanged() { setChanged(); } @Override public boolean stillValid(Player p_38874_) { return stillValid(this.access, p_38874_, ModBlocks.TABLE_OF_MAGIC.get()); } @Override public void slotsChanged(Container p_38868_) { this.access.execute((p_39386_, p_39387_) -> { slotChangedCraftingGrid(this, p_39386_, this.player, this.craftSlots, this.resultSlots); }); } protected static void slotChangedCraftingGrid(AbstractContainerMenu p_150547_, Level p_150548_, Player p_150549_, CraftingContainer p_150550_, ResultContainer p_150551_) { if (!p_150548_.isClientSide) { ServerPlayer serverplayer = (ServerPlayer)p_150549_; ItemStack itemstack = ItemStack.EMPTY; Optional<CraftingRecipe> optional = p_150548_.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, p_150550_, p_150548_); if (optional.isPresent()) { CraftingRecipe craftingrecipe = optional.get(); if (p_150551_.setRecipeUsed(p_150548_, serverplayer, craftingrecipe)) { itemstack = craftingrecipe.assemble(p_150550_); } } p_150551_.setItem(0, itemstack); p_150547_.setRemoteSlot(0, itemstack); serverplayer.connection.send(new ClientboundContainerSetSlotPacket(p_150547_.containerId, p_150547_.incrementStateId(), 0, itemstack)); } } @Override public void clearContent() { } } TableOfMagicScreen: public class TableOfMagicScreen extends AbstractContainerScreen<TableOfMagicMenu> { private static final ResourceLocation CRAFTING_TABLE_LOCATION = new ResourceLocation("textures/gui/container/crafting_table.png"); public TableOfMagicScreen(TableOfMagicMenu p_97741_, Inventory p_97742_, Component p_97743_) { super(p_97741_, p_97742_, p_97743_); } @Override protected void renderBg(PoseStack p_97787_, float p_97788_, int p_97789_, int p_97790_) { RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderTexture(0, CRAFTING_TABLE_LOCATION); int i = this.leftPos; int j = (this.height - this.imageHeight) / 2; this.blit(p_97787_, i, j, 0, 0, this.imageWidth, this.imageHeight); } } And I Do Have: @Mod.EventBusSubscriber(modid = MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public static class ClientModEvents { @SubscribeEvent public static void onClientSetup(FMLClientSetupEvent event) { event.enqueueWork(() -> { MenuScreens.register(ModBlockContainers.TABLE_OF_MAGIC.get(), TableOfMagicScreen::new); }); } } But I can't Seem To Make Custom Recipes For My Custom WorkBench (not even vanilla recipes work) Thank You In Advance :)!
  4. I've Made A Mod With Custom Items And Instead Of Letting People Craft Them In The Crafting Table I want To Make My Own Custom Workbench, I'm Using Mostly Just The Crafting Table Code But I'm Struggling To Create Something To Make A Result. Here Is My Code: TableOfMagic: public class TableOfMagic extends Block { private static final Component CONTAINER_TITLE = Component.translatable("container.crafting"); public TableOfMagic(Properties p_49795_) { super(p_49795_); } @Override public InteractionResult use(BlockState p_60503_, Level p_60504_, BlockPos p_60505_, Player p_60506_, InteractionHand p_60507_, BlockHitResult p_60508_) { if (p_60504_.isClientSide) { return InteractionResult.SUCCESS; } else { p_60506_.openMenu(p_60503_.getMenuProvider(p_60504_, p_60505_)); return InteractionResult.CONSUME; } } @Nullable @Override public MenuProvider getMenuProvider(BlockState p_60563_, Level p_60564_, BlockPos p_60565_) { return new SimpleMenuProvider((p_52229_, p_52230_, p_52231_) -> new TableOfMagicMenu(p_52229_, p_52230_), CONTAINER_TITLE); } } TableOfMagicMenu: public class TableOfMagicMenu extends AbstractContainerMenu implements Container { private final ContainerLevelAccess access; private final Player player; private final CraftingContainer craftSlots = new CraftingContainer(this, 3, 3); private final ResultContainer resultSlots = new ResultContainer(); public TableOfMagicMenu(int p_39353_, Inventory p_39354_) { this(p_39353_, p_39354_, ContainerLevelAccess.NULL); } public TableOfMagicMenu(int p_39356_, Inventory p_39357_, ContainerLevelAccess p_39358_) { super(ModBlockContainers.TABLE_OF_MAGIC.get(), p_39356_); this.access = p_39358_; this.player = p_39357_.player; this.addSlot(new ResultSlot(p_39357_.player, this.craftSlots, this.resultSlots, 0, 124, 35)); for(int i = 0; i < 3; ++i) { for(int j = 0; j < 3; ++j) { this.addSlot(new Slot(this.craftSlots, j + i * 3, 30 + j * 18, 17 + i * 18)); } } for(int k = 0; k < 3; ++k) { for(int i1 = 0; i1 < 9; ++i1) { this.addSlot(new Slot(p_39357_, i1 + k * 9 + 9, 8 + i1 * 18, 84 + k * 18)); } } for(int l = 0; l < 9; ++l) { this.addSlot(new Slot(p_39357_, l, 8 + l * 18, 142)); } } @Override public ItemStack quickMoveStack(Player p_39391_, int p_39392_) { ItemStack itemstack = ItemStack.EMPTY; Slot slot = this.slots.get(p_39392_); if (slot != null && slot.hasItem()) { ItemStack itemstack1 = slot.getItem(); itemstack = itemstack1.copy(); if (p_39392_ == 0) { this.access.execute((p_39378_, p_39379_) -> { itemstack1.getItem().onCraftedBy(itemstack1, p_39378_, p_39391_); }); if (!this.moveItemStackTo(itemstack1, 10, 46, true)) { return ItemStack.EMPTY; } slot.onQuickCraft(itemstack1, itemstack); } else if (p_39392_ >= 10 && p_39392_ < 46) { if (!this.moveItemStackTo(itemstack1, 1, 10, false)) { if (p_39392_ < 37) { if (!this.moveItemStackTo(itemstack1, 37, 46, false)) { return ItemStack.EMPTY; } } else if (!this.moveItemStackTo(itemstack1, 10, 37, false)) { return ItemStack.EMPTY; } } } else if (!this.moveItemStackTo(itemstack1, 10, 46, false)) { return ItemStack.EMPTY; } if (itemstack1.isEmpty()) { slot.set(ItemStack.EMPTY); } else { slot.setChanged(); } if (itemstack1.getCount() == itemstack.getCount()) { return ItemStack.EMPTY; } slot.onTake(p_39391_, itemstack1); if (p_39392_ == 0) { p_39391_.drop(itemstack1, false); } } return itemstack; } @Override public int getContainerSize() { return 9; } @Override public boolean isEmpty() { return craftSlots.isEmpty(); } @Override public ItemStack getItem(int p_18941_) { return craftSlots.getItem(p_18941_); } @Override public ItemStack removeItem(int p_18942_, int p_18943_) { return removeItem(p_18942_, p_18943_); } @Override public ItemStack removeItemNoUpdate(int p_18951_) { return removeItemNoUpdate(p_18951_); } @Override public void setItem(int p_18944_, ItemStack p_18945_) { setItem(p_18944_, p_18945_); } @Override public void setChanged() { setChanged(); } @Override public boolean stillValid(Player p_38874_) { return stillValid(this.access, p_38874_, ModBlocks.TABLE_OF_MAGIC.get()); } @Override public void slotsChanged(Container p_38868_) { this.access.execute((p_39386_, p_39387_) -> { slotChangedCraftingGrid(this, p_39386_, this.player, this.craftSlots, this.resultSlots); }); } protected static void slotChangedCraftingGrid(AbstractContainerMenu p_150547_, Level p_150548_, Player p_150549_, CraftingContainer p_150550_, ResultContainer p_150551_) { if (!p_150548_.isClientSide) { ServerPlayer serverplayer = (ServerPlayer)p_150549_; ItemStack itemstack = ItemStack.EMPTY; Optional<CraftingRecipe> optional = p_150548_.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, p_150550_, p_150548_); if (optional.isPresent()) { CraftingRecipe craftingrecipe = optional.get(); if (p_150551_.setRecipeUsed(p_150548_, serverplayer, craftingrecipe)) { itemstack = craftingrecipe.assemble(p_150550_); } } p_150551_.setItem(0, itemstack); p_150547_.setRemoteSlot(0, itemstack); serverplayer.connection.send(new ClientboundContainerSetSlotPacket(p_150547_.containerId, p_150547_.incrementStateId(), 0, itemstack)); } } @Override public void clearContent() { } } TableOfMagicScreen: public class TableOfMagicScreen extends AbstractContainerScreen<TableOfMagicMenu> { private static final ResourceLocation CRAFTING_TABLE_LOCATION = new ResourceLocation("textures/gui/container/crafting_table.png"); public TableOfMagicScreen(TableOfMagicMenu p_97741_, Inventory p_97742_, Component p_97743_) { super(p_97741_, p_97742_, p_97743_); } @Override protected void renderBg(PoseStack p_97787_, float p_97788_, int p_97789_, int p_97790_) { RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderTexture(0, CRAFTING_TABLE_LOCATION); int i = this.leftPos; int j = (this.height - this.imageHeight) / 2; this.blit(p_97787_, i, j, 0, 0, this.imageWidth, this.imageHeight); } } And I Do Have: @Mod.EventBusSubscriber(modid = MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public static class ClientModEvents { @SubscribeEvent public static void onClientSetup(FMLClientSetupEvent event) { event.enqueueWork(() -> { MenuScreens.register(ModBlockContainers.TABLE_OF_MAGIC.get(), TableOfMagicScreen::new); }); } } But I can't Seem To Make Custom Recipes For My Custom WorkBench (not even vanilla recipes work)
  5. Thanks but now it says this when i right click it:
  6. Ok, so I've been working on a gui and I've gotten most of it to work but just as I am finishing an error appeared, Whenever I right click the block instead of showing the gui minecraft crashes. this is the error message: and this is my code: ExampleChestScreen.java: public class ExampleChestScreen extends AbstractContainerScreen<ExampleChestContainer> { private static final ResourceLocation TEXTURE = new ResourceLocation(KnoxiItems.MOD_ID, "textures/gui/magical_workbench_gui.png"); private ExtendedButton beanButton; public ExampleChestScreen(ExampleChestContainer container, Inventory playerInv, Component title) { super(container, playerInv, title); this.leftPos = 0; this.topPos = 0; } @Override public void render(PoseStack stack, int mouseX, int mouseY, float partialTicks) { super.render(stack, mouseX, mouseY, partialTicks); this.font.draw(stack, this.title, this.leftPos + 20, this.topPos + 5, 0x404040); this.font.draw(stack, this.playerInventoryTitle, this.leftPos + 8, this.topPos + 75, 0x404040); } @Override protected void init() { super.init(); this.beanButton = addRenderableWidget( new ExtendedButton(this.leftPos, this.topPos, 16, 16, Component.literal("beans"), btn -> Minecraft.getInstance().player.displayClientMessage(Component.literal("beans"), false))); } @Override protected void renderBg(PoseStack stack, float mouseX, int mouseY, int partialTicks) { renderBackground(stack); RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); RenderSystem.setShaderTexture(0, TEXTURE); blit(stack, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight); } @Override protected void renderLabels(PoseStack stack, int mouseX, int mouseY) { } } ExampleChestBlockEntity.java: public class ExampleChestBlockEntity extends BlockEntity { public static Component TITLE = Component.literal("Example Chest"); IItemHandler inventory; public ExampleChestBlockEntity(BlockPos pos, BlockState state) { super(ModBlockEntities.EXAMPLE_CHEST.get(), pos, state); inventory = new IItemHandler() { private ItemStack[] Inventory = new ItemStack[27]; @Override public int getSlots() { return Inventory.length; } @Override public @NotNull ItemStack getStackInSlot(int slot) { return Inventory[slot]; } @Override public @NotNull ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) { Inventory[slot] = stack; return Inventory[slot]; } @Override public @NotNull ItemStack extractItem(int slot, int amount, boolean simulate) { if (!(amount >= Inventory[slot].getCount())) { Inventory[slot] = new ItemStack(Inventory[slot].getItem(), Inventory[slot].getCount() - amount); } else { Inventory[slot] = null; } return Inventory[slot]; } @Override public int getSlotLimit(int slot) { return 64; } @Override public boolean isItemValid(int slot, @NotNull ItemStack stack) { return true; } }; } } ExampleChestContainer.java: public class ExampleChestContainer extends AbstractContainerMenu { private final ContainerLevelAccess containerAccess; // Client Constructor public ExampleChestContainer(int id, Inventory playerInv) { this(id, playerInv, new ItemStackHandler(27), BlockPos.ZERO); } // Server constructor public ExampleChestContainer(int id, Inventory playerInv, IItemHandler slots, BlockPos pos) { super(ModBlockContainers.EXAMPLE_CHEST.get(), id); this.containerAccess = ContainerLevelAccess.create(playerInv.player.level, pos); final int slotSizePlus2 = 18, startX = 8, startY = 86, hotbarY = 144, inventoryY = 18; for (int row = 0; row < 3; row++) { for (int column = 0; column < 9; column++) { addSlot(new SlotItemHandler(slots, row * 9 + column, startX + column * slotSizePlus2, inventoryY + row * slotSizePlus2)); } } for (int row = 0; row < 3; row++) { for (int column = 0; column < 9; column++) { addSlot(new Slot(playerInv, 9 + row * 9 + column, startX + column * slotSizePlus2, startY + row * slotSizePlus2)); } } for (int column = 0; column < 9; column++) { addSlot(new Slot(playerInv, column, startX + column * slotSizePlus2, hotbarY)); } } @Override public ItemStack quickMoveStack(Player player, int index) { var retStack = ItemStack.EMPTY; final Slot slot = getSlot(index); if (slot.hasItem()) { final ItemStack item = slot.getItem(); retStack = item.copy(); if (index < 27) { if (!moveItemStackTo(item, 27, this.slots.size(), true)) return ItemStack.EMPTY; } else if (!moveItemStackTo(item, 0, 27, false)) return ItemStack.EMPTY; if (item.isEmpty()) { slot.set(ItemStack.EMPTY); } else { slot.setChanged(); } } return retStack; } @Override public boolean stillValid(Player player) { return stillValid(this.containerAccess, player, ModBlocks.EXAMPLE_CHEST.get()); } public static MenuConstructor getServerContainer(ExampleChestBlockEntity chest, BlockPos pos) { return (id, playerInv, player) -> new ExampleChestContainer(id, playerInv, chest.inventory, pos); } } ExampleChestBlock.java: public class ExampleChestBlock extends HorizontalDirectionalBlock implements EntityBlock { public ExampleChestBlock(Properties properties) { super(properties); registerDefaultState(defaultBlockState().setValue(FACING, Direction.NORTH)); } @Override public BlockState getStateForPlacement(BlockPlaceContext context) { return defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()); } /* @Override public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> beType) { //return level.isClientSide ? null // : (level0, pos, state0, blockEntity) -> ((ExampleChestBlockEntity) blockEntity).tick(); return super.defaultBlockState().getTicker(level, beType); }*/ @Nullable @Override public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level p_153212_, BlockState p_153213_, BlockEntityType<T> p_153214_) { return EntityBlock.super.getTicker(p_153212_, p_153213_, p_153214_); } @Override public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { return new ExampleChestBlockEntity(pos, state); } @Override public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult result) { if (!level.isClientSide && level.getBlockEntity(pos) instanceof final ExampleChestBlockEntity chest) { final MenuProvider container = new SimpleMenuProvider(ExampleChestContainer.getServerContainer(chest, pos), ExampleChestBlockEntity.TITLE); NetworkHooks.openScreen((ServerPlayer) player, container, pos); } return InteractionResult.SUCCESS; } @Override protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { super.createBlockStateDefinition(builder); builder.add(FACING); } } Thank you in advance for any help
  7. knoxi

    GUI Help

    Oh I figured it out
  8. knoxi

    GUI Help

    Oh yeah, ty but the MagicalWorkBenchBE::new still throws an error public static final RegistryObject<BlockEntityType<MagicalWorkBenchBE>> MAGICAL_WORKBENCH_BE = BLOCK_ENTITIES.register("magical_workbench", () -> BlockEntityType.Builder.of(MagicalWorkBenchBE::new, ModBlocks.MAGICAL_WORKBENCH.get()).build(null));
  9. knoxi

    GUI Help

    So I'm making a gui and I've found you need: -The ACtual Block -BlockEntity -Container -Client side rendering But when I try to make the block entities (here is my code): public class ModBlockEntities { public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES = DeferredRegister.create( ForgeRegistries.BLOCK_ENTITY_TYPES, KnoxiItems.MOD_ID); public static final RegistryObject<BlockEntityType<MagicalWorkBenchBE>> MAGICAL_WORKBENCH_BE = BLOCK_ENTITIES.register("magical_workbench", () -> BlockEntityType.Builder.of(MagicalWorkBenchBE::new, ModBlocks.MAGICAL_WORKBENCH).build(null));//here } on the line with MagicalWorkBenchBE::new it says I've seen other people do it but creating a supplier by ::new just never works for me
  10. Ok so I have a program where the server has a hashmap storing all of the players mana and every tick it send the data to all players via networking. I'm trying to make an item that when right clicked it uses some of the mana i have stored, in the hashmap I use the ServerPlayer as the key but when I try and cast a regular player to serverplayer: public static boolean useMana(Player _player, float mana) { ServerPlayer player = (ServerPlayer) _player; it throws the error: java.lang.ClassCastException: class net.minecraft.client.player.LocalPlayer cannot be cast to class net.minecraft.server.level.ServerPlayer (net.minecraft.client.player.LocalPlayer and net.minecraft.server.level.ServerPlayer are in module [email protected] of loader 'TRANSFORMER' @3dd31157) thanks in advance for any help
×
×
  • Create New...

Important Information

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