• Recently Browsing

    No registered users viewing this page.

  • Posts

    • So recently I have been trying to make a block which has multiple pages of slots, and getting to the next page and going back a page will just be a simple click of a button. However I am experiencing some issues where the slot index will be out of bounds. So from what I can tell(its quite hard to see whats actually happening), I am able to go from Page 1(first page) to Page 2 perfectly fine, and visa versa. However if I then try to go to Page 3, I get an error and the game crashes with an ArrayOutOfBoundsException. However, if I close the GUI, then re-open it, and go from Page 2 to Page 3 it works fine. Here is my code for switching pages:  public void onRecieved(Supplier<NetworkEvent.Context> context) { context.get().enqueueWork(() -> { if (context.get().getSender().openContainer instanceof SiloContainer) { SiloContainer container = (SiloContainer) context.get().getSender().openContainer; if (this.option == 0) { int index = 36; container.currentPage.set(container.currentPage.get() - 1); for (Slot slot : container.inventorySlots) { System.out.println("index: " + (slot.getSlotIndex() - (104 * container.currentPage.get()))); if (slot instanceof SlotItemHandler) { container.inventorySlots.set(index, new SlotItemHandler( container.tileEntity.getHandler().orElse(container.tileEntity.createHandler()), ((SlotItemHandler) slot).getSlotIndex() - (104 * container.currentPage.get()), ((SlotItemHandler) slot).xPos, ((SlotItemHandler) slot).yPos)); index++; } } container.detectAndSendChanges(); } else if (this.option == 1) { int index = 36; container.currentPage.set(container.currentPage.get() + 1); for (Slot slot : container.inventorySlots) { System.out.println("index: " + (slot.getSlotIndex() + (104 * container.currentPage.get()))); if (slot instanceof SlotItemHandler) { container.inventorySlots.set(index, new SlotItemHandler( container.tileEntity.getHandler().orElse(container.tileEntity.createHandler()), ((SlotItemHandler) slot).getSlotIndex() + (104 * container.currentPage.get()), ((SlotItemHandler) slot).xPos, ((SlotItemHandler) slot).yPos)); index++; } } container.detectAndSendChanges(); } } }); context.get().setPacketHandled(true); } I have been trying to figure this out for hours(over the course of many days) so forgive me if something I am doing here is horribly stupid. This is also my 9th or 10th rewrite of the code, so yea, I'm starting to get very tired with this xD. Note: I have been trying to figure this out for hours(over the course of many days) so forgive me if something I am doing here is horribly stupid. This is also my 9th or 10th rewrite of the code, so yea, I'm starting to get very tired with this xD. Also, I should note, there are 5 pages, and 104 slots per page(so the ItemHandler has a size of 520).  Here is the latest log(which includes the crash): https://hatebin.com/krsedhysky And here is a video of what i did to produce this crash(it crashed when the video ends): Also, ignore the fact that the page number doesn't update correctly, I know why, I just haven't got around to fixing it yet.    If there is any other code you need to see, just ask and I will send, cause I'm not really sure what other code would be relevant.   In advance, many thanks. TurtyWurty.
    • Hi, I have a weird issue, I dont know why but when I hold left click with a Gun Item(to aim) in the main hand, looking at grass, flowers, or torches, the player gets stuck and cant move until I stop holding left click or stop looking at the grass, flower, torch, etc,....    How could I fix this? I think i've checked all the methods from the Gun class and all the events that relate to this issue, but none is making this happen.   PD: in creative mode it has a different, it just causes the player movement to lag, and its triggered by holding left click with any block.   Here's the repo:    Gun class   Footage:  
    • So I just created a custom purple campfire. I have a few problems I've registered the block (Code attached to the bottom). But for some reason it doesn't act like a campfire at all.   The problems are that there is: no smoke no recipes working (the items stay raw) the inputted items don't render on the block the campfire doesn't re-light (with flint and steel) after it is put out   public static final RegistryObject<Block> PURPLE_CAMPFIRE = BLOCKS.register("purple_campfire", () -> new CampfireBlock(false, 3, AbstractBlock.Properties.create(Material.WOOD, MaterialColor.OBSIDIAN) .hardnessAndResistance(2.0F) .sound(SoundType.WOOD) .setLightLevel(getLightValueLit(10)) .notSolid())); private static ToIntFunction<BlockState> getLightValueLit(int lightValue) { return (block) -> { return block.get(BlockStateProperties.LIT) ? lightValue : 0; }; }  
    • There's no ready to do this, you can just call CauldronRecipe.getAllCauldronRecipes() any time you need them. If you just want a shorthand, make recipes static. This is unused.   "For all required ingredients: If the stack in slot 0 is not the ingredient: Recipe is not matched."   Uh...
    • So I'm trying to create a new crafting block. I've already got the recipe, the serialiser, etc. I've taken a look different crafting blocks in vanilla's code (mostly AbstractFunaceTileEntity, as the other blocks are done without a tile), and I keep writing code, getting stuck, then rewriting it, over and over. How would I go about making this work? I have a custom cauldron block, and I want a player to right-click it to add one of the items in the stack they're holding to the tile's inventory, or if they're holding nothing then drop all the items in the inventory. Here's my code so far:   Block: public class LabKauldron extends Block { public LabKauldron() { super(Block.Properties.from(Blocks.CAULDRON) .lootFrom(Blocks.CAULDRON) ); } @Override public BlockRenderLayer getRenderLayer() { return BlockRenderLayer.CUTOUT; } @Override public boolean hasTileEntity(BlockState state) { return true; } @Override public TileEntity createTileEntity(BlockState state, IBlockReader world) { return new LabKauldronTileEntity(); } @Override public boolean onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) { TileEntity tile = world.getTileEntity(pos); //Do something with the tile } }   Tile: public class LabKauldronTileEntity extends TileEntity { private LazyOptional<IItemHandler> itemHandler = LazyOptional.of(this::createItemHandler); private ArrayList<CauldronRecipe> recipes = CauldronRecipe.getAllCauldronRecipes(); private CauldronRecipe currentRecipe; public LabKauldronTileEntity() { super(ModRegistry.TileTypes.LABKAULDRON.get()); } @Override @SuppressWarnings("unchecked") public void read(CompoundNBT tag) { CompoundNBT invTag = tag.getCompound("inv"); itemHandler.ifPresent(h -> ((INBTSerializable<CompoundNBT>) h).deserializeNBT(invTag)); super.read(tag); } @Override @SuppressWarnings("unchecked") public CompoundNBT write(CompoundNBT tag) { itemHandler.ifPresent(h -> { CompoundNBT compound = ((INBTSerializable<CompoundNBT>) h).serializeNBT(); tag.put("inv", compound); }); return super.write(tag); } private IItemHandler createItemHandler() { return new ItemStackHandler(50) { @Override protected void onContentsChanged(int slot) { markDirty(); } @Override public boolean isItemValid(int slot, @Nonnull ItemStack stack) { return true; } }; } }   CauldronRecipe: public class CauldronRecipe implements ICauldronRecipe { private ResourceLocation id; private ItemStack output; private int cookingDelay; private Ingredient[] ingredients; public CauldronRecipe(ResourceLocation id, ItemStack output, int cookingDelay, Ingredient... ingredients) { this.id = id; this.output = output; this.cookingDelay = cookingDelay; this.ingredients = ingredients; } public ItemStack getIcon() { return new ItemStack(Blocks.CAULDRON); } public IRecipeSerializer<?> getSerializer() { return ModRegistry.RecipeSerializers.CAULDRON_RECIPE.get(); } @Override public boolean matches(RecipeWrapper inv, World world) { for(Ingredient ingredient : ingredients) { if(ingredient.test(inv.getStackInSlot(0)) == false) { return false; } } return true; } @Override public ItemStack getCraftingResult(RecipeWrapper inv) { return output; } @Override public ItemStack getRecipeOutput() { return output; } @Override public ResourceLocation getId() { return id; } @Override public Ingredient[] getInputs() { return ingredients; } @Override public int getCookingDelay() { return cookingDelay; } @Override public NonNullList<Ingredient> getIngredients() { return NonNullList.from(null, getInputs()); } public static ArrayList<CauldronRecipe> getAllCauldronRecipes() { ArrayList<CauldronRecipe> recipeList = new ArrayList<CauldronRecipe>(); RecipeManager rm = new RecipeManager(); for (IRecipe<?> r : rm.getRecipes()) { if(r.getType() == ModRecipeTypes.CAULDRON) { recipeList.add((CauldronRecipe) r); } } return recipeList; } }   Also, here's the json file for an example recipe: { "type": "labkit:cauldron", "inputs": [ { "item": "minecraft:dirt", "count": 1 }, { "tag": "forge:seeds", "count": 3 } ], "cooking_delay": 50, "output": { "item": "minecraft:grass_block", "count": 1 } } This all gets parsed correctly, it's just for reference The order of the inputs doesn't matter to me, I'd just like to know how to check if they equal a recipe's ingredients. Thanks!
  • Topics

  • Who's Online (See full list)