Jump to content

kiou.23

Members
  • Posts

    444
  • Joined

  • Last visited

  • Days Won

    5

Everything posted by kiou.23

  1. Just a little something here: 1- You should call NetworkHooks.openGui() instead of player.openContainer. 2- I don't think you should call player.addStat(Stats.INTERACT_WITH_CRAFTING_TABLE), since the player is interacting with your custom crafting table, not a vanilla one
  2. you'll also need to register the screen for the container using ScreenManager.registerFactory in the Client setup. you should enqueue the registration tho. the client setup event provides a enqueueWork method that you can use for this
  3. totally forgot that canInteractWith takes the block, yeah I guess you can make a new class that extends WorkbenchContainer, and then override the canInteractWith method then in your Crafting Table Block class you can override the getContainer method to return a SimpleNamedContainerProvider that returns your container instead of the vanilla one
  4. 1- why did you make the same topic twice? 2- if you're having trouble while making a mod your topic should go under the Modder Support section 3- 1.12 is no longer supported on this forum, please update to a modern version of minecraft
  5. can't you just do the same thing you're doing for the x, y and z fields?
  6. in the drawGuiContainerBackgroundLayer method you need to call blit() after binding the texture to actually draw it to the screen. Binding the texture simply sends the image to the gpu, but doesn't draw it. in the drawGuiContainerForegroundLayer you don't need to draw the title, calling the method on super already does that. super.drawGuiContainerForegroundLayer draws both the inventory title and the player inventory title
  7. @Override public void read(CompoundNBT compound) { super.read(compound); CompoundNBT initValues = compound.getCompound("initvalues"); if(initValues != null) { this.x = initValues.getInt("x"); this.y = initValues.getInt("y"); this.z = initValues.getInt("z"); this.tick = 0; initialized = true; return; } init(); } You are hard setting the tick field to 0 every time your tileEntity reads the saved NBT data
  8. yeah, just spent 5 hours in solving the crafting table logic. It's working perfectly now, may not be the best way to implement, and later I'll come back and try to simplify the code, but so far this is it: (The behaviour is the same as the vanilla workbench except it keeps the items in as it is a tile entity) Tile entity public class ModWorkbenchTileEntity extends TileEntity implements INamedContainerProvider, ICraftingTE { public static final int CRAFT_MATRIX_SLOT_START = 0; public static final int CRAFT_MATRIX_SLOT_END = 8; public static final int OUTPUT_SLOT = 9; public final ItemStackHandler inventory = new ItemStackHandler(10) { @Override protected void onContentsChanged(int slot) { super.onContentsChanged(slot); switch (slot) { case OUTPUT_SLOT: break; default: updateInventory(); } } }; private ModWorkbenchInventory getCraftingInventory() { ItemStackHandler craftMatrix = new ItemStackHandler(9); for (int _slot = CRAFT_MATRIX_SLOT_START; _slot <= CRAFT_MATRIX_SLOT_END; _slot++) craftMatrix.setStackInSlot(_slot, inventory.getStackInSlot(_slot)); return new ModWorkbenchInventory(craftMatrix); } public ModWorkbenchTileEntity() { super(ModTileEntityTypes.MOD_WORKBENCH.get()); } private ItemStack getRecipeResult() { return world.getRecipeManager().getRecipe( IRecipeType.CRAFTING, getCraftingInventory(), world ).map(recipe -> recipe.getCraftingResult(getCraftingInventory())).orElse(ItemStack.EMPTY); } private void updateInventory() { ItemStack resultStack = getRecipeResult(); if (inventory.getStackInSlot(OUTPUT_SLOT) == resultStack) return; inventory.setStackInSlot(OUTPUT_SLOT, resultStack); } private void shrinkStackInSlot(int slot) { ItemStack slotStack = inventory.getStackInSlot(slot); ItemStack container = slotStack.hasContainerItem() ? slotStack.getContainerItem() : ItemStack.EMPTY; slotStack.shrink(1); if (inventory.getStackInSlot(slot).isEmpty() && !container.isEmpty()) inventory.setStackInSlot(slot, container); } @Override public void onCraft() { for (int _slot = CRAFT_MATRIX_SLOT_START; _slot <= CRAFT_MATRIX_SLOT_END; _slot++) shrinkStackInSlot(_slot); ItemStack resultStack = getRecipeResult(); if (inventory.getStackInSlot(OUTPUT_SLOT) != resultStack) inventory.setStackInSlot(OUTPUT_SLOT, resultStack); } public ItemStack onCraftMany(PlayerInventory playerInv) { ItemStack output = inventory.getStackInSlot(OUTPUT_SLOT); int amount = 64; for (int _slot = CRAFT_MATRIX_SLOT_START; _slot <= CRAFT_MATRIX_SLOT_END; _slot++){ ItemStack stack = inventory.getStackInSlot(_slot); if (stack.isEmpty()) continue; amount = amount > stack.getCount() ? stack.getCount() : amount; } for(int i = 0; i < amount; i++) { if (!playerInv.addItemStackToInventory(output)) return inventory.getStackInSlot(OUTPUT_SLOT); for (int _slot = CRAFT_MATRIX_SLOT_START; _slot <= CRAFT_MATRIX_SLOT_END; _slot++) shrinkStackInSlot(_slot); updateInventory(); } return ItemStack.EMPTY; } @Override public ITextComponent getDisplayName() { return new TranslationTextComponent(ModBlocks.MOD_WORKBENCH.get().getTranslationKey()); } @Override public Container createMenu(int windowId, PlayerInventory playerInv, PlayerEntity player) { return new ModWorkbenchContainer(windowId, playerInv, this); } } Container public class ModWorkbenchContainer extends Container { public final ModWorkbenchTileEntity tileEntity; private final IWorldPosCallable canInteractWithCallable; public ModWorkbenchContainer(final int windowId, PlayerInventory playerInv, final PacketBuffer data) { this(windowId, playerInv, (ModWorkbenchTileEntity)playerInv.player.world.getTileEntity(data.readBlockPos())); } public ModWorkbenchContainer(final int windowId, PlayerInventory playerInventory, ModWorkbenchTileEntity tileEntity) { super(ModContainerTypes.MOD_WORKBENCH.get(), windowId); this.tileEntity = tileEntity; this.canInteractWithCallable = IWorldPosCallable.of(tileEntity.getWorld(), tileEntity.getPos()); final int slotSizePlus2 = 18; //Craft Matrix final int craftMatStartX = 30; final int craftMatStartY = 17; for (int row = 0; row < 3; row++) for (int column = 0; column < 3; column++) this.addSlot(new SlotItemHandler(tileEntity.inventory, row * 3 + column, craftMatStartX + column * slotSizePlus2, craftMatStartY + row * slotSizePlus2 )); //Output Slot this.addSlot(new ClosedSlotItemHandler(tileEntity.inventory, 9, 124, 35, tileEntity)); //Player Inventory final int playerInvStartX = 8; final int playerInvStartY = 84; for (int row = 0; row < 3; row++) for (int column = 0; column < 9; column++) this.addSlot(new Slot(playerInventory, 9 + (row * 9) + column, playerInvStartX + (column * slotSizePlus2), playerInvStartY + (row * slotSizePlus2) )); final int playerHotbarY = playerInvStartY + slotSizePlus2 * 3 + 4; for (int column = 0; column < 9; column++) this.addSlot(new Slot(playerInventory, column, playerInvStartX + (column * slotSizePlus2), playerHotbarY )); } @Override public boolean canInteractWith(PlayerEntity player) { return isWithinUsableDistance(canInteractWithCallable, player, ModBlocks.MOD_WORKBENCH.get()); } @Override public ItemStack transferStackInSlot(PlayerEntity player, int index) { ItemStack stack = ItemStack.EMPTY; Slot slot = this.inventorySlots.get(index); if (slot == null || !slot.getHasStack()) return stack; ItemStack slotStack = slot.getStack(); stack = slotStack.copy(); if (index >= tileEntity.inventory.getSlots()) { if (!mergeItemStack(slotStack, 0, tileEntity.inventory.getSlots() - 1, false)) return ItemStack.EMPTY; } else if (index == tileEntity.OUTPUT_SLOT) { return tileEntity.onCraftMany(player.inventory); } else { if (!mergeItemStack(slotStack, tileEntity.inventory.getSlots(), inventorySlots.size(), false)) return ItemStack.EMPTY; } if (slotStack.isEmpty()) slot.putStack(ItemStack.EMPTY); else slot.onSlotChanged(); return stack; } } Edit: ICraftingTE is an interface so that I can pass the TileEntity to the Slot in the container and have the Slot handle the code for whenever an Item is taken out of it (As I couldn't assume the player had taken the recipe output if the slot changed to Empty since it could also be the crafting matrix being changed to an invalid recipe) I tried had that, but whenever getting the recipe it would act weird, I suppose because of the Output slot is also in the "inventory" for instance: if I placed a block of iron in the crafting matrix, the result slot would update correctly to be 9 iron ingots. however, if I removed the iron block from the crafting matrix and left it empty, the result slot would update to be 9 iron nuggets. There's definetely a better way of getting the crafting inventory to pass to the recipe manager, but this is it worked and I wanted to have it working before I polished the code
  9. I didn't just gave him the code, I told him Minecraft and forge are built on Java and that he needs to learn it if he wishes to proceed in modding, I also pointed him towards a very good and short Java introduction for programming beginners why is that? I only used it because the class I looked for reference, the vanilla LayerRenderer classes, uses it
  10. if all you want is the code for that, here it is: @OnlyIn(Dist.CLIENT) public class FurnaceHeadLayer extends LayerRenderer<PlayerEntity, PlayerModel<PlayerEntity>> { public FurnaceHeadLayer(PlayerRenderer entityRendererIn) { super((IEntityRenderer)entityRendererIn); } @Override public void render(MatrixStack matrixStack, IRenderTypeBuffer buffer, int packedLightIn, PlayerEntity entitylivingbaseIn, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) { if (entitylivingbaseIn.isInvisible()) return; matrixStack.push(); this.getEntityModel().getModelHead().translateRotate(matrixStack); float f = 0.625F; matrixStack.translate(0.0D, -0.34375D, 0.0D); matrixStack.rotate(Vector3f.YP.rotationDegrees(180.0F)); matrixStack.scale(0.625F, -0.625F, -0.625F); ItemStack itemstack = new ItemStack(Blocks.FURNACE); Minecraft.getInstance().getItemRenderer().renderItem(entitylivingbaseIn, itemstack, ItemCameraTransforms.TransformType.HEAD, false, matrixStack, buffer, entitylivingbaseIn.world, packedLightIn, LivingRenderer.getPackedOverlay(entitylivingbaseIn, 0.0F)); matrixStack.pop(); } } @SubscribeEvent public void renderPlayerEvent(final RenderPlayerEvent event) { PlayerRenderer renderer = event.getRenderer(); LayerRenderer layer = new FurnaceHeadLayer(renderer); renderer.addLayer(layer); } This will render a furnace in the head of every player But again: Minecraft (and Forge) is built on top of Java. Java is a programming language, it can do a lot of things, and it is required knowledge if you want to make mods with Forge you'll constantly get stuck without being able to implement features of your own without searching for help if you don't know Java so I suggest that you later study about Java Programming, and Object Oriented Programming
  11. watch at your own pace but the problem you're having is that you don't know the basics of programming in Java, the only thing that can help with that really is to watch a course on the language
  12. Here, watch this
  13. ? I've already told you create a class that extends LayerRenderer<AbstractClientPlayerEntity, PlayerModel<AbstractClientPlayerEntity>> then override the render method, and what you want to do in the render method is very similar to what the SnowmanHeadLayer does next, in the RenderPlayerEvent handler you can create an instance of this LayerRenderer (PlayerHatLayer for instance), and add it to the Player Renderer in the event handler you can get the Player Renderer by calling event.getRenderer() and you can add a layer by calling addLayer() on the Player Renderer if you try it you will see if it works or not and if you want help if the troubles you're having you should say what the troubles are
  14. oh, my bad then, should've read the docs that actaully explains why an event handler I had in a class wasn't being called, thanks
  15. if you're using the @SubscribeEvent annotation the method shouldn't be static right?
  16. yeah, try it and see if it works you may also need to tweak the values in translate, rotate and scale to manage to place it properly
  17. you want the SnowmanHeadLayer, not the SnowManRender
  18. just public void if you're on IntelliJ you can click on the search button in the top-right, type the class you want to find, and then just open it
  19. the method shouldn't be static
  20. ... you literally just copy and paste
  21. take a look at the render method of the SnowmanHeadLayer class, it should have everything that you need (honestly you can probably just copy paste that method and change the Carved Pumpkin to be your block)
  22. actually, you may want to subscribe to the RenderPlayerEvent, get the player Renderer form the event and use PlayerRenderer#addLayer() I havent' done much rendering code, so I'm not that sure Edit: yeah, you want to create a class that extends LayerRenderer, and override the render method to render your hat. you then pass an instance of your LayerRenderer to the PlayerRenderer#addLayer()
×
×
  • Create New...

Important Information

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