Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

FossilFind

Members
  • Joined

  • Last visited

  1. I had tried using ContainerData before but I didn't notice addDataSlots in AbstractFurnaceMenu. After adding it to the constructor it worked. Thank you.
  2. I'm making a custom furnace(refinery) and want to sync the BlockEntity data with the client so I can display it on the ContainerScreen. I've tried getUpdatePacket() and onDataPacket() in the BlockEntity and also using a packet. Neither worked. RefineryBlock RefineryBlockEntity RefineryMenu RefineryScreen PacketHandler RefineryUpdatePacket ClientAccess
  3. I've been messing around with Networking and I have no idea what i'm doing.
  4. I change a static variable in the LivingEntity to change the gravity so I'm guessing it's only changing on one side. How would I change it on both sides?
  5. In the PlayerTickEvent I want to test if the player is in my custom moon dimension and change the gravity but nothing I have tried has worked. I noticed that some things I tried would work but when I change dimensions either with /forge command or teleport function, the gravity would be the same as the dimension I came from. When I re logged it worked though.
  6. Could you refer me to a good capabilities tutorial then as I am not familiar with them.
  7. You could use blockstates maybe
  8. I have a canister item that holds 20 buckets of a fluid. It uses FluidStack to hold fluid and amount but when i change the amount on one item all of the instances of the item also change. Item class: public class CanisterItem extends Item { private Supplier<? extends Fluid> supplier; private FluidStack fluid; public CanisterItem(Supplier<? extends Fluid> supplier, Properties builder) { super(builder); this.supplier = supplier; } @Override public void addInformation(ItemStack stack, World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) { if(fluid == null) fluid = new FluidStack(supplier.get(), 20000); if(KeyboardHelper.isHoldingShift()) { tooltip.add(new StringTextComponent(fluid.getAmount() + "mB / 20000mB")); } else { tooltip.add(new StringTextComponent(fluid.getAmount() / 1000 + "B / 20B")); } super.addInformation(stack, worldIn, tooltip, flagIn); } @Override public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) { if(this.getClass() == CanisterItem.class) return new FluidBucketWrapper(stack); else return super.initCapabilities(stack, nbt); } public Supplier<? extends Fluid> getFluid() { return supplier; } public FluidStack getContents() { if(fluid == null) fluid = new FluidStack(supplier.get(), 20000); return fluid; } }
  9. I figured it out: @Override public CompoundNBT getUpdateTag() { return write(new CompoundNBT()); } @Override public void handleUpdateTag(CompoundNBT tag) { read(tag); }
  10. I don't know where you see IInventory and how would I sync my fluid data to the client?
  11. public class ElectrolyzerTileEntity extends LockableLootTileEntity implements ITickableTileEntity { public FluidTank tank1, tank2, tank3, tank4, tank5; public int cookTime, cookTimeTotal; public ElectrolyzerRecipe recipe; private NonNullList<ItemStack> contents = NonNullList.withSize(getSizeInventory(), ItemStack.EMPTY); protected int numPlayersUsing; private IItemHandlerModifiable items = createHandler(); private LazyOptional<IItemHandlerModifiable> itemHandler = LazyOptional.of(() -> items); private LazyOptional<IFluidHandler> tank1Handler = LazyOptional.of(() -> tank1); // private LazyOptional<IFluidHandler> tank2Handler = LazyOptional.of(() -> tank2); // private LazyOptional<IFluidHandler> tank3Handler = LazyOptional.of(() -> tank3); // private LazyOptional<IFluidHandler> tank4Handler = LazyOptional.of(() -> tank4); // private LazyOptional<IFluidHandler> tank5Handler = LazyOptional.of(() -> tank5); public ElectrolyzerTileEntity(TileEntityType<?> type) { super(type); tank1 = new FluidTank(20000); tank2 = new FluidTank(20000); tank3 = new FluidTank(20000); tank4 = new FluidTank(20000); tank5 = new FluidTank(20000); } public ElectrolyzerTileEntity() { this(TileEntityInit.ELECTROLYZER.get()); } @Override public void tick() { if(isIngredient(getStackInSlot(0))) { tank1.fill(new FluidStack(((BucketItem) getStackInSlot(0).getItem()).getFluid(), 20000), FluidAction.EXECUTE); setInventorySlotContents(0, new ItemStack(Items.BUCKET)); } if(isIngredient(tank1.getFluid())) { if(recipe == null) { recipe = getRecipe(tank1.getFluid()); cookTimeTotal = recipe.getCookTime(); cookTime = 0; } if(canCook()) { if(cookTime == cookTimeTotal) { tank1.drain(recipe.getIngredient().getAmount(), FluidAction.EXECUTE); tank2.fill(recipe.getResult1(), FluidAction.EXECUTE); tank3.fill(recipe.getResult2(), FluidAction.EXECUTE); tank4.fill(recipe.getResult3(), FluidAction.EXECUTE); tank5.fill(recipe.getResult4(), FluidAction.EXECUTE); if(recipe.getIngredient().getFluid() == FluidInit.SEAWATER.get()) { if(getStackInSlot(3).isEmpty()) setInventorySlotContents(3, new ItemStack(ItemInit.CAUSTIC_SODA.get(), 0)); getStackInSlot(3).grow(1); } recipe = null; cookTime = 0; } else cookTime++; } else cookTime = 0; } else cookTime = 0; SpaceMod.LOGGER.info(tank1.getFluid().getFluid() + " : " + tank1.getFluid().getAmount()); } @Override public int getSizeInventory() { return 5; } @Override public NonNullList<ItemStack> getItems() { return contents; } @Override protected void setItems(NonNullList<ItemStack> items) { contents = items; } @Override protected ITextComponent getDefaultName() { return new TranslationTextComponent("container.space.electrolyzer"); } @Override protected Container createMenu(int id, PlayerInventory player) { return new ElectrolyzerContainer(id, player, this); } @Override public CompoundNBT write(CompoundNBT compound) { compound.putInt("cookTime", cookTime); compound.putInt("cookTimeTotal", cookTimeTotal); compound.put("tank1", tank1.writeToNBT(new CompoundNBT())); // compound.put("tank2", tank2.writeToNBT(compound)); // compound.put("tank3", tank3.writeToNBT(compound)); // compound.put("tank4", tank4.writeToNBT(compound)); // compound.put("tank5", tank5.writeToNBT(compound)); if(!checkLootAndWrite(compound)) ItemStackHelper.saveAllItems(compound, contents); return super.write(compound); } @Override public void read(CompoundNBT compound) { super.read(compound); cookTime = compound.getInt("cookTime"); cookTimeTotal = compound.getInt("cookTimeTotal"); tank1.readFromNBT(compound.getCompound("tank1")); // tank2.readFromNBT(compound.getCompound("tank2")); // tank3.readFromNBT(compound.getCompound("tank3")); // tank4.readFromNBT(compound.getCompound("tank4")); // tank5.readFromNBT(compound.getCompound("tank5")); contents = NonNullList.withSize(getSizeInventory(), ItemStack.EMPTY); if(!checkLootAndRead(compound)) ItemStackHelper.loadAllItems(compound, contents); } @Override public boolean receiveClientEvent(int id, int type) { if(id == 1) { numPlayersUsing = type; return true; } return super.receiveClientEvent(id, type); } @Override public void openInventory(PlayerEntity player) { if(!player.isSpectator()) { if(numPlayersUsing < 0) numPlayersUsing = 0; numPlayersUsing++; onOpenOrClose(); } } @Override public void closeInventory(PlayerEntity player) { if(!player.isSpectator()) { numPlayersUsing++; onOpenOrClose(); } } protected void onOpenOrClose() { Block block = getBlockState().getBlock(); if(block instanceof ElectrolyzerBlock) { world.addBlockEvent(pos, block, 1, numPlayersUsing); world.notifyNeighborsOfStateChange(pos, block); } } public static int getPlayersUsing(IBlockReader reader, BlockPos pos) { if(reader.getBlockState(pos).hasTileEntity()) { TileEntity te = reader.getTileEntity(pos); if(te instanceof ElectrolyzerTileEntity) return ((ElectrolyzerTileEntity) te).numPlayersUsing; } return 0; } public static void swapContents(ElectrolyzerTileEntity te, ElectrolyzerTileEntity otherTe) { NonNullList<ItemStack> list = te.getItems(); te.setItems(otherTe.getItems()); otherTe.setItems(list); } @Override public void updateContainingBlockInfo() { super.updateContainingBlockInfo(); if(itemHandler != null) { itemHandler.invalidate(); itemHandler = null; } // if(tank1Handler != null) // { // tank1Handler.invalidate(); // tank1Handler = null; // } } @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nonnull Direction side) { if(cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return itemHandler.cast(); // if(cap == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) return tank1Handler.cast(); // if(cap == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY && side == Direction.NORTH) return tank2Handler.cast(); // if(cap == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY && side == Direction.EAST) return tank3Handler.cast(); // if(cap == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY && side == Direction.SOUTH) return tank4Handler.cast(); // if(cap == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY && side == Direction.WEST) return tank5Handler.cast(); return super.getCapability(cap); } private IItemHandlerModifiable createHandler() { return new InvWrapper(this); } @Override public void remove() { super.remove(); if(itemHandler != null) itemHandler.invalidate(); // if(tank1Handler != null) tank1Handler.invalidate(); } private boolean isIngredient(FluidStack stack) { if(stack.getFluid() == Fluids.WATER) return true; if(stack.getFluid() == FluidInit.SEAWATER.get()) return true; return false; } public boolean isIngredient(ItemStack stack) { if(stack.getItem() == Items.WATER_BUCKET) return true; if(stack.getItem() == ItemInit.SEAWATER_BUCKET.get()) return true; return false; } private boolean canCook() { boolean isPowered = true; if(isPowered) { return tank1.getCapacity() >= recipe.getIngredient().getAmount() && (tank2.isEmpty() || (tank2.getFluid().getFluid() == recipe.getResult1().getFluid() && tank2.getCapacity() + recipe.getResult1().getAmount() <= 20000)) && (tank3.isEmpty() || (tank3.getFluid().getFluid() == recipe.getResult2().getFluid() && tank3.getCapacity() + recipe.getResult2().getAmount() <= 20000)) && (tank4.isEmpty() || (tank4.getFluid().getFluid() == recipe.getResult3().getFluid() && tank4.getCapacity() + recipe.getResult3().getAmount() <= 20000)) && (tank5.isEmpty() || (tank5.getFluid().getFluid() == recipe.getResult4().getFluid() && tank5.getCapacity() + recipe.getResult4().getAmount() <= 20000)) && recipe.getIngredient().getFluid() == FluidInit.SEAWATER.get() ? ((getStackInSlot(3).getItem() == ItemInit.CAUSTIC_SODA.get() && getStackInSlot(3).getCount() <= 63) || getStackInSlot(3).isEmpty()) : true; } return false; } private ElectrolyzerRecipe getRecipe(FluidStack ingredient) { if(ingredient.getFluid() == Fluids.WATER) return new ElectrolyzerRecipe(60, new FluidStack(Fluids.WATER, 1000), new FluidStack(FluidInit.HYDROGEN.get(), 500), new FluidStack(FluidInit.OXYGEN.get(), 250), FluidStack.EMPTY, FluidStack.EMPTY); if(ingredient.getFluid() == FluidInit.SEAWATER.get()) return new ElectrolyzerRecipe(60, new FluidStack(FluidInit.SEAWATER.get(), 1000), new FluidStack(FluidInit.HYDROGEN.get(), 500), new FluidStack(FluidInit.CHLORINE.get(), 500), FluidStack.EMPTY, FluidStack.EMPTY); return null; } public FluidTank getTank(int index) { switch(index) { case 1: return tank1; case 2: return tank2; case 3: return tank3; case 4: return tank4; case 5: return tank5; default: return tank1; } } }
  12. I'm sorry I was confused. I made a separate one. But it still says that there is only fluid on the Server thread and not the Render thread.
  13. How do I make another one?
  14. @Override public CompoundNBT write(CompoundNBT compound) { compound.putInt("cookTime", cookTime); compound.putInt("cookTimeTotal", cookTimeTotal); compound.put("tank1", tank1.writeToNBT(compound)); if(!checkLootAndWrite(compound)) ItemStackHelper.saveAllItems(compound, contents); return super.write(compound); } @Override public void read(CompoundNBT compound) { super.read(compound); cookTime = compound.getInt("cookTime"); cookTimeTotal = compound.getInt("cookTimeTotal"); tank1.readFromNBT(compound.getCompound("tank1")); contents = NonNullList.withSize(getSizeInventory(), ItemStack.EMPTY); if(!checkLootAndRead(compound)) ItemStackHelper.loadAllItems(compound, contents); }
  15. But then I get the infinite recursion

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.