• Recently Browsing

    No registered users viewing this page.

  • Posts

    • Ok, well, easier said than done. 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 ItemStack 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:   package ... import ... public class CauldronTileEntity extends TileEntity { private LazyOptional<IItemHandler> itemHandler = LazyOptional.of(this::createItemHandler); private ArrayList<CauldronRecipe> recipes = CauldronRecipe.getAllCauldronRecipes(); private CauldronRecipe currentRecipe; public CauldronTileEntity() { super(ModRegistry.TileTypes.CAULDRON.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; } }; } public void handleRightClick(PlayerEntity player, Hand hand) { ItemStack stack = player.getHeldItem(hand); if(stack.isEmpty()) { popOutAllItems(); }else { itemHandler.ifPresent(h -> { for(int i = 0; i <= h.getSlots(); i++) { if(h.insertItem(i, stack.split(1), true) != stack.split(1)) { player.setHeldItem(hand, h.insertItem(i, stack.split(1), false)); }else { player.sendStatusMessage(ITextComponent.Serializer.fromJsonLenient("Cauldron Full!"), true); } } }); checkRecipe(); } } private void popOutAllItems() { itemHandler.ifPresent(h -> { ItemEntity[] itemEntities = {}; for(int i = 0; i <= h.getSlots(); i++) { itemEntities[i] = new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), h.getStackInSlot(i)); } for(ItemEntity e : itemEntities) { world.addEntity(e); } }); } private void checkRecipe() { } }   handleRightClick is called from onBlockActivated in the Cauldron's block class.   As you can see, checkRecipe() is empty. I'd like it so that whenever a player changes the items in the inventory, it checks whether it can do a recipe (which is why I call it from handleRightClick). How would I go about it? I've changed the json format to be this instead:   { "type": "labkit:cauldron", "inputs": [ { "item": "minecraft:dirt", "count": 1 }, { "tag": "forge:seeds", "count": 3 } ], "cooking_delay": 50, "output": { "item": "minecraft:grass_block", "count": 1 } }   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.   (Also, I've just tested running the game, and my cauldron doesn't have a tile entity... I'm using DeferredRegister, and I've got these two methods in my block's class: @Override public boolean hasTileEntity(BlockState state) { return true; } @Override public TileEntity createTileEntity(BlockState state, IBlockReader world) { return new CauldronTileEntity(); } which as far as i'm aware, should do the trick...) Thanks!
    • Okay... Just to make sure I got it right: What does reobf do? (Sorry for asking)
    • Well you'll still have the issue of do you want to reobf with build or do you want to reobf with publish?
    • I don't fully understand this, but enough for me to say that I don't want this problem. So you recommend using mavenLocal... I dont know what this is and how I can get it working, but I will try it. And could you please give a few examples or, even better, a guide?
  • Topics

  • Who's Online (See full list)