From d5193d2a86e3db0f50fec36334c335f515983e3f Mon Sep 17 00:00:00 2001 From: gazotti Date: Tue, 20 Apr 2021 09:24:10 -0300 Subject: [PATCH] Added Mekanism support! The boiler is now capable of outputting Mekanism Steam when prompted to do so by a gas extracting device (such as a Pressurized Tube set to pull). I've yet to add support for inputting gas as fuel, though. --- .classpath | 30 +- build.gradle | 18 +- gradle/wrapper/gradle-wrapper.properties | 1 + runClient.launch | 35 +- runData.launch | 29 +- runServer.launch | 29 +- src/main/java/gazcreations/borkler/Index.java | 2 +- .../borkler/blocks/BorklerBlock.java | 86 +++-- .../borkler/blocks/BorklerTileEntity.java | 340 ++++++++---------- .../borkler/client/screen/BorklerScreen.java | 44 ++- .../borkler/compat/MekaBorkler.java | 174 +++++++++ .../compat/jei/BorklerFluidFuelCategory.java | 2 +- .../compat/jei/BorklerFuelCategory.java | 2 +- .../borkler/compat/jei/JustEnoughBork.java | 5 +- .../borkler/container/BorklerContainer.java | 65 ++-- .../gazcreations/borkler/fluids/Steam.java | 41 +-- .../borkler/fluids/SteamBlock.java | 4 +- .../borkler/items/BorklerItem.java | 2 +- .../gazcreations/borkler/items/SteamItem.java | 2 +- .../borkler/network/BorklerData.java | 4 +- .../borkler/proxy/ClientProxy.java | 2 +- .../borkler/recipes/BorklerFuel.java | 13 +- .../recipes/BorklerFuelSerializer.java | 6 +- src/main/resources/META-INF/mods.toml | 2 +- 24 files changed, 547 insertions(+), 391 deletions(-) create mode 100644 src/main/java/gazcreations/borkler/compat/MekaBorkler.java diff --git a/.classpath b/.classpath index 3028944..5763fcb 100644 --- a/.classpath +++ b/.classpath @@ -2,22 +2,40 @@ - + - + - + + + + + + + + + + + + + + + + + + + + + + - - - diff --git a/build.gradle b/build.gradle index 7e68c93..fd8740c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ buildscript { repositories { maven { url = 'https://files.minecraftforge.net/maven' } + maven { url = 'https://modmaven.dev' } jcenter() mavenCentral() } @@ -28,6 +29,8 @@ repositories { name = "ModMaven" url = "https://modmaven.k-4u.nl" } + //Mekanism + } dependencies { @@ -37,7 +40,12 @@ dependencies { compileOnly fg.deobf("mezz.jei:jei-1.16.5:7.6.1.75:api") // at runtime, use the full JEI jar runtimeOnly fg.deobf("mezz.jei:jei-1.16.5:7.6.1.75") - + //mekanism + compileOnly fg.deobf("mekanism:Mekanism:1.16.5-10.0.21.448:api") + compile fg.deobf("mekanism:Mekanism:1.16.5-10.0.21.448") + runtimeOnly fg.deobf("mekanism:Mekanism:1.16.5-10.0.21.448") + runtimeOnly fg.deobf("mekanism:Mekanism:1.16.5-10.0.21.448:additions") + runtimeOnly fg.deobf("mekanism:Mekanism:1.16.5-10.0.21.448:generators") } version = '1.0' @@ -53,7 +61,7 @@ minecraft { // stable_# Stables are built at the discretion of the MCP team. // Use non-default mappings at your own risk. they may not always work. // Simply re-run your setup task after changing the mappings to update your workspace. - mappings channel: 'snapshot', version: '20201028-1.16.3' + mappings channel: 'official', version: '1.16.5' // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') @@ -139,7 +147,7 @@ dependencies { // Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed // that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied. // The userdev artifact is a special name and will get all sorts of transformations applied to it. - minecraft 'net.minecraftforge:forge:1.16.5-36.0.43' + minecraft 'net.minecraftforge:forge:1.16.5-36.1.0' // You may put jars on which you depend on in ./libs or you may define them like so.. // compile "some.group:artifact:version:classifier" @@ -167,9 +175,9 @@ jar { attributes([ "Specification-Title": "borkler", "Specification-Vendor": "gazcreations", - "Specification-Version": "0.2.2", // We are version 1 of ourselves + "Specification-Version": "0.2.3", "Implementation-Title": "borkler", - "Implementation-Version": "0.2.2", + "Implementation-Version": "0.2.3", "Implementation-Vendor" :"gazcreations", "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") ]) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1d5b29f..f420eae 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,3 +3,4 @@ distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip + diff --git a/runClient.launch b/runClient.launch index c137317..b174bf4 100644 --- a/runClient.launch +++ b/runClient.launch @@ -1,20 +1,21 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/runData.launch b/runData.launch index 72e2ded..6dacdbc 100644 --- a/runData.launch +++ b/runData.launch @@ -1,17 +1,18 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/runServer.launch b/runServer.launch index dc51c43..ea1c7da 100644 --- a/runServer.launch +++ b/runServer.launch @@ -1,17 +1,18 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/src/main/java/gazcreations/borkler/Index.java b/src/main/java/gazcreations/borkler/Index.java index 11694ab..5bcad8f 100755 --- a/src/main/java/gazcreations/borkler/Index.java +++ b/src/main/java/gazcreations/borkler/Index.java @@ -67,7 +67,7 @@ public static final class Items { @ObjectHolder(value = "borkler:borklertile") public static final TileEntityType BORKLER_TE_TYPE = TileEntityType.Builder - .create(BorklerTileEntity::new, Index.Blocks.BORKLERBLOCK).build(null) + .of(BorklerTileEntity::new, Index.Blocks.BORKLERBLOCK).build(null) .setRegistryName("borkler", "borklertile"); @SuppressWarnings("unchecked") diff --git a/src/main/java/gazcreations/borkler/blocks/BorklerBlock.java b/src/main/java/gazcreations/borkler/blocks/BorklerBlock.java index e742c54..67c9963 100755 --- a/src/main/java/gazcreations/borkler/blocks/BorklerBlock.java +++ b/src/main/java/gazcreations/borkler/blocks/BorklerBlock.java @@ -27,7 +27,6 @@ import net.minecraft.block.ILiquidContainer; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; -import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.fluid.Fluid; @@ -38,6 +37,7 @@ import net.minecraft.item.Items; import net.minecraft.state.BooleanProperty; import net.minecraft.state.StateContainer; +import net.minecraft.state.StateContainer.Builder; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResultType; import net.minecraft.util.Hand; @@ -83,18 +83,29 @@ public class BorklerBlock extends Block implements ILiquidContainer { * pickaxe. */ public BorklerBlock() { - super(Properties.create(Material.PISTON).hardnessAndResistance(2.0f).sound(SoundType.STONE) - .harvestTool(ToolType.PICKAXE).harvestLevel(0).setLightLevel(new ToIntFunction() { - @Override - public int applyAsInt(BlockState value) { - if (value.get(BorklerBlock.ACTIVE)) - return 13; - else - return 0; - } - })); + super(Properties.of(Material.PISTON).strength(2.0f).sound(SoundType.STONE).harvestTool(ToolType.PICKAXE) + .harvestLevel(0)); this.setRegistryName("borkler", "steam_boiler"); - this.setDefaultState(stateContainer.getBaseState().with(ACTIVE, false)); + Builder b = new Builder(this); + this.createBlockStateDefinition(b); + this.registerDefaultState( + this.defaultBlockState().setValue(ACTIVE, Boolean.valueOf(false))); + this.properties.lightLevel(new ToIntFunction() { + + @Override + public int applyAsInt(BlockState value) { + if (value.getValue(ACTIVE)) + return 13; + else + return 0; + } + }); + // TODO there must be a better way of doing this + // for (BlockState s : stateDefinition.getPossibleStates()) { + // if (!s.getValue(ACTIVE)) { + // registerDefaultState(s); + // } + // } } /** @@ -112,23 +123,23 @@ public int applyAsInt(BlockState value) { * @return */ @Override - public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, - Hand handIn, BlockRayTraceResult hit) { - if (!worldIn.isRemote) { - ItemStack held = player.getHeldItem(handIn); + public ActionResultType use(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, + BlockRayTraceResult hit) { + if (!worldIn.isClientSide) { + ItemStack held = player.getItemInHand(handIn); if (held.getItem() instanceof BucketItem) { - boolean filled = this.receiveFluid(worldIn, pos, state, - ((BucketItem) held.getItem()).getFluid().getDefaultState()); + boolean filled = this.placeLiquid(worldIn, pos, state, + ((BucketItem) held.getItem()).getFluid().defaultFluidState()); if (filled) { held.setCount(held.getCount() - 1); - player.inventory.addItemStackToInventory(new ItemStack(Items.BUCKET, 1)); + player.inventory.add(new ItemStack(Items.BUCKET, 1)); return ActionResultType.SUCCESS; } return ActionResultType.PASS; } BorklerTileEntity te = getTileEntity(worldIn, pos); NetworkHooks.openGui((ServerPlayerEntity) player, te, ((t) -> { - BorklerData.encodePos(te.getPos(), t); + BorklerData.encodePos(te.getBlockPos(), t); })); } @@ -182,7 +193,7 @@ public TileEntity createTileEntity(BlockState state, IBlockReader world) { * block. */ @Override - protected void fillStateContainer(StateContainer.Builder stateContainer) { + protected void createBlockStateDefinition(StateContainer.Builder stateContainer) { stateContainer.add(ACTIVE); } @@ -195,7 +206,7 @@ protected void fillStateContainer(StateContainer.Builder stat * @return */ private BorklerTileEntity getTileEntity(IBlockReader world, BlockPos pos) { - TileEntity temp = world.getTileEntity(pos); + TileEntity temp = world.getBlockEntity(pos); if (temp instanceof BorklerTileEntity) return (BorklerTileEntity) temp; throw new RuntimeException( @@ -204,11 +215,8 @@ private BorklerTileEntity getTileEntity(IBlockReader world, BlockPos pos) { } @Override - public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { - BorklerTileEntity te = getTileEntity(worldIn, pos); - if (stack.hasDisplayName()) { - te.setCustomName(stack.getDisplayName()); - } + public void onPlace(BlockState state, World world, BlockPos pos, BlockState otherState, boolean wut) { + BorklerTileEntity te = getTileEntity(world, pos); te.updateFluidConnections(); te.updateItemConnections(); } @@ -217,7 +225,7 @@ public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, Livin * @return see {@link BorklerTileEntity#isFluidValid(Fluid)} */ @Override - public boolean canContainFluid(IBlockReader arg0, BlockPos arg1, BlockState arg2, Fluid arg3) { + public boolean canPlaceLiquid(IBlockReader arg0, BlockPos arg1, BlockState arg2, Fluid arg3) { return getTileEntity(arg0, arg1).getTankForFluid(arg3) >= 0; } @@ -230,16 +238,16 @@ public boolean canContainFluid(IBlockReader arg0, BlockPos arg1, BlockState arg2 * @return whether the fluid was successfully inserted or not */ @Override - public boolean receiveFluid(IWorld arg0, BlockPos arg1, BlockState arg2, FluidState arg3) { + public boolean placeLiquid(IWorld arg0, BlockPos arg1, BlockState arg2, FluidState arg3) { BorklerTileEntity tileEntity = getTileEntity(arg0, arg1); - int tank = tileEntity.getTankForFluid(arg3.getFluid()); + int tank = tileEntity.getTankForFluid(arg3.getType()); if (tank < 0 || tank == 2) return false; if (tileEntity.getTankCapacity(tank) - tileEntity.getFluidInTank(tank).getAmount() < 1000) // TODO not hardcode // bucket volume return false; - if (tileEntity.fill(new FluidStack(arg3.getFluid(), 1000), FluidAction.SIMULATE) > 0) { - return tileEntity.fill(new FluidStack(arg3.getFluid(), 1000), FluidAction.EXECUTE) > 0; + if (tileEntity.fill(new FluidStack(arg3.getType(), 1000), FluidAction.SIMULATE) > 0) { + return tileEntity.fill(new FluidStack(arg3.getType(), 1000), FluidAction.EXECUTE) > 0; } return false; } @@ -248,10 +256,14 @@ public boolean receiveFluid(IWorld arg0, BlockPos arg1, BlockState arg2, FluidSt * Overriden to drop items in the Boiler's inventory if it is destroyed. */ @Override - public void onBlockHarvested(World worldIn, BlockPos pos, BlockState state, PlayerEntity player) { - super.onBlockHarvested(worldIn, pos, state, player); - getTileEntity(worldIn, pos).remove(); - InventoryHelper.dropInventoryItems(worldIn, pos, getTileEntity(worldIn, pos)); + public boolean removedByPlayer(BlockState state, World world, BlockPos pos, PlayerEntity player, + boolean willHarvest, FluidState fluid) { + boolean harvested = super.removedByPlayer(state, world, pos, player, false, fluid); + if (harvested && willHarvest) { + getTileEntity(world, pos).setRemoved(); + InventoryHelper.dropContents(world, pos, getTileEntity(world, pos)); + super.removedByPlayer(state, world, pos, player, willHarvest, fluid); + } + return harvested; } - } diff --git a/src/main/java/gazcreations/borkler/blocks/BorklerTileEntity.java b/src/main/java/gazcreations/borkler/blocks/BorklerTileEntity.java index b4d7e26..79c91f4 100755 --- a/src/main/java/gazcreations/borkler/blocks/BorklerTileEntity.java +++ b/src/main/java/gazcreations/borkler/blocks/BorklerTileEntity.java @@ -21,14 +21,15 @@ import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Set; import gazcreations.borkler.BorklerConfig; import gazcreations.borkler.Index; +import gazcreations.borkler.compat.MekaBorkler; import gazcreations.borkler.container.BorklerContainer; import gazcreations.borkler.recipes.BorklerFuel; +import it.unimi.dsi.fastutil.objects.ObjectArraySet; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; @@ -81,53 +82,6 @@ */ public class BorklerTileEntity extends LockableTileEntity implements ITickableTileEntity, IFluidHandler, IItemHandler { - /** - * A set of valid {@link Fluid} types to use as fuel. - */ - // @Deprecated - // private static BorklerFluidList validuels = BorklerFluidList.getDefault(); - - /** - * @return A copy (in case you're tempted to alter its contents) of the map of - * valid fuels and burn times. - */ - // public static BorklerFluidList getValidFuelTypes() { - // BorklerFluidList copy = new BorklerFluidList(validuels); - // gazcreations.borkler.Borkler.LOGGER.debug("getting valid fuel types: " + - // copy); - // return copy; - // } - - // public static void addFuel(Fluid fuel, int burnTime) { - // validuels.put(fuel, burnTime); - // if (ServerLifecycleHooks.getCurrentServer() != null) { - // for (PlayerEntity player : - // ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers()) { - // addFutureServerTask(player.world, () -> - // BorklerPacketHandler.sendToPlayer(player, validuels), true); - // } - // } - // } - - /** - * Called when a client receives a BorklerFluidList update from the server, on - * login or reload. - * - * @param fluids - * @param context - */ - // public static void updateValidFuelList(BorklerFluidList fluids, - // java.util.function.Supplier context) { - // Context ctx = context.get(); - // if (ctx.getDirection() == NetworkDirection.LOGIN_TO_CLIENT - // || ctx.getDirection() == NetworkDirection.PLAY_TO_CLIENT) { - // gazcreations.borkler.Borkler.LOGGER.debug("updateValidFuelList has been - // called; list is " + fluids); - // validuels = fluids; - // } - // ctx.setPacketHandled(true); - // } - /** * The tier of this boiler. Currently unused.
* Will be used as a multiplier for tank capacity and steam production, @@ -203,6 +157,8 @@ public class BorklerTileEntity extends LockableTileEntity implements ITickableTi */ private LazyOptional itemHandlerCapability; + private LazyOptional gasHandlerWrapper; + /** * A constructor. Populates the Borkler's tanks with empty FluidStacks, * initializes its inventory and sets burnTime to zero. @@ -220,15 +176,16 @@ public BorklerTileEntity(IBlockReader world) { * Calls this TileEntity's markDirty() method. */ @Override - public void markDirty() { - BorklerTileEntity.this.markDirty(); + public void setChanged() { + super.setChanged(); + BorklerTileEntity.this.setChanged(); } /** * Checks the burn time of the itemstack to see if it can be used as fuel. */ @Override - public boolean isItemValidForSlot(int slot, ItemStack stack) { + public boolean canPlaceItem(int slot, ItemStack stack) { List hardcoded = new ArrayList<>(); hardcoded.add(Items.BUCKET); return hardcoded.contains(stack.getItem()) || stack.isEmpty() || ForgeHooks.getBurnTime(stack) > 0; @@ -238,10 +195,10 @@ public boolean isItemValidForSlot(int slot, ItemStack stack) { this.isActive = false; this.fluidConnections = Collections.emptySet(); this.itemConnections = Collections.emptySet(); - this.world = (World) world; - if (world != null) { // index TEs will not run this - addFutureServerTask(this.world, () -> updateFluidConnections(), false); - addFutureServerTask(this.world, () -> updateItemConnections(), false); + this.level = (World) world; + if (level != null) { // index TEs will not run this + addFutureServerTask(this.level, () -> updateFluidConnections(), false); + addFutureServerTask(this.level, () -> updateItemConnections(), false); } } @@ -259,15 +216,22 @@ public IInventory getInventory() { } @Override - public void markDirty() { - if (this.world != null) { + public void setChanged() { + if (this.level != null) { if (this.ticksSinceLastClientUpdate > 1) { - addFutureServerTask(world, () -> this.world.notifyBlockUpdate(getPos(), - getWorld().getBlockState(getPos()), getWorld().getBlockState(getPos()), 3), true); + addFutureServerTask(level, () -> this.level.sendBlockUpdated(getBlockPos(), + getWorld().getBlockState(getBlockPos()), getWorld().getBlockState(getBlockPos()), 3), true); this.ticksSinceLastClientUpdate = 0; } } - super.markDirty(); + super.setChanged(); + } + + /** + * @return + */ + private IBlockReader getWorld() { + return this.getLevel(); } /** @@ -305,7 +269,7 @@ public int getSlots() { @Override public ItemStack getStackInSlot(int slot) { // return new ItemStack(() -> solidFuel.getItem(), solidFuel.getCount()); - return solidFuel.getStackInSlot(0); + return solidFuel.getItem(0); } /** @@ -315,17 +279,17 @@ public ItemStack getStackInSlot(int slot) { * * @param active */ - private final void setActive(final boolean active) { + private void setActive(final boolean active) { if (this.isActive == active) { return; // nothing to do, nothing changed } this.isActive = active; - if (world != null) - this.world.setBlockState(pos, - Index.Blocks.BORKLERBLOCK.getStateContainer().getBaseState().with(BorklerBlock.ACTIVE, active)); + if (level != null) + this.level.setBlockAndUpdate(worldPosition, + Index.Blocks.BORKLERBLOCK.getStateDefinition().any().setValue(BorklerBlock.ACTIVE, active)); requestModelDataUpdate(); - this.updateContainingBlockInfo(); - markDirty(); +// this.updateContainingBlockInfo(); + setChanged(); } @Override @@ -336,7 +300,7 @@ public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { if (!isItemValid(0, stack)) return stack; - ItemStack existing = this.solidFuel.getStackInSlot(0); + ItemStack existing = this.solidFuel.getItem(0); int limit = getSlotLimit(0); if (!existing.isEmpty()) { if (!ItemHandlerHelper.canItemStacksStack(stack, existing)) @@ -351,13 +315,12 @@ public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { if (!simulate) { if (existing.isEmpty()) { - solidFuel.setInventorySlotContents(0, - reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack); + solidFuel.setItem(0, reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack); } else { existing.grow(reachedLimit ? limit : stack.getCount()); } - markDirty(); + setChanged(); } return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - limit) : ItemStack.EMPTY; } @@ -389,15 +352,7 @@ public int getSlotLimit(int slot) { */ @Override public boolean isItemValid(int slot, ItemStack stack) { - return solidFuel.isItemValidForSlot(0, stack); - } - - /** - * See {@link BorklerTileEntity#isItemValid(int, ItemStack)}. - */ - @Override - public boolean isItemValidForSlot(int slot, ItemStack stack) { - return solidFuel.isItemValidForSlot(0, stack); + return solidFuel.canAddItem(stack); } /** @@ -468,14 +423,13 @@ public boolean isFluidValid(Fluid fluid) { public boolean isFluidValid(int tank, FluidStack stack) { switch (tank) { case 0: - return stack.getFluid().isIn(FluidTags.WATER); + return stack.getFluid().is(FluidTags.WATER); case 1: // return validFuels.containsKey(stack.getFluid()); - return BorklerFuel.getBurnTime(stack.getFluid(), world) > 0; + return BorklerFuel.getBurnTime(stack.getFluid(), level) > 0; case 2: - return stack.getFluid().isEquivalentTo(Index.Fluids.STEAM) - || stack.getFluid().isEquivalentTo(Index.Fluids.STEAMSOURCE) - || stack.getFluid().isIn(FluidTags.getCollection().get(new ResourceLocation("forge:fluids/steam"))); + return stack.getFluid().isSame(Index.Fluids.STEAM) || stack.getFluid().isSame(Index.Fluids.STEAMSOURCE) + || stack.getFluid().is(FluidTags.getAllTags().getTag(new ResourceLocation("forge:fluids/steam"))); } return false; } @@ -489,13 +443,13 @@ public boolean isFluidValid(int tank, FluidStack stack) { * @return 0 if water, 1 if fuel, 2 if steam, or -1 if neither. */ public byte getTankForFluid(Fluid fluid) { - if (fluid.isIn(FluidTags.WATER)) + if (fluid.is(FluidTags.WATER)) return 0; // if (validFuels.containsKey(fluid)) { - if (BorklerFuel.getBurnTime(fluid, world) > 0) { + if (BorklerFuel.getBurnTime(fluid, level) > 0) { return 1; } - if (fluid.isIn(FluidTags.getCollection().get(new ResourceLocation("forge:fluids/steam")))) { + if (fluid.is(FluidTags.getAllTags().getTag(new ResourceLocation("forge:fluids/steam")))) { return 2; } return -1; @@ -582,7 +536,7 @@ public int fill(FluidStack resource, FluidAction action) { default: return 0; // we should never get here, plenty of checks by now } - markDirty(); // this signals the game that stuff has changed + setChanged(); // this signals the game that stuff has changed return selectedTank.getAmount(); // this is how much fluid was inserted } else { if (!selectedTank.isFluidEqual(resource)) { @@ -594,12 +548,12 @@ public int fill(FluidStack resource, FluidAction action) { if (resource.getAmount() < remainingCapacity) { // everything fits! selectedTank.grow(resource.getAmount()); - markDirty(); + setChanged(); return resource.getAmount(); } else { // Tank is filled and there's fluid leftover selectedTank.setAmount(getTankCapacity(whereDoIPutThis)); - markDirty(); + setChanged(); return remainingCapacity; } } @@ -615,11 +569,12 @@ public int fill(FluidStack resource, FluidAction action) { * @param element * @return */ - private LazyOptional addWithListener(Set> set, LazyOptional element) { - set.add(element); + public void addWithListener(Set> set, LazyOptional element) { if (element == null) { - return null; + //return null; + return; } + set.add(element); element.addListener(new NonNullConsumer>() { @Override public void accept(LazyOptional t) { @@ -628,13 +583,13 @@ public void accept(LazyOptional t) { set.remove(element); } }); - return element; + //return element; } public void updateItemConnections() { - if (world.isRemote) + if (level.isClientSide) return; - Set> consumers = new HashSet>(7, 0.99f) { + Set> consumers = new ObjectArraySet>(7) { private static final long serialVersionUID = 1L; public boolean add(LazyOptional element) { @@ -643,46 +598,46 @@ public boolean add(LazyOptional element) { return super.add(element); } }; - gazcreations.borkler.Borkler.LOGGER - .debug("Borkler @" + world + " ," + pos + " has been politely asked to update its item connections."); + gazcreations.borkler.Borkler.LOGGER.debug("Borkler @" + level + " ," + worldPosition + + " has been politely asked to update its item connections."); LazyOptional cap = null; TileEntity te = null; // Trigger warning: the following section may require subsequent use of // eyebleach. // up - if ((te = this.world.getTileEntity(getPos().offset(Direction.UP))) != null) { + if ((te = this.level.getBlockEntity(getBlockPos().above())) != null) { cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.DOWN); // if (cap.isPresent()) override of Set.add will prevent empty Optionals from // being added addWithListener(consumers, cap); } // down - if ((te = this.world.getTileEntity(getPos().offset(Direction.DOWN))) != null) { + if ((te = this.level.getBlockEntity(getBlockPos().below())) != null) { cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.UP); addWithListener(consumers, cap); } // east - if ((te = this.world.getTileEntity(getPos().offset(Direction.EAST))) != null) { + if ((te = this.level.getBlockEntity(getBlockPos().east())) != null) { cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.WEST); addWithListener(consumers, cap); } // west - if ((te = this.world.getTileEntity(getPos().offset(Direction.WEST))) != null) { + if ((te = this.level.getBlockEntity(getBlockPos().west())) != null) { cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.EAST); addWithListener(consumers, cap); } // north - if ((te = this.world.getTileEntity(getPos().offset(Direction.NORTH))) != null) { + if ((te = this.level.getBlockEntity(getBlockPos().north())) != null) { cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.SOUTH); addWithListener(consumers, cap); } // south - if ((te = this.world.getTileEntity(getPos().offset(Direction.SOUTH))) != null) { + if ((te = this.level.getBlockEntity(getBlockPos().south())) != null) { cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.NORTH); addWithListener(consumers, cap); } - gazcreations.borkler.Borkler.LOGGER - .debug("Borkler @" + world + " ," + pos + "has updated its item connections: " + consumers.toString()); + gazcreations.borkler.Borkler.LOGGER.debug("Borkler @" + level + " ," + worldPosition + + "has updated its item connections: " + consumers.toString()); this.itemConnections = consumers; } @@ -695,9 +650,9 @@ public boolean add(LazyOptional element) { * */ public void updateFluidConnections() { - if (world.isRemote) + if (level.isClientSide) return; - Set> consumers = new HashSet>(7, 0.99f) { + Set> consumers = new ObjectArraySet>(7) { private static final long serialVersionUID = 1L; public boolean add(LazyOptional element) { @@ -706,47 +661,21 @@ public boolean add(LazyOptional element) { return super.add(element); } }; - gazcreations.borkler.Borkler.LOGGER - .debug("Borkler @" + world + " ," + pos + " has been politely asked to update its fluid connections."); + gazcreations.borkler.Borkler.LOGGER.debug("Borkler @" + level + " ," + worldPosition + + " has been politely asked to update its fluid connections."); gazcreations.borkler.Borkler.LOGGER.debug("Current connections are: " + this.fluidConnections.toString()); LazyOptional cap = null; TileEntity te = null; - // Trigger warning: the following section may require subsequent use of - // eyebleach. - // up - if ((te = this.world.getTileEntity(getPos().offset(Direction.UP))) != null) { - cap = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, Direction.DOWN); - // if (cap.isPresent()) override of Set.add will prevent empty Optionals from - // being added - addWithListener(consumers, cap); - } - // down - if ((te = this.world.getTileEntity(getPos().offset(Direction.DOWN))) != null) { - cap = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, Direction.UP); - addWithListener(consumers, cap); - } - // east - if ((te = this.world.getTileEntity(getPos().offset(Direction.EAST))) != null) { - cap = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, Direction.WEST); - addWithListener(consumers, cap); - } - // west - if ((te = this.world.getTileEntity(getPos().offset(Direction.WEST))) != null) { - cap = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, Direction.EAST); - addWithListener(consumers, cap); - } - // north - if ((te = this.world.getTileEntity(getPos().offset(Direction.NORTH))) != null) { - cap = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, Direction.SOUTH); - addWithListener(consumers, cap); - } - // south - if ((te = this.world.getTileEntity(getPos().offset(Direction.SOUTH))) != null) { - cap = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, Direction.NORTH); - addWithListener(consumers, cap); + for (Direction d : Direction.values()) { + if ((te = this.level.getBlockEntity(getBlockPos().relative(d))) != null) { + cap = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, d.getOpposite()); + // if (cap.isPresent()) override of Set.add will prevent empty Optionals from + // being added + addWithListener(consumers, cap); + } } - gazcreations.borkler.Borkler.LOGGER - .debug("Borkler @" + world + " ," + pos + "has updated its connections: " + consumers.toString()); + gazcreations.borkler.Borkler.LOGGER.debug( + "Borkler @" + level + " ," + worldPosition + "has updated its connections: " + consumers.toString()); this.fluidConnections = consumers; } @@ -756,7 +685,7 @@ public boolean add(LazyOptional element) { * The Boiler will attempt to evenly distribute its steam to all consumers. */ private void distributeSteam() { - Set> consumers = new HashSet<>(7, .99f); + Set> consumers = new ObjectArraySet<>(7); for (LazyOptional dest : fluidConnections) { if (dest.isPresent()) { IFluidHandler handler = dest.orElse(null); @@ -822,11 +751,11 @@ public void pullFluid(IFluidHandler source) { // try to pull water FluidStack toDrain = new FluidStack(Fluids.WATER, getTankCapacity(0) - water.getAmount()); FluidStack drained = source.drain(toDrain, FluidAction.SIMULATE); - if (drained.getFluid().isEquivalentTo(Fluids.WATER) && drained.getAmount() > 0) { + if (drained.getFluid().isSame(Fluids.WATER) && drained.getAmount() > 0) { if (water.isEmpty()) water = new FluidStack(Fluids.WATER, 0); water.grow(source.drain(toDrain, FluidAction.EXECUTE).getAmount()); - markDirty(); + setChanged(); // water has been pulled! } // try to pull fuel @@ -838,7 +767,7 @@ public void pullFluid(IFluidHandler source) { return; if (drained.getAmount() > 0) { fuel.grow(source.drain(toDrain, FluidAction.EXECUTE).getAmount()); - markDirty(); + setChanged(); // fuel has been pulled! } } @@ -852,7 +781,7 @@ public void pullFluid(IFluidHandler source) { if (toDrain.getAmount() > 0) { fuel = new FluidStack(toDrain.getFluid(), 0); fuel.grow(source.drain(toDrain, FluidAction.EXECUTE).getAmount()); - markDirty(); + setChanged(); // fuel has been pulled! } } @@ -888,7 +817,7 @@ public FluidStack drain(int maxDrain, FluidAction action) { FluidStack stack = new FluidStack(steam, drained); if (action.execute() && drained > 0) { steam.shrink(drained); - markDirty(); + setChanged(); } return stack; } @@ -903,7 +832,7 @@ protected ITextComponent getDefaultName() { */ @Override public Container createMenu(int id, PlayerInventory playerInv, PlayerEntity player) { - BorklerContainer menu = new BorklerContainer(id, playerInv, this.solidFuel, getPos()); + BorklerContainer menu = new BorklerContainer(id, playerInv, this.solidFuel, getBlockPos()); return menu; } @@ -911,11 +840,11 @@ public Container createMenu(int id, PlayerInventory playerInv, PlayerEntity play * Credits to the folks at @TeamCofh for helping me make sense of this method. */ @Override - public ItemStack decrStackSize(int slot, int amount) { - if (solidFuel.getStackInSlot(0).isEmpty()) + public ItemStack removeItem(int slot, int amount) { + if (solidFuel.getItem(0).isEmpty()) return ItemStack.EMPTY; - ItemStack stack = solidFuel.decrStackSize(0, amount); - markDirty(); + ItemStack stack = solidFuel.removeItem(0, amount); + setChanged(); return stack; } @@ -923,8 +852,8 @@ public ItemStack decrStackSize(int slot, int amount) { * Wrapper for {@link Inventory#getSizeInventory()}. */ @Override - public int getSizeInventory() { - return solidFuel.getSizeInventory(); + public int getContainerSize() { + return solidFuel.getContainerSize(); } /** @@ -932,14 +861,14 @@ public int getSizeInventory() { */ @Override public boolean isEmpty() { - return (solidFuel == null || solidFuel.isEmpty() || solidFuel.getStackInSlot(0).isEmpty()); + return (solidFuel == null || solidFuel.isEmpty() || solidFuel.getItem(0).isEmpty()); } /** * Will return true, even though it shouldn't. */ @Override - public boolean isUsableByPlayer(PlayerEntity arg0) { + public boolean canOpen(PlayerEntity arg0) { return true; } @@ -947,10 +876,10 @@ public boolean isUsableByPlayer(PlayerEntity arg0) { * Will just pass this on to its underlying inventory. */ @Override - public ItemStack removeStackFromSlot(int arg0) { - ItemStack stonks = solidFuel.removeStackFromSlot(0); + public ItemStack removeItemNoUpdate(int arg0) { + ItemStack stonks = solidFuel.removeItemNoUpdate(0); if (!stonks.isEmpty()) - markDirty(); + setChanged(); return stonks; } @@ -958,10 +887,10 @@ public ItemStack removeStackFromSlot(int arg0) { * Will check item for validity and pass it on to its underlying inventory. */ @Override - public void setInventorySlotContents(int arg0, ItemStack arg1) { + public void setItem(int arg0, ItemStack arg1) { if (isItemValid(0, arg1)) { - this.solidFuel.setInventorySlotContents(0, arg1); - markDirty(); + this.solidFuel.setItem(0, arg1); + setChanged(); } } @@ -969,22 +898,22 @@ public void setInventorySlotContents(int arg0, ItemStack arg1) { * Wrapper for this {@link Inventory#clear()}. */ @Override - public void clear() { - solidFuel.clear(); - markDirty(); + public void clearContent() { + solidFuel.clearContent(); + setChanged(); } @Override public void onDataPacket(NetworkManager man, SUpdateTileEntityPacket s) { super.onDataPacket(man, s); - if (world.isRemote) { // just checking we're clientside - this.readCustomData(s.getNbtCompound()); + if (level.isClientSide) { // just checking we're clientside + this.readCustomData(s.getTag()); } } @Override public SUpdateTileEntityPacket getUpdatePacket() { - return new SUpdateTileEntityPacket(pos, 0, writeCustomData()); + return new SUpdateTileEntityPacket(worldPosition, 0, writeCustomData()); } /** @@ -996,7 +925,7 @@ public SUpdateTileEntityPacket getUpdatePacket() { */ @Override public void tick() { - if (world.isRemote()) // server side only. + if (level.isClientSide()) // server side only. return; // first things first: if this boiler is set to auto-input fluids, it will try // to do so before anything else. @@ -1044,7 +973,7 @@ public void tick() { int additionalBurnTime = nerfdBurnTime(getStackInSlot(0)); if (additionalBurnTime > 0) { // burnTime += ForgeHooks.getBurnTime(decrStackSize(0, 1)); - burnTime += nerfdBurnTime(decrStackSize(0, 1)); + burnTime += nerfdBurnTime(removeItem(0, 1)); setActive(true); break mainMethod; } @@ -1053,7 +982,7 @@ public void tick() { // ok, there is liquid fuel in the boiler. We'll try to burn this. int bitOFuel = Math.min(fuel.getAmount(), 5); // int addBurnTime = validFuels.getInt(fuel.getFluid()) * bitOFuel; - int addBurnTime = BorklerFuel.getBurnTime(fuel.getFluid(), world) * bitOFuel; + int addBurnTime = BorklerFuel.getBurnTime(fuel.getFluid(), level) * bitOFuel; fuel.shrink(bitOFuel); burnTime += addBurnTime; setActive(true); @@ -1090,7 +1019,7 @@ private final void boil() { if (steam.getAmount() > getTankCapacity(2)) steam.setAmount(getTankCapacity(2)); burnTime--; - markDirty(); + setChanged(); } /** @@ -1104,8 +1033,8 @@ private CompoundNBT writeCustomData() { stuff.putInt("water", this.water.getAmount()); stuff.putString("fuelType", fuel.getFluid().getRegistryName().toString()); stuff.putInt("fuelAmount", this.fuel.getAmount()); - stuff.putString("solidFuelType", this.solidFuel.getStackInSlot(0).getItem().getRegistryName().toString()); - stuff.putInt("solidFuelAmount", this.solidFuel.getStackInSlot(0).getCount()); + stuff.putString("solidFuelType", this.solidFuel.getItem(0).getItem().getRegistryName().toString()); + stuff.putInt("solidFuelAmount", this.solidFuel.getItem(0).getCount()); stuff.putBoolean("isActive", isActive); stuff.putInt("burnTime", this.burnTime); return stuff; @@ -1121,7 +1050,7 @@ private void readCustomData(CompoundNBT nbt) { water = new FluidStack(Fluids.WATER, nbt.getInt("water")); fuel = new FluidStack(ForgeRegistries.FLUIDS.getValue(new ResourceLocation(nbt.getString("fuelType"))), nbt.getInt("fuelAmount")); - solidFuel.setInventorySlotContents(0, + solidFuel.setItem(0, new ItemStack( () -> ForgeRegistries.ITEMS.getValue(new ResourceLocation(nbt.getString("solidFuelType"))), nbt.getInt("solidFuelAmount"))); @@ -1135,29 +1064,31 @@ private void readCustomData(CompoundNBT nbt) { * for persistence. */ @Override - public CompoundNBT write(CompoundNBT nbt) { + public CompoundNBT save(CompoundNBT nbt) { writeCustomData(); - return super.write(nbt); + return super.save(nbt); } /** * Populates this TileEntity's fields with values stored in an NBT. */ @Override - public void read(BlockState state, CompoundNBT nbtTag) { - super.read(state, nbtTag); + public void load(BlockState state, CompoundNBT nbtTag) { + super.load(state, nbtTag); readCustomData(nbtTag.getCompound("ForgeData")); - if (this.world != null) + if (this.level != null) { updateFluidConnections(); + updateItemConnections(); + } } @Override public void onLoad() { super.onLoad(); - if (world != null && !world.isRemote()) { - addFutureServerTask(world, () -> updateFluidConnections(), true); - addFutureServerTask(world, () -> updateItemConnections(), true); - addFutureServerTask(world, () -> this.updateContainingBlockInfo(), true); + if (level != null && !level.isClientSide()) { + addFutureServerTask(level, () -> updateFluidConnections(), true); + addFutureServerTask(level, () -> updateItemConnections(), true); + addFutureServerTask(level, () -> this.setChanged(), true); } } @@ -1172,17 +1103,17 @@ public void onLoad() { * @param forceFuture */ public static void addFutureServerTask(World world, Runnable task, boolean forceFuture) { - LogicalSide side = world.isRemote ? LogicalSide.CLIENT : LogicalSide.SERVER; + LogicalSide side = world.isClientSide ? LogicalSide.CLIENT : LogicalSide.SERVER; ThreadTaskExecutor tmp = LogicalSidedProvider.WORKQUEUE.get(side); if (forceFuture) { int tick; - if (world.isRemote) + if (world.isClientSide) tick = 0; else - tick = ((MinecraftServer) tmp).getTickCounter(); - tmp.enqueue(new TickDelayedTask(tick, task)); + tick = ((MinecraftServer) tmp).getTickCount(); + tmp.tell(new TickDelayedTask(tick, task)); } else - tmp.deferTask(task); + tmp.submit(task); } /** @@ -1204,6 +1135,17 @@ public LazyOptional getCapability(Capability cap, @javax.annotation.Nu } return itemHandlerCapability.cast(); } + try { + if (cap == MekaBorkler.GasHandlerCapability) { + gazcreations.borkler.Borkler.LOGGER.debug("something is checking borkler for gases"); + if (gasHandlerWrapper == null || !gasHandlerWrapper.isPresent()) { + gasHandlerWrapper = LazyOptional.of(() -> new MekaBorkler(this)); + } + return gasHandlerWrapper.cast(); + } + } catch (Throwable t) { + gazcreations.borkler.Borkler.LOGGER.debug(t); // TODO remove this + } return LazyOptional.empty(); } @@ -1227,4 +1169,14 @@ public Container createMenu(int id, PlayerInventory player) { return this.createMenu(id, player, player.player); } + @Override + public ItemStack getItem(int p_70301_1_) { + return this.getStackInSlot(p_70301_1_); + } + + @Override + public boolean stillValid(PlayerEntity p_70300_1_) { + return solidFuel.stillValid(p_70300_1_); + } + } diff --git a/src/main/java/gazcreations/borkler/client/screen/BorklerScreen.java b/src/main/java/gazcreations/borkler/client/screen/BorklerScreen.java index 70d433c..b4afc40 100644 --- a/src/main/java/gazcreations/borkler/client/screen/BorklerScreen.java +++ b/src/main/java/gazcreations/borkler/client/screen/BorklerScreen.java @@ -62,6 +62,8 @@ public class BorklerScreen extends ContainerScreen implements "textures/gui/boiler_overlay.png"); private TankSimulator[] tanks; private BorklerTileEntity ent; + private int xSize; + private int ySize; /** * A little screen constructor, containing the back-end container and the @@ -75,9 +77,11 @@ public BorklerScreen(BorklerContainer screenContainer, PlayerInventory inv, ITex super(screenContainer, inv, titleIn); this.xSize = 184; this.ySize = 151; + //corrections lul + this.inventoryLabelY -= 8; + this.titleLabelY += 8; ent = screenContainer.getTileEntity(); - initTanks(Minecraft.getInstance().getMainWindow().getWidth(), - Minecraft.getInstance().getMainWindow().getHeight()); + initTanks(Minecraft.getInstance().getWindow().getWidth(), Minecraft.getInstance().getWindow().getHeight()); passEvents = false; } @@ -104,10 +108,10 @@ public void init(Minecraft minecraft, int width, int height) { * Will draw default tooltips for items and for the fluids in the tanks. */ @Override - protected void renderHoveredTooltip(MatrixStack matrixStack, int x, int y) { - if (this.minecraft.player.inventory.getItemStack().isEmpty() && this.hoveredSlot != null - && this.hoveredSlot.getHasStack()) { - this.renderTooltip(matrixStack, this.hoveredSlot.getStack(), x, y); + protected void renderTooltip(MatrixStack matrixStack, int x, int y) { + if (this.minecraft.player.inventory.getItem(this.minecraft.player.inventory.selected).isEmpty() + && this.hoveredSlot != null && this.hoveredSlot.hasItem()) { + this.renderTooltip(matrixStack, this.hoveredSlot.getItem(), x, y); } else { for (int i = 0; i < tanks.length; i++) { TankSimulator tank = tanks[i]; @@ -127,13 +131,6 @@ protected void renderHoveredTooltip(MatrixStack matrixStack, int x, int y) { } } - @Override - protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int mouseX, int mouseY) { - this.font.func_243248_b(matrixStack, this.title, 8.0F, 6.0F, 4210752); - this.font.func_243248_b(matrixStack, this.playerInventory.getDisplayName(), 8.0F, (float) (this.ySize - 96 + 2), - 4210752); - } - /** * Will draw a tank with its fluid and level on the screen. * @@ -162,7 +159,7 @@ private void drawTank(MatrixStack matrixStack, TankSimulator tank, boolean doubl RenderSystem.color4f(tank.fluidColor.getRed() / 255f, tank.fluidColor.getGreen() / 255f, tank.fluidColor.getBlue() / 255f, tank.fluidColor.getAlpha() / 255f); RenderSystem.enableBlend(); - getMinecraft().getTextureManager().bindTexture(PlayerContainer.LOCATION_BLOCKS_TEXTURE); + getMinecraft().getTextureManager().bind(PlayerContainer.BLOCK_ATLAS); /* * Again, we will subtract two pixels from the tank's X size and dislocate it to * the right. @@ -170,7 +167,7 @@ private void drawTank(MatrixStack matrixStack, TankSimulator tank, boolean doubl blit(matrixStack, tank.posX + 1, yPos, 0, tank.sizeX - 2, ySize, tank.cachedFluidSprite); RenderSystem.disableBlend(); RenderSystem.color4f(1, 1, 1, 1); - getMinecraft().getTextureManager().bindTexture(overlayTexture); + getMinecraft().getTextureManager().bind(overlayTexture); /* * This offset tells the texture manager where to look for the tank overlay in * the gui texture file. @@ -186,16 +183,18 @@ private void drawTank(MatrixStack matrixStack, TankSimulator tank, boolean doubl public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { this.renderBackground(matrixStack); super.render(matrixStack, mouseX, mouseY, partialTicks); + //this.font.draw(matrixStack, this.title, 8.0F, 6.0F, 4210752); + //this.font.draw(matrixStack, this.inventory.getDisplayName(), 8.0F, (float) (this.ySize - 96 + 2), 4210752); for (int i = 0; i < 3; i++) { drawTank(matrixStack, tanks[i], i == 2); } - this.renderHoveredTooltip(matrixStack, mouseX, mouseY); + this.renderTooltip(matrixStack, mouseX, mouseY); } @Override - protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int x, int y) { + protected void renderBg(MatrixStack matrixStack, float partialTicks, int x, int y) { RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); - this.minecraft.getTextureManager().bindTexture(guiTexture); + this.minecraft.getTextureManager().bind(guiTexture); blit(matrixStack, (this.width - this.xSize) / 2, (this.height - this.ySize) / 2, 0, 0, 256, 256); } @@ -222,14 +221,13 @@ public TankSimulator(int index, int posX, int posY) { this.sizeX = 18; this.sizeY = 49; setFluidTexture(); - BorklerScreen.this.addListener(this); // this is done so that the tanks can be resized - gazcreations.borkler.Borkler.LOGGER.info(getFluid().getDisplayName().getString()); - + BorklerScreen.this.addWidget(this); // this is done so that the tanks can be resized } /** * Gets whether the mouse is currently over this TankSimulator's area. */ + @Override //nice public boolean isMouseOver(double mouseX, double mouseY) { return mouseX >= this.posX && mouseX < this.posX + this.sizeX && mouseY >= this.posY && mouseY < this.posY + this.sizeY; @@ -245,8 +243,7 @@ private void setFluidTexture() { return; } if (cachedFluidSprite == null) { - Texture txtr = Minecraft.getInstance().getTextureManager() - .getTexture(PlayerContainer.LOCATION_BLOCKS_TEXTURE); + Texture txtr = Minecraft.getInstance().getTextureManager().getTexture(PlayerContainer.BLOCK_ATLAS); if (txtr instanceof AtlasTexture) { cachedFluidSprite = ((AtlasTexture) txtr) .getSprite(getFluid().getFluid().getAttributes().getStillTexture()); @@ -276,5 +273,4 @@ FluidStack getFluid() { return ent.getFluidInTank(index); } } - } diff --git a/src/main/java/gazcreations/borkler/compat/MekaBorkler.java b/src/main/java/gazcreations/borkler/compat/MekaBorkler.java new file mode 100644 index 0000000..d819037 --- /dev/null +++ b/src/main/java/gazcreations/borkler/compat/MekaBorkler.java @@ -0,0 +1,174 @@ +/** + * Copyright 2021, B. Gazotti + * + * This file is part of Borkler. + * + * Borkler is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Borkler is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Borkler. If not, see . + */ + +package gazcreations.borkler.compat; + +import java.util.AbstractSet; +import java.util.Collections; +import java.util.Set; + +import javax.annotation.Nonnull; + +import gazcreations.borkler.blocks.BorklerTileEntity; +import it.unimi.dsi.fastutil.objects.ObjectArraySet; +import mekanism.api.Action; +import mekanism.api.chemical.gas.GasStack; +import mekanism.api.chemical.gas.IGasHandler; +import mekanism.common.registries.MekanismGases; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Direction; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.CapabilityInject; +import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.fluids.capability.CapabilityFluidHandler; +import net.minecraftforge.fluids.capability.IFluidHandler; +import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction; + +/** + * This class acts as a wrapper for a {@link BorklerTileEntity}, implementing + * Mekanism's {@link IGasHandler} interface.
+ * Basically, it provides an external {@link Capability} that a + * BorklerTE can use to output steam in its Mekanism gaseous form. The "Liquid" + * steam provided by Borkler is converted to Mekanism's gaseous Steam when + * something tries to extract a gas from it. + * + * @author gazotti + * + */ +public class MekaBorkler implements IGasHandler { + + @CapabilityInject(IGasHandler.class) + public static Capability GasHandlerCapability = null; + + private final BorklerTileEntity boiler; + + private Set> gasConsumers; + + public MekaBorkler(@Nonnull BorklerTileEntity borkler) { + assert borkler != null; + boiler = borkler; + gasConsumers = Collections.emptySet(); + updateGasConnections(); + } + + @SuppressWarnings("resource") + public void updateGasConnections() { + if (boiler.getLevel().isClientSide) + return; + Set> consumers = new ObjectArraySet>(7) { + + private static final long serialVersionUID = 1L; + + public boolean add(LazyOptional element) { + if (element == null || !element.isPresent()) + return false; + return super.add(element); + } + }; + gazcreations.borkler.Borkler.LOGGER.debug("Borkler @" + boiler.getLevel() + " ," + boiler.getBlockPos() + + " has been politely asked to update its gas connections."); + gazcreations.borkler.Borkler.LOGGER.debug("Current connections are: " + gasConsumers.toString()); + LazyOptional cap = null; + TileEntity te = null; + for (Direction d : Direction.values()) { + if ((te = boiler.getLevel().getBlockEntity(boiler.getBlockPos().relative(d))) != null) { + cap = te.getCapability(GasHandlerCapability, d.getOpposite()); + // if (cap.isPresent()) override of Set.add will prevent empty Optionals from + // being added + boiler.addWithListener(consumers, cap); + } + } + gazcreations.borkler.Borkler.LOGGER.debug( + "Borkler @" + boiler.getLevel() + " ," + boiler.getBlockPos() + "has updated its connections: " + consumers.toString()); + this.gasConsumers = consumers; + } + + public BorklerTileEntity getWrapped() { + return boiler; + } + + @Override + public GasStack extractChemical(int tank, long maxDrain, Action action) { + // TODO Auto-generated method stub + if (tank != 2) + return GasStack.EMPTY; + long drained = maxDrain; + // Okay. Since we're talking about a steam boiler, it only makes sense + // that whatever we drain here is steam, right? + // guys? + if (boiler.getFluidInTank(2).getAmount() < drained) { + drained = boiler.getFluidInTank(2).getAmount(); + } + GasStack stack = MekanismGases.STEAM.getStack(drained); + if (action.execute() && drained > 0) { + boiler.drain((int) drained, FluidAction.EXECUTE); + boiler.setChanged(); + } + return stack; + } + + @Override + public GasStack getChemicalInTank(int arg0) { + // TODO Auto-generated method stub + if (arg0 == 2) { + return MekanismGases.STEAM.getStack(boiler.getFluidInTank(arg0).getAmount()); + } + return GasStack.EMPTY; + } + + @Override + public long getTankCapacity(int arg0) { + return boiler.getTankCapacity(arg0); + } + + @Override + public int getTanks() { + return boiler.getTanks(); + } + + @Override + public GasStack insertChemical(int arg0, GasStack arg1, Action arg2) { + // TODO add support for gas fuels? + // as of right now, this method won't do anything, because you can't pipe steam + // to a boiler. + return arg1; + } + + @Override + public boolean isValid(int arg0, GasStack arg1) { + // TODO Auto-generated method stub + return arg0 == 2 && arg1.getRaw() == MekanismGases.STEAM.get(); + } + + @Override + public void setChemicalInTank(int arg0, GasStack arg1) { + // TODO Auto-generated method stub + + } + + @Override + public GasStack getEmptyStack() { + return GasStack.EMPTY; + } + + public void autoOutputGas() { + // TODO implement + } + +} diff --git a/src/main/java/gazcreations/borkler/compat/jei/BorklerFluidFuelCategory.java b/src/main/java/gazcreations/borkler/compat/jei/BorklerFluidFuelCategory.java index f073ddf..2ae0dae 100644 --- a/src/main/java/gazcreations/borkler/compat/jei/BorklerFluidFuelCategory.java +++ b/src/main/java/gazcreations/borkler/compat/jei/BorklerFluidFuelCategory.java @@ -97,6 +97,6 @@ public void setRecipe(IRecipeLayout layout, BorklerFuel recipe, IIngredients ing @SuppressWarnings("resource") @Override public void draw(BorklerFuel recipe, MatrixStack stack, double mouseX, double mouseY) { - Minecraft.getInstance().fontRenderer.drawString(stack, recipe.getBurnTime() + " ticks", 5, 5, 0); + Minecraft.getInstance().font.draw(stack, recipe.getBurnTime() + " ticks", 5, 5, 0); } } diff --git a/src/main/java/gazcreations/borkler/compat/jei/BorklerFuelCategory.java b/src/main/java/gazcreations/borkler/compat/jei/BorklerFuelCategory.java index deffae8..ce83a62 100644 --- a/src/main/java/gazcreations/borkler/compat/jei/BorklerFuelCategory.java +++ b/src/main/java/gazcreations/borkler/compat/jei/BorklerFuelCategory.java @@ -53,7 +53,7 @@ public BorklerFuelCategory(IGuiHelper guiHelper) { @Override public String getTitle() { - return I18n.format("container.borkler.steam_boiler"); + return I18n.get("container.borkler.steam_boiler"); } @Override diff --git a/src/main/java/gazcreations/borkler/compat/jei/JustEnoughBork.java b/src/main/java/gazcreations/borkler/compat/jei/JustEnoughBork.java index 0336689..07024f8 100644 --- a/src/main/java/gazcreations/borkler/compat/jei/JustEnoughBork.java +++ b/src/main/java/gazcreations/borkler/compat/jei/JustEnoughBork.java @@ -63,8 +63,9 @@ public void registerCategories(IRecipeCategoryRegistration reg) { @Override public void registerRecipes(IRecipeRegistration reg) { // register all liquid fuel types - reg.addRecipes(Minecraft.getInstance().world.getRecipeManager().getRecipesForType(BorklerFuel.TYPE), - BorklerFluidFuelCategory.UID); + + reg.addRecipes(Minecraft.getInstance().player.getCommandSenderWorld().getRecipeManager() + .getAllRecipesFor(BorklerFuel.TYPE), BorklerFluidFuelCategory.UID); } diff --git a/src/main/java/gazcreations/borkler/container/BorklerContainer.java b/src/main/java/gazcreations/borkler/container/BorklerContainer.java index 5f82480..5dd57d5 100644 --- a/src/main/java/gazcreations/borkler/container/BorklerContainer.java +++ b/src/main/java/gazcreations/borkler/container/BorklerContainer.java @@ -73,41 +73,42 @@ public BorklerContainer(int id, PlayerInventory playerInv, IInventory inventory, BlockPos pos) { super(Index.BORKLER_CONTAINER_TYPE, id); if (pos != null) { - this.borklerInventory = ((BorklerTileEntity) playerInv.player.world.getTileEntity(pos)).getInventory(); + this.borklerInventory = ((BorklerTileEntity) playerInv.player.level.getBlockEntity(pos)).getInventory(); gazcreations.borkler.Borkler.LOGGER.debug("Workaround implemented."); } else this.borklerInventory = inventory; - borklerInventory.openInventory(playerInv.player); - addSlot(new Slot(borklerInventory, 0, 28, 27) { + borklerInventory.startOpen(playerInv.player); + addSlot(new Slot(borklerInventory, 0, 24, 34) { @Override - public boolean isItemValid(ItemStack stack) { - boolean valid = borklerInventory.isItemValidForSlot(this.getSlotIndex(), stack); + public boolean mayPlace(ItemStack stack) { + boolean valid = borklerInventory.canPlaceItem(this.getSlotIndex(), stack); return valid; } @Override - public void putStack(ItemStack stack) { - if (this.isItemValid(stack)) - super.putStack(stack); + public void set(ItemStack stack) { + if (this.mayPlace(stack)) + super.set(stack); } }); + // 137, 106 -> 133, 113: -4, +7 // 12,68 is the first player slot // 12,126 is the player's first hotbar slot - int leftCol = 12; + int leftCol = 8; for (int playerInvRow = 0; playerInvRow < 3; playerInvRow++) { for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++) { addSlot(new Slot(playerInv, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, - 151 - (4 - playerInvRow) * 18 - 10)); + 158 - (4 - playerInvRow) * 18 - 10)); } } for (int hotbarSlot = 0; hotbarSlot < 9; hotbarSlot++) { - addSlot(new Slot(playerInv, hotbarSlot, leftCol + hotbarSlot * 18, 127)); + addSlot(new Slot(playerInv, hotbarSlot, leftCol + hotbarSlot * 18, 134)); } if (pos != null) { this.tileEntityPos = pos; - this.borklerTE = (BorklerTileEntity) playerInv.player.world.getTileEntity(tileEntityPos); + this.borklerTE = (BorklerTileEntity) playerInv.player.level.getBlockEntity(tileEntityPos); if (borklerTE != null) { gazcreations.borkler.Borkler.LOGGER.debug(this.getClass() + ": BorklerTE found"); this.tanksWithCapacity = new ArrayList>(4); @@ -119,48 +120,37 @@ public void putStack(ItemStack stack) { } @Override - public boolean canInteractWith(PlayerEntity playerIn) { - return borklerInventory.isUsableByPlayer(playerIn); - } - - @Override - public void onContainerClosed(PlayerEntity playerIn) { - super.onContainerClosed(playerIn); - borklerInventory.closeInventory(playerIn); - } - - @Override - public void putStackInSlot(int index, ItemStack stack) { + public void setItem(int index, ItemStack stack) { if (index == 0) { // Borkler Special Slot. Running extra checks. - if (!getSlot(0).isItemValid(stack)) + if (!getSlot(0).mayPlace(stack)) return; } - super.putStackInSlot(index, stack); + super.setItem(index, stack); } /** * Handles shift+click logic. */ @Override - public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) { + public ItemStack quickMoveStack(PlayerEntity playerIn, int index) { ItemStack itemstack = ItemStack.EMPTY; - Slot slot = this.inventorySlots.get(index); - if (slot != null && slot.getHasStack()) { - ItemStack itemstack1 = slot.getStack(); + Slot slot = this.slots.get(index); + if (slot != null && slot.hasItem()) { + ItemStack itemstack1 = slot.getItem(); itemstack = itemstack1.copy(); - if (index < borklerInventory.getSizeInventory()) { - if (!this.mergeItemStack(itemstack1, borklerInventory.getSizeInventory(), this.inventorySlots.size(), + if (index < borklerInventory.getContainerSize()) { + if (!this.moveItemStackTo(itemstack1, borklerInventory.getContainerSize(), this.slots.size(), true)) { return ItemStack.EMPTY; } - } else if (!this.mergeItemStack(itemstack1, 0, borklerInventory.getSizeInventory(), false)) { + } else if (!this.moveItemStackTo(itemstack1, 0, borklerInventory.getContainerSize(), false)) { return ItemStack.EMPTY; } if (itemstack1.isEmpty()) { - slot.putStack(ItemStack.EMPTY); + slot.set(ItemStack.EMPTY); } else { - slot.onSlotChanged(); + slot.setChanged(); } } @@ -186,4 +176,9 @@ public void setTileEntityPos(BlockPos tileEntityPos) { public BorklerTileEntity getTileEntity() { return this.borklerTE; } + + @Override + public boolean stillValid(PlayerEntity p_75145_1_) { + return this.borklerInventory.stillValid(p_75145_1_); + } } diff --git a/src/main/java/gazcreations/borkler/fluids/Steam.java b/src/main/java/gazcreations/borkler/fluids/Steam.java index 63fddd9..c7400f9 100755 --- a/src/main/java/gazcreations/borkler/fluids/Steam.java +++ b/src/main/java/gazcreations/borkler/fluids/Steam.java @@ -28,6 +28,7 @@ import net.minecraft.item.Item; import net.minecraft.item.Items; import net.minecraft.state.StateContainer; +import net.minecraft.state.StateHolder; import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundEvents; @@ -66,7 +67,7 @@ protected FluidAttributes createAttributes() { return net.minecraftforge.fluids.FluidAttributes .builder(new ResourceLocation("block/water_still"), new ResourceLocation("block/water_flow")) .overlay(new ResourceLocation("block/water_overlay")).translationKey("block.borkler.steam_source") - .color(0xFFD6EBEB).sound(SoundEvents.ITEM_BUCKET_FILL, SoundEvents.ITEM_BUCKET_EMPTY).density(-5) + .color(0xFFD6EBEB).sound(SoundEvents.BUCKET_FILL, SoundEvents.BUCKET_EMPTY).density(-5) .temperature(373).gaseous().viscosity(500).build(Index.Fluids.STEAMSOURCE); } @@ -76,7 +77,7 @@ protected FluidAttributes createAttributes() { * @return Air. Yep. */ @Override - public Item getFilledBucket() { + public Item getBucket() { return Items.AIR; } @@ -86,7 +87,7 @@ public Item getFilledBucket() { * @return false */ @Override - protected boolean canDisplace(FluidState fluidState, IBlockReader blockReader, BlockPos pos, Fluid fluid, + protected boolean canBeReplacedWith(FluidState fluidState, IBlockReader blockReader, BlockPos pos, Fluid fluid, Direction direction) { return false; } @@ -97,7 +98,7 @@ protected boolean canDisplace(FluidState fluidState, IBlockReader blockReader, B * @return 5, the default tick rate for water. */ @Override - public int getTickRate(IWorldReader p_205569_1_) { + public int getTickDelay(IWorldReader p_205569_1_) { return 5; } @@ -115,7 +116,7 @@ protected float getExplosionResistance() { * @return A reference to flowing steam. */ @Override - public Fluid getFlowingFluid() { + public Fluid getFlowing() { return Index.Fluids.STEAM; } @@ -123,7 +124,7 @@ public Fluid getFlowingFluid() { * @return A reference to a steam source block. */ @Override - public Fluid getStillFluid() { + public Fluid getSource() { return Index.Fluids.STEAMSOURCE; } @@ -132,7 +133,7 @@ public Fluid getStillFluid() { * produce steam out of steam. Or can you? */ @Override - protected boolean canSourcesMultiply() { + protected boolean canConvertToSource() { return false; } @@ -140,7 +141,7 @@ protected boolean canSourcesMultiply() { * I should probably implement this method. */ @Override - protected void beforeReplacingBlock(IWorld worldIn, BlockPos pos, BlockState state) { + protected void beforeDestroyingBlock(IWorld worldIn, BlockPos pos, BlockState state) { } /** @@ -155,17 +156,17 @@ protected int getSlopeFindDistance(IWorldReader worldIn) { * Ok, you got me. I do not know what this method does. But it's there, and * perhaps the reason for the bizarre behaviour? */ - @Override - public BlockState getBlockState(FluidState state) { - return Index.Blocks.STEAM.getDefaultState().with(FlowingFluidBlock.LEVEL, - Integer.valueOf(getLevelFromState(state))); + public BlockState createLegacyBlock(FluidState state) { + return Index.Blocks.STEAM.defaultBlockState(). + setValue(FlowingFluidBlock.LEVEL, + Integer.valueOf(getLegacyLevel(state))); } /** * @return 1. Water value. */ @Override - public int getLevelDecreasePerBlock(IWorldReader worldIn) { + public int getDropOff(IWorldReader worldIn) { return 1; } @@ -187,19 +188,13 @@ protected FluidAttributes createAttributes() { return net.minecraftforge.fluids.FluidAttributes .builder(new ResourceLocation("block/water_still"), new ResourceLocation("block/water_flow")) .overlay(new ResourceLocation("block/water_overlay")).translationKey("block.borkler.steam_source") - .color(0xFFD6EBEB).sound(SoundEvents.ITEM_BUCKET_FILL, SoundEvents.ITEM_BUCKET_EMPTY).density(-5) + .color(0xFFD6EBEB).sound(SoundEvents.BUCKET_FILL, SoundEvents.BUCKET_EMPTY).density(-5) .temperature(373).gaseous().viscosity(500).build(Index.Fluids.STEAM); } @Override - protected void fillStateContainer(StateContainer.Builder builder) { - super.fillStateContainer(builder); - builder.add(LEVEL_1_8); - } - - @Override - public int getLevel(FluidState state) { - return state.get(LEVEL_1_8); + public int getAmount(FluidState state) { + return state.getAmount(); } @Override @@ -222,7 +217,7 @@ public Source() { } @Override - public int getLevel(FluidState state) { + public int getAmount(FluidState state) { return 8; } diff --git a/src/main/java/gazcreations/borkler/fluids/SteamBlock.java b/src/main/java/gazcreations/borkler/fluids/SteamBlock.java index a882c09..e10a894 100755 --- a/src/main/java/gazcreations/borkler/fluids/SteamBlock.java +++ b/src/main/java/gazcreations/borkler/fluids/SteamBlock.java @@ -37,8 +37,8 @@ public SteamBlock() { public Steam get() { return Index.Fluids.STEAMSOURCE; } - }, AbstractBlock.Properties.create(Material.WATER, MaterialColor.LIGHT_GRAY).doesNotBlockMovement() - .hardnessAndResistance(0.0F).noDrops().setLightLevel(new ToIntFunction() { + }, AbstractBlock.Properties.of(Material.WATER, MaterialColor.COLOR_LIGHT_GRAY).noCollission() + .strength(0.0F).noDrops().lightLevel(new ToIntFunction() { @Override public int applyAsInt(BlockState value) { diff --git a/src/main/java/gazcreations/borkler/items/BorklerItem.java b/src/main/java/gazcreations/borkler/items/BorklerItem.java index 25f2886..dd587a6 100755 --- a/src/main/java/gazcreations/borkler/items/BorklerItem.java +++ b/src/main/java/gazcreations/borkler/items/BorklerItem.java @@ -26,7 +26,7 @@ public class BorklerItem extends BlockItem { public BorklerItem() { - super(Index.Blocks.BORKLERBLOCK, new Properties().group(ItemGroup.REDSTONE).maxStackSize(64)); + super(Index.Blocks.BORKLERBLOCK, new Properties().tab(ItemGroup.TAB_REDSTONE).stacksTo(64)); this.setRegistryName("borkler", "steam_boiler"); } diff --git a/src/main/java/gazcreations/borkler/items/SteamItem.java b/src/main/java/gazcreations/borkler/items/SteamItem.java index a3006be..4182a6a 100755 --- a/src/main/java/gazcreations/borkler/items/SteamItem.java +++ b/src/main/java/gazcreations/borkler/items/SteamItem.java @@ -36,7 +36,7 @@ public class SteamItem extends BlockItem { public SteamItem() { - super(new SteamBlock(), new Properties().group(ItemGroup.MISC)); + super(new SteamBlock(), new Properties().tab(ItemGroup.TAB_MISC)); this.setRegistryName("borkler", "steam_source"); } } diff --git a/src/main/java/gazcreations/borkler/network/BorklerData.java b/src/main/java/gazcreations/borkler/network/BorklerData.java index b16ba75..d0613d0 100644 --- a/src/main/java/gazcreations/borkler/network/BorklerData.java +++ b/src/main/java/gazcreations/borkler/network/BorklerData.java @@ -107,7 +107,7 @@ public static CompoundNBT decodeToNBT(PacketBuffer packet) { } public static void encode(CompoundNBT data, PacketBuffer packet) { - packet.writeCompoundTag(data); + packet.writeNbt(data); } /** @@ -120,7 +120,7 @@ public static void encode(CompoundNBT data, PacketBuffer packet) { public static void handlePacket(BorklerData data, Supplier contextSupplier) { Context context = contextSupplier.get(); context.enqueueWork(() -> { - Container container = Minecraft.getInstance().player.openContainer; + Container container = Minecraft.getInstance().player.containerMenu; if (container != null && container instanceof BorklerContainer) { BorklerContainer bc = (BorklerContainer) container; bc.setTanks(data.tanks); diff --git a/src/main/java/gazcreations/borkler/proxy/ClientProxy.java b/src/main/java/gazcreations/borkler/proxy/ClientProxy.java index f7557dc..868fba0 100644 --- a/src/main/java/gazcreations/borkler/proxy/ClientProxy.java +++ b/src/main/java/gazcreations/borkler/proxy/ClientProxy.java @@ -45,7 +45,7 @@ public class ClientProxy implements Supplier { @SuppressWarnings("unchecked") private void doClientStuff(final FMLCommonSetupEvent evt) { Borkler.LOGGER.info("Registering Screens!"); - ScreenManager.registerFactory((ContainerType) Index.BORKLER_CONTAINER_TYPE, + ScreenManager.register((ContainerType) Index.BORKLER_CONTAINER_TYPE, BorklerScreen::new); } diff --git a/src/main/java/gazcreations/borkler/recipes/BorklerFuel.java b/src/main/java/gazcreations/borkler/recipes/BorklerFuel.java index 0bc7158..273c677 100644 --- a/src/main/java/gazcreations/borkler/recipes/BorklerFuel.java +++ b/src/main/java/gazcreations/borkler/recipes/BorklerFuel.java @@ -70,8 +70,8 @@ private static ResourceLocation getFluidName(Fluid fluid) { * @return The burn time in ticks/mB; 0 if the fluid is not fuel */ public static int getBurnTime(Fluid fluid, World world) { - for (BorklerFuel rec : world.getRecipeManager().getRecipesForType(BorklerFuel.TYPE)) { - if (rec.fluid.isEquivalentTo(fluid)) + for (BorklerFuel rec : world.getRecipeManager().getAllRecipesFor(BorklerFuel.TYPE)) { + if (rec.fluid.isSame(fluid)) return rec.burnTime; } return 0; @@ -97,21 +97,21 @@ public static void registerSolidRecipes(Object o) { @Override public boolean matches(BorklerTileEntity inv, World worldIn) { - return inv.getFluidInTank(1).getFluid().isEquivalentTo(fluid); + return inv.getFluidInTank(1).getFluid().isSame(fluid); } @Override - public ItemStack getCraftingResult(BorklerTileEntity inv) { + public ItemStack assemble(BorklerTileEntity inv) { return ItemStack.EMPTY; } @Override - public boolean canFit(int width, int height) { + public boolean canCraftInDimensions(int width, int height) { return false; } @Override - public ItemStack getRecipeOutput() { + public ItemStack getResultItem() { return ItemStack.EMPTY; } @@ -129,4 +129,5 @@ public IRecipeSerializer getSerializer() { public IRecipeType getType() { return TYPE; } + } diff --git a/src/main/java/gazcreations/borkler/recipes/BorklerFuelSerializer.java b/src/main/java/gazcreations/borkler/recipes/BorklerFuelSerializer.java index 8586ca9..76bd8be 100644 --- a/src/main/java/gazcreations/borkler/recipes/BorklerFuelSerializer.java +++ b/src/main/java/gazcreations/borkler/recipes/BorklerFuelSerializer.java @@ -50,7 +50,7 @@ private BorklerFuelSerializer() { @Nullable @Override - public BorklerFuel read(ResourceLocation recipeId, JsonObject json) { + public BorklerFuel fromJson(ResourceLocation recipeId, JsonObject json) { try { String fluidName = json.get("fluid").getAsString(); Fluid fluid = ForgeRegistries.FLUIDS.getValue(new ResourceLocation(fluidName)); @@ -65,14 +65,14 @@ public BorklerFuel read(ResourceLocation recipeId, JsonObject json) { } @Override - public BorklerFuel read(ResourceLocation recipeId, PacketBuffer buffer) { + public BorklerFuel fromNetwork(ResourceLocation recipeId, PacketBuffer buffer) { Fluid fluid = buffer.readFluidStack().getFluid(); int burnTime = buffer.readInt(); return new BorklerFuel(fluid, burnTime, recipeId); } @Override - public void write(PacketBuffer buffer, BorklerFuel recipe) { + public void toNetwork(PacketBuffer buffer, BorklerFuel recipe) { buffer.writeFluidStack(new FluidStack(recipe.fluid, 1)); buffer.writeInt(recipe.burnTime); } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 20f01fe..0cc54b9 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -19,7 +19,7 @@ modId="borkler" #mandatory # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it # ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata # see the associated build.gradle script for how to populate this completely automatically during a build -version="0.2.2" #mandatory +version="0.2.3" #mandatory # A display name for the mod displayName="Borkler" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/