From dd9acfcb942cf4fc35ad1babb87c0bd0dfdbc291 Mon Sep 17 00:00:00 2001 From: DaCodia Date: Wed, 7 Aug 2024 23:39:18 -0500 Subject: [PATCH] mango deserves the death penalty istg --- .../drmangotea/createindustry/CreateTFMG.java | 7 +- .../TFMGCreativeModeTab.java | 4 +- .../base/util/CombinedStorageWrapper.java | 21 ++ .../createindustry/base/util/TFMGUtils.java | 35 +- .../base/util/spark/BlueSpark.java | 3 +- .../base/util/spark/GreenSpark.java | 4 +- .../createindustry/base/util/spark/Spark.java | 4 +- .../blocks/electricity/api/Energy.java | 44 ++- .../blocks/electricity/api/EnergyStorage.java | 24 -- .../base/ConverterBlockEntity.java | 5 - .../electricity/base/IElectricBlock.java | 175 +++------- .../base/TFMGForgeEnergyStorage.java | 49 --- .../cables/CableConnectorBlockEntity.java | 1 - .../cables/test/ElectricalNetworkMember.java | 3 - .../CopycatCableBlock.java | 3 +- .../CopycatCableBlockEntity.java | 1 - .../ElectricMotorBlockEntity.java | 1 - .../diesel/DieselEngineBlockEntity.java | 26 +- .../blocks/fluids/HotFluidType.java | 1 - .../machines/TFMGMachineBlockEntity.java | 10 +- .../BlastFurnaceOutputBlockEntity.java | 14 +- .../DistillationControllerBlockEntity.java | 18 +- .../output/DistillationOutputBlockEntity.java | 12 +- .../base/PumpjackBaseBlockEntity.java | 50 +-- .../welding_machine/WeldingBehaviour.java | 2 +- .../blocks/tanks/SteelFluidTankModel.java | 52 ++- .../blocks/tanks/SteelFluidTankRenderer.java | 44 +-- .../blocks/tanks/SteelTankBlock.java | 326 +++++++++--------- .../blocks/tanks/SteelTankBlockEntity.java | 31 +- .../createindustry/events/ClientEvents.java | 18 + .../AdvancedPotatoCannonItem.java | 12 +- .../AdvancedPotatoCannonItemRenderer.java | 2 - .../flamethrover/FlamethrowerItem.java | 5 +- .../QuadPotatoCannonItem.java | 8 +- .../QuadPotatoCannonItemRenderer.java | 1 + 35 files changed, 458 insertions(+), 558 deletions(-) create mode 100644 src/main/java/com/drmangotea/createindustry/base/util/CombinedStorageWrapper.java delete mode 100644 src/main/java/com/drmangotea/createindustry/blocks/electricity/api/EnergyStorage.java delete mode 100644 src/main/java/com/drmangotea/createindustry/blocks/electricity/base/TFMGForgeEnergyStorage.java create mode 100644 src/main/java/com/drmangotea/createindustry/events/ClientEvents.java diff --git a/src/main/java/com/drmangotea/createindustry/CreateTFMG.java b/src/main/java/com/drmangotea/createindustry/CreateTFMG.java index 7cc24b51..79700357 100644 --- a/src/main/java/com/drmangotea/createindustry/CreateTFMG.java +++ b/src/main/java/com/drmangotea/createindustry/CreateTFMG.java @@ -28,10 +28,9 @@ public class CreateTFMG implements ModInitializer { public static final Logger LOGGER = LogUtils.getLogger(); static { - REGISTRATE.setTooltipModifierFactory(item -> { - return new ItemDescription.Modifier(item, TooltipHelper.Palette.STANDARD_CREATE) - .andThen(TooltipModifier.mapNull(KineticStats.create(item))); - }); + REGISTRATE.setTooltipModifierFactory(item -> + new ItemDescription.Modifier(item, TooltipHelper.Palette.STANDARD_CREATE) + .andThen(TooltipModifier.mapNull(KineticStats.create(item)))); } @Override diff --git a/src/main/java/com/drmangotea/createindustry/base/creative_mode_tabs/TFMGCreativeModeTab.java b/src/main/java/com/drmangotea/createindustry/base/creative_mode_tabs/TFMGCreativeModeTab.java index 192a9c47..0407ec5b 100644 --- a/src/main/java/com/drmangotea/createindustry/base/creative_mode_tabs/TFMGCreativeModeTab.java +++ b/src/main/java/com/drmangotea/createindustry/base/creative_mode_tabs/TFMGCreativeModeTab.java @@ -4,8 +4,10 @@ import java.util.Collection; import com.drmangotea.createindustry.CreateTFMG; import com.simibubi.create.compat.jei.CreateJEI; +import com.simibubi.create.infrastructure.item.CreateCreativeModeTab; import com.tterrag.registrate.util.entry.RegistryEntry; +import io.github.fabricators_of_create.porting_lib.util.ItemGroupUtil; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.entity.ItemRenderer; import net.minecraft.client.resources.model.BakedModel; @@ -18,7 +20,7 @@ import net.minecraft.world.item.ItemStack; public abstract class TFMGCreativeModeTab extends CreativeModeTab { public TFMGCreativeModeTab(String id) { - super(CreateTFMG.MOD_ID + "." + id); + super(ItemGroupUtil.expandArrayAndGetId(), CreateTFMG.MOD_ID + "." + id); } @Override diff --git a/src/main/java/com/drmangotea/createindustry/base/util/CombinedStorageWrapper.java b/src/main/java/com/drmangotea/createindustry/base/util/CombinedStorageWrapper.java new file mode 100644 index 00000000..7228e197 --- /dev/null +++ b/src/main/java/com/drmangotea/createindustry/base/util/CombinedStorageWrapper.java @@ -0,0 +1,21 @@ +package com.drmangotea.createindustry.base.util; + +import com.simibubi.create.foundation.fluid.CombinedTankWrapper; +import com.simibubi.create.foundation.item.SmartInventory; +import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.Storage; +import net.fabricmc.fabric.api.transfer.v1.storage.base.CombinedStorage; + +import java.util.Arrays; + +public class CombinedStorageWrapper extends CombinedStorage> { + + @SafeVarargs + public CombinedStorageWrapper(Storage... parts) { + super(Arrays.stream(parts).toList()); + } + +// public CombinedStorageWrapper(SmartInventory... invs) { +// super(); +// } +} diff --git a/src/main/java/com/drmangotea/createindustry/base/util/TFMGUtils.java b/src/main/java/com/drmangotea/createindustry/base/util/TFMGUtils.java index 6a5fa813..c665bd0b 100644 --- a/src/main/java/com/drmangotea/createindustry/base/util/TFMGUtils.java +++ b/src/main/java/com/drmangotea/createindustry/base/util/TFMGUtils.java @@ -4,14 +4,20 @@ import com.drmangotea.createindustry.base.ElectricSparkParticle; import com.drmangotea.createindustry.base.util.spark.Spark; import com.drmangotea.createindustry.registry.TFMGEntityTypes; import com.simibubi.create.Create; -import com.simibubi.create.foundation.utility.VecHelper; +import io.github.fabricators_of_create.porting_lib.mixin.common.ProjectileUtilMixin; +import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil; +import io.github.fabricators_of_create.porting_lib.transfer.fluid.FluidTank; +import io.github.fabricators_of_create.porting_lib.util.FluidStack; +import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; import net.minecraft.core.BlockPos; import net.minecraft.util.Mth; import net.minecraft.util.RandomSource; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityEvent; +import net.minecraft.world.entity.projectile.ProjectileUtil; import net.minecraft.world.level.Explosion; +import net.minecraft.world.level.GameRules; import net.minecraft.world.level.Level; -import net.minecraft.world.phys.Vec3; import org.apache.commons.lang3.StringUtils; import java.util.Arrays; @@ -70,4 +76,29 @@ public class TFMGUtils { } } + public static void drain(FluidTank tank, long amount) { + try (Transaction t = TransferUtil.getTransaction()) { + tank.extract(tank.variant, amount, t); + t.commit(); + } + } + + public static long fill(FluidTank tank, FluidStack fluid) { + if (!tank.isEmpty() && tank.variant != fluid.getType()) + throw new RuntimeException("fluid variant being filled into tank isn't the same variant as the fluid in the tank"); + try (Transaction t = TransferUtil.getTransaction()) { + tank.insert(fluid.getType(), fluid.getAmount(), t); + t.commit(); + } + return fluid.getAmount(); + } + +// public static boolean mobGriefingEvent(Level level, Entity entity) { +// EntityEvent event = ProjectileUtil.; +// MinecraftForge.EVENT_BUS.post(event); +// boolean result = event.getResult(); +// return result == Result.DEFAULT ? level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) : result == Result.ALLOW; +// } + + } diff --git a/src/main/java/com/drmangotea/createindustry/base/util/spark/BlueSpark.java b/src/main/java/com/drmangotea/createindustry/base/util/spark/BlueSpark.java index 855ec286..db582da7 100644 --- a/src/main/java/com/drmangotea/createindustry/base/util/spark/BlueSpark.java +++ b/src/main/java/com/drmangotea/createindustry/base/util/spark/BlueSpark.java @@ -13,6 +13,7 @@ import net.minecraft.core.particles.ParticleTypes; import net.minecraft.world.entity.*; import net.minecraft.world.entity.projectile.ThrowableProjectile; import net.minecraft.world.item.Item; +import net.minecraft.world.level.GameRules; import net.minecraft.world.level.Level; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.EntityHitResult; @@ -78,7 +79,7 @@ public class BlueSpark extends ThrowableProjectile { super.onHitBlock(p_37384_); if (!this.level.isClientSide) { Entity entity = this.getOwner(); - if (!(entity instanceof Mob) || mobGriefingEvent(this.level, this)) { + if (!(entity instanceof Mob) || level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { BlockPos blockpos = p_37384_.getBlockPos().relative(p_37384_.getDirection()); if (this.level.isEmptyBlock(blockpos)) { this.level.setBlockAndUpdate(blockpos, BlueFireBlock.getState(this.level, blockpos)); diff --git a/src/main/java/com/drmangotea/createindustry/base/util/spark/GreenSpark.java b/src/main/java/com/drmangotea/createindustry/base/util/spark/GreenSpark.java index 97ed1011..f5344183 100644 --- a/src/main/java/com/drmangotea/createindustry/base/util/spark/GreenSpark.java +++ b/src/main/java/com/drmangotea/createindustry/base/util/spark/GreenSpark.java @@ -1,7 +1,6 @@ package com.drmangotea.createindustry.base.util.spark; -import com.drmangotea.createindustry.items.weapons.explosives.pipe_bomb.PipeBomb; import com.drmangotea.createindustry.items.weapons.explosives.thermite_grenades.fire.GreenFireBlock; import com.drmangotea.createindustry.registry.TFMGEntityTypes; import com.drmangotea.createindustry.registry.TFMGItems; @@ -13,6 +12,7 @@ import net.minecraft.core.particles.ParticleTypes; import net.minecraft.world.entity.*; import net.minecraft.world.entity.projectile.ThrowableProjectile; import net.minecraft.world.item.Item; +import net.minecraft.world.level.GameRules; import net.minecraft.world.level.Level; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.EntityHitResult; @@ -78,7 +78,7 @@ public class GreenSpark extends ThrowableProjectile { super.onHitBlock(p_37384_); if (!this.level.isClientSide) { Entity entity = this.getOwner(); - if (!(entity instanceof Mob) || net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(this.level, this)) { + if (!(entity instanceof Mob) || level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { BlockPos blockpos = p_37384_.getBlockPos().relative(p_37384_.getDirection()); if (this.level.isEmptyBlock(blockpos)) { this.level.setBlockAndUpdate(blockpos, GreenFireBlock.getState(this.level, blockpos)); diff --git a/src/main/java/com/drmangotea/createindustry/base/util/spark/Spark.java b/src/main/java/com/drmangotea/createindustry/base/util/spark/Spark.java index 53adff08..15be6360 100644 --- a/src/main/java/com/drmangotea/createindustry/base/util/spark/Spark.java +++ b/src/main/java/com/drmangotea/createindustry/base/util/spark/Spark.java @@ -1,7 +1,6 @@ package com.drmangotea.createindustry.base.util.spark; -import com.drmangotea.createindustry.items.weapons.explosives.pipe_bomb.PipeBomb; import com.drmangotea.createindustry.registry.TFMGEntityTypes; import com.drmangotea.createindustry.registry.TFMGItems; import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder; @@ -11,6 +10,7 @@ import net.minecraft.core.particles.ParticleTypes; import net.minecraft.world.entity.*; import net.minecraft.world.entity.projectile.ThrowableProjectile; import net.minecraft.world.item.Item; +import net.minecraft.world.level.GameRules; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.BaseFireBlock; import net.minecraft.world.phys.BlockHitResult; @@ -74,7 +74,7 @@ public class Spark extends ThrowableProjectile { super.onHitBlock(p_37384_); if (!this.level.isClientSide) { Entity entity = this.getOwner(); - if (!(entity instanceof Mob) || net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(this.level, this)) { + if (!(entity instanceof Mob) || level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { BlockPos blockpos = p_37384_.getBlockPos().relative(p_37384_.getDirection()); if (this.level.isEmptyBlock(blockpos)) { this.level.setBlockAndUpdate(blockpos, BaseFireBlock.getState(this.level, blockpos)); diff --git a/src/main/java/com/drmangotea/createindustry/blocks/electricity/api/Energy.java b/src/main/java/com/drmangotea/createindustry/blocks/electricity/api/Energy.java index 1d3f7082..61e9f4cd 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/electricity/api/Energy.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/electricity/api/Energy.java @@ -1,33 +1,39 @@ package com.drmangotea.createindustry.blocks.electricity.api; -import net.fabricmc.fabric.api.transfer.v1.storage.TransferVariant; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import org.jetbrains.annotations.Nullable; +import com.drmangotea.createindustry.blocks.electricity.base.IElectricBlock; -public class Energy implements TransferVariant { - @Override - public boolean isBlank() { - return false; +import static org.apache.commons.lang3.ObjectUtils.min; + +public class Energy { + long voltage; + long current; + + public Energy(long voltage, long current) { + this.current = current; + this.voltage = current; } - @Override - public Double getObject() { - return null; + public long getVoltage() { + return voltage; } - @Override - public @Nullable CompoundTag getNbt() { - return null; + public long getCurrent() { + return current; } - @Override - public CompoundTag toNbt() { - return null; + public long discharge(long amount, boolean simulate) { + + return amount; } - @Override - public void toPacket(FriendlyByteBuf buf) { + public long charge(long amount, boolean simulate) { + return amount; + } + + public long transfer(IElectricBlock to, long amount, boolean simulate) { + long discharge = discharge(amount, true); + long charge = to.getStorage().charge(amount, true); + return min(discharge, charge); } } diff --git a/src/main/java/com/drmangotea/createindustry/blocks/electricity/api/EnergyStorage.java b/src/main/java/com/drmangotea/createindustry/blocks/electricity/api/EnergyStorage.java deleted file mode 100644 index ecb5e4d3..00000000 --- a/src/main/java/com/drmangotea/createindustry/blocks/electricity/api/EnergyStorage.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.drmangotea.createindustry.blocks.electricity.api; - -import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleVariantStorage; -import org.jetbrains.annotations.ApiStatus; - -@ApiStatus.Experimental -public class EnergyStorage extends SingleVariantStorage { - - - public EnergyStorage(long i) { - this.variant = new Energy(); - this.amount = i; - } - - @Override - protected Energy getBlankVariant() { - return null; - } - - @Override - protected long getCapacity(Energy variant) { - return 0; - } -} diff --git a/src/main/java/com/drmangotea/createindustry/blocks/electricity/base/ConverterBlockEntity.java b/src/main/java/com/drmangotea/createindustry/blocks/electricity/base/ConverterBlockEntity.java index 219b1b45..08620bfe 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/electricity/base/ConverterBlockEntity.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/electricity/base/ConverterBlockEntity.java @@ -28,11 +28,6 @@ public class ConverterBlockEntity extends ElectricBlockEntity { @Override public void tick() { super.tick(); - - - - - } @Override diff --git a/src/main/java/com/drmangotea/createindustry/blocks/electricity/base/IElectricBlock.java b/src/main/java/com/drmangotea/createindustry/blocks/electricity/base/IElectricBlock.java index bd5c1457..d005b180 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/electricity/base/IElectricBlock.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/electricity/base/IElectricBlock.java @@ -1,9 +1,7 @@ package com.drmangotea.createindustry.blocks.electricity.base; -import com.drmangotea.createindustry.CreateTFMG; -import com.drmangotea.createindustry.blocks.electricity.capacitor.CapacitorBlockEntity; +import com.drmangotea.createindustry.blocks.electricity.api.Energy; import com.drmangotea.createindustry.blocks.electricity.resistors.ResistorBlockEntity; -import com.drmangotea.createindustry.registry.TFMGBlocks; import com.simibubi.create.Create; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -13,24 +11,18 @@ import net.minecraft.world.level.block.entity.BlockEntity; public interface IElectricBlock { - - float internalResistance(); + Energy getStorage(); + int getVoltage(); - boolean gotFElastTick(int value); - int getCurrent(); - - int feGeneration(); - int voltageGeneration(); int transferSpeed(); - void addVoltage(float amount); default float getCharge(){ @@ -41,22 +33,14 @@ public interface IElectricBlock { return false; } - TFMGForgeEnergyStorage getForgeEnergy(); - boolean hasElectricitySlot(Direction direction); - float maxVoltage(); void explode(); - int FECapacity(); - - int getDistanceFromSource(); - - void setDistanceFromSource(int value); void sendStuff(); @@ -75,8 +59,6 @@ public interface IElectricBlock { boolean getsVoltageFromNonTFMGBlock = false; - - if(canBeDisabled()){ @@ -92,37 +74,29 @@ public interface IElectricBlock { if(be1 instanceof IElectricBlock be2){ - - if(be2.hasElectricitySlot(direction.getOpposite())) { - - int distance = be2.getDistanceFromSource(); if(!isStorage()&&be2.isStorage()&&direction == Direction.UP) distance = Integer.MAX_VALUE; - if(getVoltage()==0) { if(distance>getDistanceFromSource()) be2.addVoltage(getVoltage()); } if(!(be2 instanceof ConverterBlockEntity)) - if(!(isStorage()&&direction == Direction.DOWN)) - if(!(!isStorage()&&be2.isStorage()&&direction == Direction.DOWN)) - if(getVoltage()!=0) { - // if(Create.RANDOM.nextInt(3) ==1) - transferCharge(be2); - if(distance>getDistanceFromSource()){ - be2.addVoltage(getVoltage()); - } - } - - lowestDistance = Math.min(lowestDistance,distance); - + if(!(isStorage()&&direction == Direction.DOWN)) + if(!(!isStorage()&&be2.isStorage()&&direction == Direction.DOWN)) + if(getVoltage()!=0) { + // if(Create.RANDOM.nextInt(3) ==1) + transferCharge(be2); + if(distance>getDistanceFromSource()) + be2.addVoltage(getVoltage()); + } + lowestDistance = Math.min(lowestDistance,distance); } if(direction.getAxis().isHorizontal()) { if (be2 instanceof ResistorBlockEntity resistorBE) @@ -133,11 +107,7 @@ public interface IElectricBlock { } - - - }else - - if(be1!=null) { + } else if(be1!=null) { if (be1.getCapability(ForgeCapabilities.ENERGY, direction.getOpposite()).isPresent()) { if (!(be1.getCapability(ForgeCapabilities.ENERGY, direction.getOpposite()).orElse(new EnergyStorage(0)) instanceof TFMGForgeEnergyStorage)) { @@ -216,114 +186,47 @@ public interface IElectricBlock { addVoltage(0); } - +//PLUH default void transferCharge(IElectricBlock be) { - - - - if(!isStorage()) { - if (be.getDistanceFromSource() > getDistanceFromSource()||be.isStorage()) { - - //int amount = getForgeEnergy().extractEnergy(transferSpeed(), true); - //int amount2 = be.getForgeEnergy().receiveEnergy( transferSpeed(), true); - - - - - - int amount = getForgeEnergy().extractEnergy(transferSpeed()*100, true); - int amount2 = be.getForgeEnergy().receiveEnergy(transferSpeed()*100, true); - - - getForgeEnergy().extractEnergy(Math.min(amount, amount2), false); - be.getForgeEnergy().receiveEnergy(Math.min(amount, amount2), false); - } - if(be.getDistanceFromSource()==getDistanceFromSource()&&getForgeEnergy().getEnergyStored()>be.getForgeEnergy().getEnergyStored()){ - - int diff = Math.abs(getForgeEnergy().getEnergyStored()-be.getForgeEnergy().getEnergyStored()); - - int amount = getForgeEnergy().extractEnergy(diff / 2, true); - int amount2 = be.getForgeEnergy().receiveEnergy( diff / 2, true); - getForgeEnergy().extractEnergy( Math.min(amount,amount2), false); - be.getForgeEnergy().receiveEnergy( Math.min(amount,amount2), false); + boolean hasHigherVoltage = getStorage().getVoltage() > be.getStorage().getVoltage(); + if(isStorage()) { + if(be.isStorage() && !hasHigherVoltage) { + long amount = getStorage().transfer(be, transferSpeed() * 10, true); + getStorage().transfer(be, amount, false); + } else { + long amount = be.getStorage().transfer(be, transferSpeed(), true); + getStorage().transfer(be, amount, false); } + } else { + if (be.getDistanceFromSource() > getDistanceFromSource() || be.isStorage()) { + long amount = getStorage().transfer(be, transferSpeed()*100, true); + getStorage().transfer(be, amount, false); + } + if(be.getDistanceFromSource() == getDistanceFromSource() && hasHigherVoltage){ + long diff = Math.abs(getStorage().getVoltage() - be.getStorage().getVoltage()); + long amount = getStorage().transfer(be, diff / 2, true); + getStorage().transfer(be, amount, false); + } } - - if(isStorage()){ - if(be.isStorage()){ - - if(!be.isStorage()||(be.isStorage()&&be.getForgeEnergy().getEnergyStored()=getDistanceFromSource()) { - int amount = getForgeEnergy().extractEnergy(transferSpeed()*10, true); - int amount2 = be.getForgeEnergy().receiveEnergy(transferSpeed()*10, true); - - - getForgeEnergy().extractEnergy(Math.min(amount, amount2), false); - be.getForgeEnergy().receiveEnergy(Math.min(amount, amount2), false); - } - - }else { - int amount = getForgeEnergy().extractEnergy(transferSpeed(), true); - int amount2 = be.getForgeEnergy().receiveEnergy(transferSpeed(), true); - - - //if(be.getForgeEnergy().getEnergyStored()0) - onEnergyChanged(energy,true); - - return 0; - } - - public abstract void onEnergyChanged(int amount, boolean setEnergy); -} \ No newline at end of file diff --git a/src/main/java/com/drmangotea/createindustry/blocks/electricity/base/cables/CableConnectorBlockEntity.java b/src/main/java/com/drmangotea/createindustry/blocks/electricity/base/cables/CableConnectorBlockEntity.java index d23cefa8..f1d0138f 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/electricity/base/cables/CableConnectorBlockEntity.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/electricity/base/cables/CableConnectorBlockEntity.java @@ -1,7 +1,6 @@ package com.drmangotea.createindustry.blocks.electricity.base.cables; import com.drmangotea.createindustry.base.TFMGTools; -import com.drmangotea.createindustry.blocks.electricity.api.EnergyStorage; import com.drmangotea.createindustry.blocks.electricity.base.*; import com.drmangotea.createindustry.blocks.electricity.resistors.ResistorBlockEntity; import com.drmangotea.createindustry.registry.TFMGItems; diff --git a/src/main/java/com/drmangotea/createindustry/blocks/electricity/base/cables/test/ElectricalNetworkMember.java b/src/main/java/com/drmangotea/createindustry/blocks/electricity/base/cables/test/ElectricalNetworkMember.java index 66895b2f..db96f504 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/electricity/base/cables/test/ElectricalNetworkMember.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/electricity/base/cables/test/ElectricalNetworkMember.java @@ -1,11 +1,8 @@ package com.drmangotea.createindustry.blocks.electricity.base.cables.test; -import com.drmangotea.createindustry.blocks.electricity.base.TFMGForgeEnergyStorage; - public class ElectricalNetworkMember { public int voltage; - public TFMGForgeEnergyStorage energy; } diff --git a/src/main/java/com/drmangotea/createindustry/blocks/electricity/cable_blocks/copycat_cable_block/CopycatCableBlock.java b/src/main/java/com/drmangotea/createindustry/blocks/electricity/cable_blocks/copycat_cable_block/CopycatCableBlock.java index 070855fb..b41ff53c 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/electricity/cable_blocks/copycat_cable_block/CopycatCableBlock.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/electricity/cable_blocks/copycat_cable_block/CopycatCableBlock.java @@ -7,6 +7,7 @@ import com.simibubi.create.AllTags; import com.simibubi.create.content.decoration.copycat.CopycatModel; import com.simibubi.create.content.equipment.wrench.IWrenchable; import com.simibubi.create.foundation.block.IBE; +import io.github.fabricators_of_create.porting_lib.block.CustomSoundTypeBlock; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; @@ -38,7 +39,7 @@ import net.minecraft.world.phys.shapes.VoxelShape; import javax.annotation.Nullable; -public class CopycatCableBlock extends Block implements IBE, IWrenchable { +public class CopycatCableBlock extends Block implements IBE, IWrenchable, CustomSoundTypeBlock { public CopycatCableBlock(Properties pProperties) { super(pProperties); diff --git a/src/main/java/com/drmangotea/createindustry/blocks/electricity/cable_blocks/copycat_cable_block/CopycatCableBlockEntity.java b/src/main/java/com/drmangotea/createindustry/blocks/electricity/cable_blocks/copycat_cable_block/CopycatCableBlockEntity.java index f25eb245..f1d09aa5 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/electricity/cable_blocks/copycat_cable_block/CopycatCableBlockEntity.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/electricity/cable_blocks/copycat_cable_block/CopycatCableBlockEntity.java @@ -2,7 +2,6 @@ package com.drmangotea.createindustry.blocks.electricity.cable_blocks.copycat_ca import com.drmangotea.createindustry.base.util.TFMGUtils; import com.drmangotea.createindustry.blocks.electricity.base.IElectricBlock; -import com.drmangotea.createindustry.blocks.electricity.base.TFMGForgeEnergyStorage; import com.simibubi.create.content.decoration.copycat.CopycatBlockEntity; import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; import net.minecraft.core.BlockPos; diff --git a/src/main/java/com/drmangotea/createindustry/blocks/electricity/electric_motor/ElectricMotorBlockEntity.java b/src/main/java/com/drmangotea/createindustry/blocks/electricity/electric_motor/ElectricMotorBlockEntity.java index 0aaa7916..6e119a2e 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/electricity/electric_motor/ElectricMotorBlockEntity.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/electricity/electric_motor/ElectricMotorBlockEntity.java @@ -2,7 +2,6 @@ package com.drmangotea.createindustry.blocks.electricity.electric_motor; import com.drmangotea.createindustry.base.util.TFMGUtils; import com.drmangotea.createindustry.blocks.electricity.base.IElectricBlock; -import com.drmangotea.createindustry.blocks.electricity.base.TFMGForgeEnergyStorage; import com.drmangotea.createindustry.registry.TFMGBlocks; import com.jozufozu.flywheel.util.transform.TransformStack; import com.mojang.blaze3d.vertex.PoseStack; diff --git a/src/main/java/com/drmangotea/createindustry/blocks/engines/diesel/DieselEngineBlockEntity.java b/src/main/java/com/drmangotea/createindustry/blocks/engines/diesel/DieselEngineBlockEntity.java index 01173a2b..cc76dc8e 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/engines/diesel/DieselEngineBlockEntity.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/engines/diesel/DieselEngineBlockEntity.java @@ -24,6 +24,7 @@ import io.github.fabricators_of_create.porting_lib.util.LazyOptional; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.Storage; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -43,7 +44,9 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.lang.ref.WeakReference; import java.util.List; +import java.util.Optional; +import static com.drmangotea.createindustry.base.util.TFMGUtils.fill; import static com.drmangotea.createindustry.blocks.engines.diesel.DieselEngineBlock.FACE; import static net.minecraft.world.level.block.HorizontalDirectionalBlock.FACING; @@ -340,8 +343,8 @@ public class DieselEngineBlockEntity extends SmartBlockEntity implements IHaveGo //airTank.drain(1, IFluidHandler.FluidAction.EXECUTE); if(!airTank.isEmpty()) { airTank.setFluid(new FluidStack(FluidVariant.of(TFMGFluids.AIR.getSource()), airTank.getFluidAmount() - 5)); - }else expansionBE.airTank.setFluid(new FluidStack(TFMGFluids.AIR.getSource(), expansionBE.airTank.getFluidAmount() - 5)); - exhaustTank.fill(new FluidStack(FluidVariant.of(TFMGFluids.CARBON_DIOXIDE.getSource()),3), IFluidHandler.FluidAction.EXECUTE); + }else expansionBE.airTank.setFluid(new FluidStack(FluidVariant.of(TFMGFluids.AIR.getSource()), expansionBE.airTank.getFluidAmount() - 5)); + fill(exhaustTank, new FluidStack(FluidVariant.of(TFMGFluids.CARBON_DIOXIDE.getSource()),3)); //tanks.get(false).setFluid(new FluidStack(TFMGFluids.CARBON_DIOXIDE.getSource(), tanks.get(false).getFluidAmount()+1)); @@ -517,13 +520,13 @@ public class DieselEngineBlockEntity extends SmartBlockEntity implements IHaveGo //--Fluid Info--// - LazyOptional handler = this.getCapability(ForgeCapabilities.FLUID_HANDLER); - Optional resolve = handler.resolve(); + LazyOptional handler = fluidCapability; + Optional resolve = handler.resolve(); if (!resolve.isPresent()) return false; - IFluidHandler tank = resolve.get(); - if (tank.getTanks() == 0) + CombinedTankWrapper tanks = resolve.get(); + if (tanks.parts.isEmpty()) return false; LangBuilder mb = Lang.translate("generic.unit.millibuckets"); @@ -532,8 +535,9 @@ public class DieselEngineBlockEntity extends SmartBlockEntity implements IHaveGo .forGoggles(tooltip); boolean isEmpty = true; - for (int i = 0; i < tank.getTanks(); i++) { - FluidStack fluidStack = tank.getFluidInTank(i); + for (int i = 0; i < tanks.parts.size(); i++) { + Storage tank = tanks.parts.get(i); + FluidStack fluidStack = tank.iterator(); if (fluidStack.isEmpty()) continue; @@ -546,7 +550,7 @@ public class DieselEngineBlockEntity extends SmartBlockEntity implements IHaveGo .add(mb) .style(ChatFormatting.DARK_GREEN)) .text(ChatFormatting.GRAY, " / ") - .add(Lang.number(tank.getTankCapacity(i)) + .add(Lang.number(tanks.getTankCapacity(i)) .add(mb) .style(ChatFormatting.DARK_GRAY)) .forGoggles(tooltip, 1); @@ -554,7 +558,7 @@ public class DieselEngineBlockEntity extends SmartBlockEntity implements IHaveGo isEmpty = false; } - if (tank.getTanks() > 1) { + if (tanks.getTanks() > 1) { if (isEmpty) tooltip.remove(tooltip.size() - 1); return true; @@ -564,7 +568,7 @@ public class DieselEngineBlockEntity extends SmartBlockEntity implements IHaveGo return true; Lang.translate("gui.goggles.fluid_container.capacity") - .add(Lang.number(tank.getTankCapacity(0)) + .add(Lang.number(tanks.getTankCapacity(0)) .add(mb) .style(ChatFormatting.DARK_GREEN)) .style(ChatFormatting.DARK_GRAY) diff --git a/src/main/java/com/drmangotea/createindustry/blocks/fluids/HotFluidType.java b/src/main/java/com/drmangotea/createindustry/blocks/fluids/HotFluidType.java index ee9a3175..cc57e908 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/fluids/HotFluidType.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/fluids/HotFluidType.java @@ -13,7 +13,6 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.phys.Vec3; -import net.minecraftforge.fluids.FluidStack; import java.util.function.Supplier; diff --git a/src/main/java/com/drmangotea/createindustry/blocks/machines/TFMGMachineBlockEntity.java b/src/main/java/com/drmangotea/createindustry/blocks/machines/TFMGMachineBlockEntity.java index 7d6223f9..2d19e622 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/machines/TFMGMachineBlockEntity.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/machines/TFMGMachineBlockEntity.java @@ -12,6 +12,8 @@ import com.simibubi.create.foundation.utility.LangBuilder; import io.github.fabricators_of_create.porting_lib.transfer.fluid.FluidTank; import io.github.fabricators_of_create.porting_lib.util.FluidStack; import io.github.fabricators_of_create.porting_lib.util.LazyOptional; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.Storage; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -31,7 +33,7 @@ public class TFMGMachineBlockEntity extends SmartBlockEntity implements IHaveGo private boolean contentsChanged; - protected LazyOptional fluidCapability; + protected LazyOptional fluidCapability; public TFMGMachineBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); @@ -68,9 +70,9 @@ public class TFMGMachineBlockEntity extends SmartBlockEntity implements IHaveGo behaviours.add(tank2); fluidCapability = LazyOptional.of(() -> { - LazyOptional inputCap = tank1.getCapability(); - LazyOptional outputCap = tank2.getCapability(); - return new CombinedTankWrapper(outputCap.orElse(null), inputCap.orElse(null)); + Storage inputCap = tank1.getCapability(); + Storage outputCap = tank2.getCapability(); + return new CombinedTankWrapper(outputCap, inputCap); }); diff --git a/src/main/java/com/drmangotea/createindustry/blocks/machines/metal_processing/blast_furnace/BlastFurnaceOutputBlockEntity.java b/src/main/java/com/drmangotea/createindustry/blocks/machines/metal_processing/blast_furnace/BlastFurnaceOutputBlockEntity.java index 19c565c4..0a8dd286 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/machines/metal_processing/blast_furnace/BlastFurnaceOutputBlockEntity.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/machines/metal_processing/blast_furnace/BlastFurnaceOutputBlockEntity.java @@ -1,5 +1,6 @@ package com.drmangotea.createindustry.blocks.machines.metal_processing.blast_furnace; +import com.drmangotea.createindustry.base.util.CombinedStorageWrapper; import com.drmangotea.createindustry.blocks.machines.TFMGMachineBlockEntity; import com.drmangotea.createindustry.recipes.industrial_blasting.IndustrialBlastingRecipe; import com.drmangotea.createindustry.registry.TFMGBlocks; @@ -7,19 +8,25 @@ import com.drmangotea.createindustry.registry.TFMGItems; import com.drmangotea.createindustry.registry.TFMGRecipeTypes; import com.simibubi.create.Create; import com.simibubi.create.content.equipment.goggles.IHaveGoggleInformation; +import com.simibubi.create.content.logistics.depot.DepotBlockEntity; import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; import com.simibubi.create.foundation.item.ItemHelper; import com.simibubi.create.foundation.item.SmartInventory; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.animation.LerpedFloat; +import io.github.fabricators_of_create.porting_lib.transfer.item.ItemStackHandler; import io.github.fabricators_of_create.porting_lib.transfer.item.RecipeWrapper; import io.github.fabricators_of_create.porting_lib.util.LazyOptional; +import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.Storage; +import net.fabricmc.fabric.api.transfer.v1.storage.base.CombinedStorage; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntityType; @@ -27,6 +34,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; import javax.annotation.Nonnull; +import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -58,14 +66,12 @@ public class BlastFurnaceOutputBlockEntity extends TFMGMachineBlockEntity implem public LerpedFloat coalCokeHeight = LerpedFloat.linear(); //item storage - public LazyOptional itemCapability; + public LazyOptional itemCapability; public SmartInventory inputInventory; public SmartInventory fuelInventory; - int debug = 0; - @@ -79,7 +85,7 @@ public class BlastFurnaceOutputBlockEntity extends TFMGMachineBlockEntity implem fuelInventory = new SmartInventory(1, this).forbidInsertion().forbidExtraction() .withMaxStackSize(64); - itemCapability = LazyOptional.of(() -> new Combined(inputInventory,fuelInventory)); + itemCapability = LazyOptional.of(() -> new CombinedStorageWrapper(inputInventory, fuelInventory)); tank1.getPrimaryHandler().setCapacity(8000); diff --git a/src/main/java/com/drmangotea/createindustry/blocks/machines/oil_processing/distillation/controller/DistillationControllerBlockEntity.java b/src/main/java/com/drmangotea/createindustry/blocks/machines/oil_processing/distillation/controller/DistillationControllerBlockEntity.java index 81d2b5cc..f123efcc 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/machines/oil_processing/distillation/controller/DistillationControllerBlockEntity.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/machines/oil_processing/distillation/controller/DistillationControllerBlockEntity.java @@ -5,14 +5,18 @@ import com.drmangotea.createindustry.blocks.tanks.SteelTankBlockEntity; import com.drmangotea.createindustry.recipes.distillation.DistillationRecipe; import com.drmangotea.createindustry.registry.TFMGBlocks; import com.simibubi.create.content.equipment.goggles.IHaveGoggleInformation; +import com.simibubi.create.content.fluids.pipes.FluidPipeBlock; +import com.simibubi.create.content.fluids.pump.PumpBlock; import com.simibubi.create.foundation.blockEntity.SmartBlockEntity; import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; import com.simibubi.create.foundation.fluid.SmartFluidTank; import com.simibubi.create.foundation.recipe.RecipeFinder; import com.simibubi.create.foundation.utility.Lang; +import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil; import io.github.fabricators_of_create.porting_lib.transfer.fluid.FluidTank; import io.github.fabricators_of_create.porting_lib.util.FluidStack; import io.github.fabricators_of_create.porting_lib.util.LazyOptional; +import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -29,6 +33,8 @@ import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.List; +import static com.drmangotea.createindustry.base.util.TFMGUtils.fill; + public class DistillationControllerBlockEntity extends SmartBlockEntity implements IHaveGoggleInformation { private static final Object DistillationRecipesKey = new Object(); @@ -99,7 +105,7 @@ public class DistillationControllerBlockEntity extends SmartBlockEntity implemen for(DistillationOutputBlockEntity be1 : outputs){ - if(be1.tank==0) + if(be1.tank.isEmpty()) return; } @@ -114,15 +120,17 @@ public class DistillationControllerBlockEntity extends SmartBlockEntity implemen if(fluidStack.isEmpty()) break; - if(output.tank.fill(new FluidStack(fluidStack, (int) (fluidStack.getAmount()*speedModifier)), IFluidHandler.FluidAction.SIMULATE)>output.tank.getCapacity()) + if(fill(output.tank, new FluidStack(fluidStack, (int) (fluidStack.getAmount()*speedModifier)))>output.tank.getCapacity()) break; - output.tank.fill(new FluidStack(fluidStack, (int) (fluidStack.getAmount()*speedModifier)), IFluidHandler.FluidAction.EXECUTE); + fill(output.tank, new FluidStack(fluidStack, (int) (fluidStack.getAmount()*speedModifier))); int consumption = (recipe.getInputFluid().getRequiredAmount()/6); - - tank.drain((int) (consumption*speedModifier), IFluidHandler.FluidAction.EXECUTE); + try (Transaction t = TransferUtil.getTransaction()) { + tank.extract(tank.variant, (long) (consumption*speedModifier), t); + t.commit(); + } numero++; diff --git a/src/main/java/com/drmangotea/createindustry/blocks/machines/oil_processing/distillation/output/DistillationOutputBlockEntity.java b/src/main/java/com/drmangotea/createindustry/blocks/machines/oil_processing/distillation/output/DistillationOutputBlockEntity.java index 7b8dfcac..2ee43dbc 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/machines/oil_processing/distillation/output/DistillationOutputBlockEntity.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/machines/oil_processing/distillation/output/DistillationOutputBlockEntity.java @@ -4,9 +4,13 @@ import com.simibubi.create.content.equipment.goggles.IHaveGoggleInformation; import com.simibubi.create.foundation.blockEntity.SmartBlockEntity; import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; import com.simibubi.create.foundation.fluid.SmartFluidTank; +import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil; import io.github.fabricators_of_create.porting_lib.transfer.fluid.FluidTank; import io.github.fabricators_of_create.porting_lib.util.FluidStack; import io.github.fabricators_of_create.porting_lib.util.LazyOptional; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.storage.Storage; +import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; @@ -20,12 +24,12 @@ import java.util.List; public class DistillationOutputBlockEntity extends SmartBlockEntity implements IHaveGoggleInformation { - protected LazyOptional fluidCapability; + protected Storage fluidCapability; public final FluidTank tank = new SmartFluidTank(8000,this::onFluidStackChanged); public DistillationOutputBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); - fluidCapability = LazyOptional.of(()->tank); + fluidCapability = tank.getSlot(0); } @Override @@ -66,8 +70,6 @@ public class DistillationOutputBlockEntity extends SmartBlockEntity implements I return containedFluidTooltip(tooltip, isPlayerSneaking, - getCapability(ForgeCapabilities.FLUID_HANDLER)); - - + fluidCapability); } } diff --git a/src/main/java/com/drmangotea/createindustry/blocks/machines/oil_processing/pumpjack/base/PumpjackBaseBlockEntity.java b/src/main/java/com/drmangotea/createindustry/blocks/machines/oil_processing/pumpjack/base/PumpjackBaseBlockEntity.java index 3ab4fe53..1e901693 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/machines/oil_processing/pumpjack/base/PumpjackBaseBlockEntity.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/machines/oil_processing/pumpjack/base/PumpjackBaseBlockEntity.java @@ -10,10 +10,12 @@ import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour import com.simibubi.create.foundation.fluid.SmartFluidTank; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.LangBuilder; +import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil; import io.github.fabricators_of_create.porting_lib.transfer.fluid.FluidTank; import io.github.fabricators_of_create.porting_lib.util.FluidStack; import io.github.fabricators_of_create.porting_lib.util.LazyOptional; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -183,52 +185,36 @@ public class PumpjackBaseBlockEntity extends SmartBlockEntity implements IHaveGo } //--Fluid Info--// - LazyOptional handler = this.getCapability(ForgeCapabilities.FLUID_HANDLER); + LazyOptional handler = fluidCapability; Optional resolve = handler.resolve(); if (!resolve.isPresent()) return false; FluidTank tank = resolve.get(); - if (tank.getTanks() == 0) - return false; + FluidStack fluidStack = tank.getFluid(); + Lang.fluidName(fluidStack) + .style(ChatFormatting.GRAY) + .forGoggles(tooltip, 1); + Lang.builder() + .add(Lang.number(fluidStack.getAmount()) + .add(mb) + .style(ChatFormatting.DARK_GREEN)) + .text(ChatFormatting.GRAY, " / ") + .add(Lang.number(tank.getCapacity()) + .add(mb) + .style(ChatFormatting.DARK_GRAY)) + .forGoggles(tooltip, 1); - boolean isEmpty = true; - for (int i = 0; i < tank.getTanks(); i++) { - FluidStack fluidStack = tank.getFluidInTank(i); - if (fluidStack.isEmpty()) - continue; - - Lang.fluidName(fluidStack) - .style(ChatFormatting.GRAY) - .forGoggles(tooltip, 1); - - Lang.builder() - .add(Lang.number(fluidStack.getAmount()) - .add(mb) - .style(ChatFormatting.DARK_GREEN)) - .text(ChatFormatting.GRAY, " / ") - .add(Lang.number(tank.getTankCapacity(i)) - .add(mb) - .style(ChatFormatting.DARK_GRAY)) - .forGoggles(tooltip, 1); - - isEmpty = false; - } - - if (tank.getTanks() > 1) { - if (isEmpty) - tooltip.remove(tooltip.size() - 1); - return true; - } + boolean isEmpty = tank.isEmpty(); if (!isEmpty) return true; Lang.translate("gui.goggles.fluid_container.capacity") - .add(Lang.number(tank.getTankCapacity(0)) + .add(Lang.number(tank.getCapacity()) .add(mb) .style(ChatFormatting.DARK_GREEN)) .style(ChatFormatting.DARK_GRAY) diff --git a/src/main/java/com/drmangotea/createindustry/blocks/machines/simple/welding_machine/WeldingBehaviour.java b/src/main/java/com/drmangotea/createindustry/blocks/machines/simple/welding_machine/WeldingBehaviour.java index 4544d0a8..06ea2308 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/machines/simple/welding_machine/WeldingBehaviour.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/machines/simple/welding_machine/WeldingBehaviour.java @@ -88,7 +88,7 @@ public class WeldingBehaviour extends BeltProcessingBehaviour { super.write(compound, clientPacket); if (clientPacket) { - compound.put("ParticleItems", NBTHelper.writeCompoundList(particleItems, ItemStack::serializeNBT)); + compound.put("ParticleItems", NBTHelper.writeCompoundList(particleItems, ItemStack::getTag)); particleItems.clear(); } } diff --git a/src/main/java/com/drmangotea/createindustry/blocks/tanks/SteelFluidTankModel.java b/src/main/java/com/drmangotea/createindustry/blocks/tanks/SteelFluidTankModel.java index 06db1164..32088d2e 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/tanks/SteelFluidTankModel.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/tanks/SteelFluidTankModel.java @@ -2,15 +2,14 @@ package com.drmangotea.createindustry.blocks.tanks; import com.drmangotea.createindustry.base.TFMGSpriteShifts; +import com.simibubi.create.AllSpriteShifts; import com.simibubi.create.api.connectivity.ConnectivityHandler; import com.simibubi.create.content.fluids.tank.FluidTankCTBehaviour; +import com.simibubi.create.content.fluids.tank.FluidTankModel; import com.simibubi.create.foundation.block.connected.CTModel; import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry; import com.simibubi.create.foundation.utility.Iterate; -import io.github.fabricators_of_create.porting_lib.model.data.ModelData; -import io.github.fabricators_of_create.porting_lib.model.data.ModelProperty; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.block.model.BakedQuad; +import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -18,52 +17,40 @@ import net.minecraft.util.RandomSource; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import java.util.function.Supplier; public class SteelFluidTankModel extends CTModel { - protected static final ModelProperty CULL_PROPERTY = new ModelProperty<>(); - public static SteelFluidTankModel standard(BakedModel originalModel) { return new SteelFluidTankModel(originalModel, TFMGSpriteShifts.STEEL_FLUID_TANK, TFMGSpriteShifts.STEEL_FLUID_TANK_TOP, TFMGSpriteShifts.STEEL_FLUID_TANK_INNER); } - private SteelFluidTankModel(BakedModel originalModel, CTSpriteShiftEntry side, CTSpriteShiftEntry top, CTSpriteShiftEntry inner) { super(originalModel, new FluidTankCTBehaviour(side, top, inner)); } @Override - protected ModelData.Builder gatherModelData(ModelData.Builder builder, BlockAndTintGetter world, BlockPos pos, BlockState state, - ModelData blockEntityData) { - super.gatherModelData(builder, world, pos, state, blockEntityData); - CullData cullData = new CullData(); + public void emitBlockQuads(BlockAndTintGetter blockView, BlockState state, BlockPos pos, Supplier randomSupplier, RenderContext context) { + SteelFluidTankModel.CullData cullData = new SteelFluidTankModel.CullData(); for (Direction d : Iterate.horizontalDirections) - cullData.setCulled(d, ConnectivityHandler.isConnected(world, pos, pos.relative(d))); - return builder.with(CULL_PROPERTY, cullData); + cullData.setCulled(d, ConnectivityHandler.isConnected(blockView, pos, pos.relative(d))); + + context.pushTransform(quad -> { + Direction cullFace = quad.cullFace(); + if (cullFace != null && cullData.isCulled(cullFace)) { + return false; + } + quad.cullFace(null); + return true; + }); + super.emitBlockQuads(blockView, state, pos, randomSupplier, context); + context.popTransform(); } - @Override - public List getQuads(BlockState state, Direction side, RandomSource rand, ModelData extraData, RenderType renderType) { - if (side != null) - return Collections.emptyList(); - - List quads = new ArrayList<>(); - for (Direction d : Iterate.directions) { - if (extraData.has(CULL_PROPERTY) && extraData.get(CULL_PROPERTY) - .isCulled(d)) - continue; - quads.addAll(super.getQuads(state, d, rand, extraData, renderType)); - } - quads.addAll(super.getQuads(state, null, rand, extraData, renderType)); - return quads; - } - private class CullData { + private static class CullData { boolean[] culledFaces; public CullData() { @@ -87,3 +74,4 @@ public class SteelFluidTankModel extends CTModel { } } + diff --git a/src/main/java/com/drmangotea/createindustry/blocks/tanks/SteelFluidTankRenderer.java b/src/main/java/com/drmangotea/createindustry/blocks/tanks/SteelFluidTankRenderer.java index aa9851df..75867fc2 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/tanks/SteelFluidTankRenderer.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/tanks/SteelFluidTankRenderer.java @@ -6,6 +6,8 @@ import com.jozufozu.flywheel.util.transform.TransformStack; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import com.simibubi.create.AllPartialModels; +import com.simibubi.create.content.fluids.tank.FluidTankBlockEntity; +import com.simibubi.create.content.fluids.tank.FluidTankRenderer; import com.simibubi.create.foundation.blockEntity.renderer.SafeBlockEntityRenderer; import com.simibubi.create.foundation.fluid.FluidRenderer; import com.simibubi.create.foundation.render.CachedBufferer; @@ -13,6 +15,7 @@ import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.animation.LerpedFloat; import io.github.fabricators_of_create.porting_lib.transfer.fluid.FluidTank; import io.github.fabricators_of_create.porting_lib.util.FluidStack; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributes; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; @@ -25,40 +28,40 @@ public class SteelFluidTankRenderer extends SafeBlockEntityRenderer { +import java.util.function.Consumer; - public static final BooleanProperty TOP = BooleanProperty.create("top"); - public static final BooleanProperty BOTTOM = BooleanProperty.create("bottom"); - public static final EnumProperty SHAPE = EnumProperty.create("shape", Shape.class); +import static com.simibubi.create.content.fluids.tank.FluidTankBlock.SILENCED_METAL; - private boolean creative; +public class SteelTankBlock extends Block implements IWrenchable, IBE, CustomSoundTypeBlock { - public static SteelTankBlock regular(Properties p_i48440_1_) { - return new SteelTankBlock(p_i48440_1_, false); + public static final BooleanProperty TOP = BooleanProperty.create("top"); + public static final BooleanProperty BOTTOM = BooleanProperty.create("bottom"); + public static final EnumProperty SHAPE = EnumProperty.create("shape", Shape.class); + public static final IntegerProperty LIGHT_LEVEL = IntegerProperty.create("light_level", 0, 15); + + public static SteelTankBlock regular(Properties p_i48440_1_) { + return new SteelTankBlock(p_i48440_1_); } - public static SteelTankBlock creative(Properties p_i48440_1_) { - return new SteelTankBlock(p_i48440_1_, true); - } + @Override + public void setPlacedBy(Level pLevel, BlockPos pPos, BlockState pState, LivingEntity pPlacer, ItemStack pStack) { + super.setPlacedBy(pLevel, pPos, pState, pPlacer, pStack); + AdvancementBehaviour.setPlacedBy(pLevel, pPos, pPlacer); + } + protected SteelTankBlock(Properties p_i48440_1_) { + super(setLightFunction(p_i48440_1_)); + registerDefaultState(defaultBlockState().setValue(TOP, true) + .setValue(BOTTOM, true) + .setValue(SHAPE, Shape.WINDOW) + .setValue(LIGHT_LEVEL, 0)); + } + private static Properties setLightFunction(Properties properties) { + return properties.lightLevel(state -> state.getValue(LIGHT_LEVEL)); + } - protected SteelTankBlock(Properties p_i48440_1_, boolean creative) { - super(p_i48440_1_); - this.creative = creative; - registerDefaultState(defaultBlockState().setValue(TOP, true) - .setValue(BOTTOM, true) - .setValue(SHAPE, Shape.WINDOW)); - } - - public static boolean isTank(BlockState state) { + public static boolean isTank(BlockState state) { return state.getBlock() instanceof SteelTankBlock; } @@ -83,7 +100,10 @@ public class SteelTankBlock extends Block implements IWrenchable, IBE consumer = FluidTankItem.IS_PLACING_NBT + ? SteelTankBlockEntity::queueConnectivityUpdate + : SteelTankBlockEntity::updateConnectivity; + withBlockEntityDo(world, pos, consumer); } @Override @@ -91,17 +111,6 @@ public class SteelTankBlock extends Block implements IWrenchable, IBE fluidTank = be.getFluidStorage(direction); + if (fluidTank == null) + return InteractionResult.PASS; + + FluidStack prevFluidInTank = TransferUtil.firstCopyOrEmpty(fluidTank); + + if (FluidHelper.tryEmptyItemIntoBE(world, player, hand, heldItem, be, direction)) + exchange = FluidExchange.ITEM_TO_TANK; + else if (FluidHelper.tryFillItemFromBE(world, player, hand, heldItem, be, direction)) + exchange = FluidExchange.TANK_TO_ITEM; + + if (exchange == null) { + if (GenericItemEmptying.canItemBeEmptied(world, heldItem) + || GenericItemFilling.canItemBeFilled(world, heldItem)) + return InteractionResult.SUCCESS; + return InteractionResult.PASS; } - @Override - public VoxelShape getBlockSupportShape(BlockState pState, BlockGetter pReader, BlockPos pPos) { - return Shapes.block(); + SoundEvent soundevent = null; + BlockState fluidState = null; + FluidStack fluidInTank = TransferUtil.firstOrEmpty(fluidTank); + + if (exchange == FluidExchange.ITEM_TO_TANK) { + Fluid fluid = fluidInTank.getFluid(); + fluidState = fluid.defaultFluidState() + .createLegacyBlock(); + soundevent = FluidVariantAttributes.getEmptySound(FluidVariant.of(fluid)); } - @Override - public BlockState updateShape(BlockState pState, Direction pDirection, BlockState pNeighborState, - LevelAccessor pLevel, BlockPos pCurrentPos, BlockPos pNeighborPos) { - if (pDirection == Direction.DOWN && pNeighborState.getBlock() != this) - withBlockEntityDo(pLevel, pCurrentPos, SteelTankBlockEntity::updateBoilerTemperature); - return pState; + if (exchange == FluidExchange.TANK_TO_ITEM) { + Fluid fluid = prevFluidInTank.getFluid(); + fluidState = fluid.defaultFluidState() + .createLegacyBlock(); + soundevent = FluidVariantAttributes.getFillSound(FluidVariant.of(fluid)); } - @Override - public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, - BlockHitResult ray) { - ItemStack heldItem = player.getItemInHand(hand); - boolean onClient = world.isClientSide; + if (soundevent != null && !onClient) { + float pitch = Mth + .clamp(1 - (1f * fluidInTank.getAmount() / (FluidTankBlockEntity.getCapacityMultiplier() * 16)), 0, 1); + pitch /= 1.5f; + pitch += .5f; + pitch += (world.random.nextFloat() - .5f) / 4f; + world.playSound(null, pos, soundevent, SoundSource.BLOCKS, .5f, pitch); + } - if (heldItem.isEmpty()) - return InteractionResult.PASS; - if (!player.isCreative() && !creative) - return InteractionResult.PASS; + if (!fluidInTank.isFluidEqual(prevFluidInTank)) { + if (be instanceof SteelTankBlockEntity) { + SteelTankBlockEntity controllerBE = be.getControllerBE(); + if (controllerBE != null) { + if (fluidState != null && onClient) { + BlockParticleOption blockParticleData = + new BlockParticleOption(ParticleTypes.BLOCK, fluidState); + float level = (float) fluidInTank.getAmount() / TransferUtil.firstCapacity(fluidTank); - FluidExchange exchange = null; - SteelTankBlockEntity te = ConnectivityHandler.partAt(getBlockEntityType(), world, pos); - if (te == null) - return InteractionResult.FAIL; + boolean reversed = FluidVariantAttributes.isLighterThanAir(fluidInTank.getType()); + if (reversed) + level = 1 - level; - LazyOptional tankCapability = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY); - if (!tankCapability.isPresent()) - return InteractionResult.PASS; - IFluidHandler fluidTank = tankCapability.orElse(null); - FluidStack prevFluidInTank = fluidTank.getFluidInTank(0) - .copy(); - - if (FluidHelper.tryEmptyItemIntoBE(world, player, hand, heldItem, te)) - exchange = FluidExchange.ITEM_TO_TANK; - else if (FluidHelper.tryFillItemFromBE(world, player, hand, heldItem, te)) - exchange = FluidExchange.TANK_TO_ITEM; - - if (exchange == null) { - if (GenericItemEmptying.canItemBeEmptied(world, heldItem) - || GenericItemFilling.canItemBeFilled(world, heldItem)) - return InteractionResult.SUCCESS; - return InteractionResult.PASS; - } - - SoundEvent soundevent = null; - BlockState fluidState = null; - FluidStack fluidInTank = tankCapability.map(fh -> fh.getFluidInTank(0)) - .orElse(FluidStack.EMPTY); - - if (exchange == FluidExchange.ITEM_TO_TANK) { - - - Fluid fluid = fluidInTank.getFluid(); - fluidState = fluid.defaultFluidState() - .createLegacyBlock(); - soundevent = FluidHelper.getEmptySound(fluidInTank); - } - - if (exchange == FluidExchange.TANK_TO_ITEM) { - - Fluid fluid = prevFluidInTank.getFluid(); - fluidState = fluid.defaultFluidState() - .createLegacyBlock(); - soundevent = FluidHelper.getFillSound(prevFluidInTank); - } - - if (soundevent != null && !onClient) { - float pitch = Mth - .clamp(1 - (1f * fluidInTank.getAmount() / (SteelTankBlockEntity.getCapacityMultiplier() * 16)), 0, 1); - pitch /= 1.5f; - pitch += .5f; - pitch += (world.random.nextFloat() - .5f) / 4f; - world.playSound(null, pos, soundevent, SoundSource.BLOCKS, .5f, pitch); - } - - if (!fluidInTank.isFluidStackIdentical(prevFluidInTank)) { - if (te instanceof SteelTankBlockEntity) { - SteelTankBlockEntity controllerTE = (SteelTankBlockEntity) ((SteelTankBlockEntity) te).getControllerBE(); - if (controllerTE != null) { - if (fluidState != null && onClient) { - BlockParticleOption blockParticleData = - new BlockParticleOption(ParticleTypes.BLOCK, fluidState); - float level = (float) fluidInTank.getAmount() / fluidTank.getTankCapacity(0); - - boolean reversed = fluidInTank.getFluid() - .getFluidType() - .isLighterThanAir(); - if (reversed) - level = 1 - level; - - Vec3 vec = ray.getLocation(); - vec = new Vec3(vec.x, controllerTE.getBlockPos() - .getY() + level * (controllerTE.height - .5f) + .25f, vec.z); - Vec3 motion = player.position() - .subtract(vec) - .scale(1 / 20f); - vec = vec.add(motion); - world.addParticle(blockParticleData, vec.x, vec.y, vec.z, motion.x, motion.y, motion.z); - return InteractionResult.SUCCESS; - } - - controllerTE.sendDataImmediately(); - controllerTE.setChanged(); + Vec3 vec = ray.getLocation(); + vec = new Vec3(vec.x, controllerBE.getBlockPos() + .getY() + level * (controllerBE.height - .5f) + .25f, vec.z); + Vec3 motion = player.position() + .subtract(vec) + .scale(1 / 20f); + vec = vec.add(motion); + world.addParticle(blockParticleData, vec.x, vec.y, vec.z, motion.x, motion.y, motion.z); + return InteractionResult.SUCCESS; } + + controllerBE.sendDataImmediately(); + controllerBE.setChanged(); } } - - return InteractionResult.SUCCESS; } - @Override - public void onRemove(BlockState state, Level world, BlockPos pos, BlockState newState, boolean isMoving) { - if (state.hasBlockEntity() && (state.getBlock() != newState.getBlock() || !newState.hasBlockEntity())) { - BlockEntity te = world.getBlockEntity(pos); - if (!(te instanceof SteelTankBlockEntity)) - return; - SteelTankBlockEntity tankTE = (SteelTankBlockEntity) te; - world.removeBlockEntity(pos); - ConnectivityHandler.splitMulti(tankTE); - } - } + return InteractionResult.SUCCESS; + } - @Override - public Class getBlockEntityClass() { + @Override + public void onRemove(BlockState state, Level world, BlockPos pos, BlockState newState, boolean isMoving) { + if (state.hasBlockEntity() && (state.getBlock() != newState.getBlock() || !newState.hasBlockEntity())) { + BlockEntity be = world.getBlockEntity(pos); + if (!(be instanceof FluidTankBlockEntity)) + return; + FluidTankBlockEntity tankBE = (FluidTankBlockEntity) be; + world.removeBlockEntity(pos); + ConnectivityHandler.splitMulti(tankBE); + } + } + + @Override + public Class getBlockEntityClass() { return SteelTankBlockEntity.class; } - @Override - public BlockEntityType getBlockEntityType() { - return creative ? TFMGBlockEntities.STEEL_FLUID_TANK.get() : TFMGBlockEntities.STEEL_FLUID_TANK.get(); - } + @Override + public BlockEntityType getBlockEntityType() { + return TFMGBlockEntities.STEEL_FLUID_TANK.get(); + } @Override public BlockState mirror(BlockState state, Mirror mirror) { @@ -304,15 +307,10 @@ public class SteelTankBlock extends Block implements IWrenchable, IBE SoundEvents.METAL_BREAK, () -> SoundEvents.METAL_STEP, - () -> SoundEvents.METAL_PLACE, () -> SoundEvents.METAL_HIT, () -> SoundEvents.METAL_FALL); - @Override public SoundType getSoundType(BlockState state, LevelReader world, BlockPos pos, Entity entity) { - SoundType soundType = super.getSoundType(state, world, pos, entity); - if (entity != null && entity.getPersistentData() + SoundType soundType = getSoundType(state); + if (entity != null && entity.getExtraCustomData() .contains("SilenceTankSound")) return SILENCED_METAL; return soundType; diff --git a/src/main/java/com/drmangotea/createindustry/blocks/tanks/SteelTankBlockEntity.java b/src/main/java/com/drmangotea/createindustry/blocks/tanks/SteelTankBlockEntity.java index 656fbf5f..00106396 100644 --- a/src/main/java/com/drmangotea/createindustry/blocks/tanks/SteelTankBlockEntity.java +++ b/src/main/java/com/drmangotea/createindustry/blocks/tanks/SteelTankBlockEntity.java @@ -13,10 +13,13 @@ import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.animation.LerpedFloat; import com.simibubi.create.foundation.utility.animation.LerpedFloat.Chaser; import com.simibubi.create.infrastructure.config.AllConfigs; +import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil; import io.github.fabricators_of_create.porting_lib.transfer.fluid.FluidTank; import io.github.fabricators_of_create.porting_lib.util.FluidStack; import io.github.fabricators_of_create.porting_lib.util.LazyOptional; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributeHandler; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributes; import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; import net.minecraft.core.BlockPos; @@ -147,14 +150,14 @@ public class SteelTankBlockEntity extends FluidTankBlockEntity implements IHaveG removeController(true); lastKnownPos = worldPosition; } - protected void onFluidStackChanged(FluidStack newFluidStack) { if (!hasLevel()) return; - FluidVariant attributes = newFluidStack.getType(); - int luminosity = (int) (attributes.getLightLevel(newFluidStack) / 1.2f); - boolean reversed = attributes.isLighterThanAir(); + FluidVariantAttributeHandler handler = FluidVariantAttributes.getHandlerOrDefault(newFluidStack.getFluid()); + FluidVariant variant = newFluidStack.getType(); + int luminosity = (int) (handler.getLuminance(variant) / 1.2f); + boolean reversed = handler.isLighterThanAir(variant); int maxY = (int) ((getFillState() * height) + 1); for (int yOffset = 0; yOffset < height; yOffset++) { @@ -446,17 +449,14 @@ public class SteelTankBlockEntity extends FluidTankBlockEntity implements IHaveG @Override public boolean addToGoggleTooltip(List tooltip, boolean isPlayerSneaking) { - SteelTankBlockEntity controllerTE = getControllerBE(); + SteelTankBlockEntity controllerBE = getControllerBE(); - if(isDistillationTower) + if (isDistillationTower) return false; - - if(getControllerBE()!=null) - if(getControllerBE().isDistillationTower) - return false; - + if (controllerBE != null && controllerBE.isDistillationTower) + return true; return containedFluidTooltip(tooltip, isPlayerSneaking, - controllerTE.getCapability(ForgeCapabilities.FLUID_HANDLER)); + controllerBE.getFluidStorage(null)); } @Override @@ -486,7 +486,10 @@ public class SteelTankBlockEntity extends FluidTankBlockEntity implements IHaveG tankInventory.setCapacity(getTotalTankSize() * getCapacityMultiplier()); tankInventory.readFromNBT(compound.getCompound("TankContent")); if (tankInventory.getSpace() < 0) - tankInventory.drain(-tankInventory.getSpace(), FluidAction.EXECUTE); + try (Transaction t = TransferUtil.getTransaction()) { + tankInventory.extract(tankInventory.variant, -tankInventory.getSpace(), t); + t.commit(); + } } @@ -578,7 +581,7 @@ public class SteelTankBlockEntity extends FluidTankBlockEntity implements IHaveG return MAX_SIZE; } - public static int getCapacityMultiplier() { + public static long getCapacityMultiplier() { return AllConfigs.server().fluids.fluidTankCapacity.get() * 1000; } diff --git a/src/main/java/com/drmangotea/createindustry/events/ClientEvents.java b/src/main/java/com/drmangotea/createindustry/events/ClientEvents.java new file mode 100644 index 00000000..9320cff3 --- /dev/null +++ b/src/main/java/com/drmangotea/createindustry/events/ClientEvents.java @@ -0,0 +1,18 @@ +package com.drmangotea.createindustry.events; + +import com.drmangotea.createindustry.CreateTFMGClient; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.minecraft.client.Minecraft; + +public class ClientEvents { + public static void onTick(Minecraft client) { + CreateTFMGClient.ADVANCED_POTATO_CANNON_RENDER_HANDLER.tick(); + CreateTFMGClient.FLAMETHROWER_RENDER_HANDLER.tick(); + CreateTFMGClient.QUAD_POTATO_CANNON_RENDER_HANDLER.tick(); + } + + public static void register() { + + ClientTickEvents.END_CLIENT_TICK.register(ClientEvents::onTick); + } +} diff --git a/src/main/java/com/drmangotea/createindustry/items/weapons/advanced_potato_cannon/AdvancedPotatoCannonItem.java b/src/main/java/com/drmangotea/createindustry/items/weapons/advanced_potato_cannon/AdvancedPotatoCannonItem.java index 328ea665..87fac410 100644 --- a/src/main/java/com/drmangotea/createindustry/items/weapons/advanced_potato_cannon/AdvancedPotatoCannonItem.java +++ b/src/main/java/com/drmangotea/createindustry/items/weapons/advanced_potato_cannon/AdvancedPotatoCannonItem.java @@ -11,6 +11,8 @@ import com.simibubi.create.content.equipment.zapper.ShootableGadgetItemMethods; import com.simibubi.create.foundation.item.CustomArmPoseItem; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.infrastructure.config.AllConfigs; +import io.github.fabricators_of_create.porting_lib.item.EntitySwingListenerItem; +import io.github.fabricators_of_create.porting_lib.item.ReequipAnimationItem; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; @@ -35,8 +37,8 @@ import org.jetbrains.annotations.Nullable; import java.util.Optional; import java.util.function.Predicate; -public class AdvancedPotatoCannonItem extends ProjectileWeaponItem implements CustomArmPoseItem { - +public class AdvancedPotatoCannonItem extends ProjectileWeaponItem implements CustomArmPoseItem, + EntitySwingListenerItem, ReequipAnimationItem { public static ItemStack CLIENT_CURRENT_AMMO = ItemStack.EMPTY; public static final int MAX_DAMAGE = 500; @@ -219,10 +221,6 @@ public class AdvancedPotatoCannonItem extends ProjectileWeaponItem implements Cu return 15; } - @Override - @Environment(EnvType.CLIENT) - public void initializeClient(Consumer consumer) { - consumer.accept(SimpleCustomRenderer.create(this, new AdvancedPotatoCannonItemRenderer())); - } + } diff --git a/src/main/java/com/drmangotea/createindustry/items/weapons/advanced_potato_cannon/AdvancedPotatoCannonItemRenderer.java b/src/main/java/com/drmangotea/createindustry/items/weapons/advanced_potato_cannon/AdvancedPotatoCannonItemRenderer.java index dbeee84c..368bb6e4 100644 --- a/src/main/java/com/drmangotea/createindustry/items/weapons/advanced_potato_cannon/AdvancedPotatoCannonItemRenderer.java +++ b/src/main/java/com/drmangotea/createindustry/items/weapons/advanced_potato_cannon/AdvancedPotatoCannonItemRenderer.java @@ -18,8 +18,6 @@ import net.minecraft.world.item.ItemStack; public class AdvancedPotatoCannonItemRenderer extends CustomRenderedItemModelRenderer { - - @Override protected void render(ItemStack stack, CustomRenderedItemModel model, PartialItemModelRenderer renderer, TransformType transformType, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { diff --git a/src/main/java/com/drmangotea/createindustry/items/weapons/flamethrover/FlamethrowerItem.java b/src/main/java/com/drmangotea/createindustry/items/weapons/flamethrover/FlamethrowerItem.java index ab5e9171..01de9e1a 100644 --- a/src/main/java/com/drmangotea/createindustry/items/weapons/flamethrover/FlamethrowerItem.java +++ b/src/main/java/com/drmangotea/createindustry/items/weapons/flamethrover/FlamethrowerItem.java @@ -5,6 +5,7 @@ import com.drmangotea.createindustry.base.util.spark.Spark; import com.drmangotea.createindustry.registry.TFMGCreativeModeTabs; import com.drmangotea.createindustry.registry.TFMGEntityTypes; import com.drmangotea.createindustry.registry.TFMGItems; +import com.simibubi.create.content.equipment.potatoCannon.PotatoCannonItem; import com.simibubi.create.content.fluids.tank.FluidTankBlockEntity; import com.simibubi.create.foundation.item.CustomArmPoseItem; import net.minecraft.client.model.HumanoidModel; @@ -27,6 +28,8 @@ import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; import org.jetbrains.annotations.Nullable; +import static com.drmangotea.createindustry.base.util.TFMGUtils.drain; + public class FlamethrowerItem extends Item implements CustomArmPoseItem { @@ -153,7 +156,7 @@ return Math.round( 13* ((float)((float)stack.getOrCreateTag().getInt("amount")/( long toDrain = Math.min(FUEL_CAPACITY - nbt.getInt("amount"), be.getFluid(0).getAmount()); nbt.putString("fuel", fluid); - be.getTankInventory().drain(toDrain, IFluidHandler.FluidAction.EXECUTE); + drain(be.getTankInventory(), toDrain); nbt.putLong("amount", nbt.getLong("amount") + toDrain); context.getPlayer().getCooldowns().addCooldown(stack.getItem(), 20); diff --git a/src/main/java/com/drmangotea/createindustry/items/weapons/quad_potato_cannon/QuadPotatoCannonItem.java b/src/main/java/com/drmangotea/createindustry/items/weapons/quad_potato_cannon/QuadPotatoCannonItem.java index 9194fc10..11c93afc 100644 --- a/src/main/java/com/drmangotea/createindustry/items/weapons/quad_potato_cannon/QuadPotatoCannonItem.java +++ b/src/main/java/com/drmangotea/createindustry/items/weapons/quad_potato_cannon/QuadPotatoCannonItem.java @@ -14,6 +14,9 @@ import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Components; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.VecHelper; +import io.github.fabricators_of_create.porting_lib.enchant.CustomEnchantingBehaviorItem; +import io.github.fabricators_of_create.porting_lib.item.EntitySwingListenerItem; +import io.github.fabricators_of_create.porting_lib.item.ReequipAnimationItem; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.ChatFormatting; @@ -48,7 +51,8 @@ import java.util.List; import java.util.Optional; import java.util.function.Predicate; -public class QuadPotatoCannonItem extends ProjectileWeaponItem implements CustomArmPoseItem { +public class QuadPotatoCannonItem extends ProjectileWeaponItem implements CustomArmPoseItem, + CustomEnchantingBehaviorItem, ReequipAnimationItem, EntitySwingListenerItem { public static ItemStack CLIENT_CURRENT_AMMO = ItemStack.EMPTY; public static final int MAX_DAMAGE = 100; @@ -74,7 +78,7 @@ public class QuadPotatoCannonItem extends ProjectileWeaponItem implements Custom return true; if (enchantment == AllEnchantments.POTATO_RECOVERY.get()) return true; - return super.canApplyAtEnchantingTable(stack, enchantment); + return false; } @Override diff --git a/src/main/java/com/drmangotea/createindustry/items/weapons/quad_potato_cannon/QuadPotatoCannonItemRenderer.java b/src/main/java/com/drmangotea/createindustry/items/weapons/quad_potato_cannon/QuadPotatoCannonItemRenderer.java index 32bb8ed3..83e44b4b 100644 --- a/src/main/java/com/drmangotea/createindustry/items/weapons/quad_potato_cannon/QuadPotatoCannonItemRenderer.java +++ b/src/main/java/com/drmangotea/createindustry/items/weapons/quad_potato_cannon/QuadPotatoCannonItemRenderer.java @@ -6,6 +6,7 @@ import com.jozufozu.flywheel.util.transform.TransformStack; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Vector3f; import com.simibubi.create.content.equipment.potatoCannon.PotatoCannonItem; +import com.simibubi.create.content.equipment.potatoCannon.PotatoCannonItemRenderer; import com.simibubi.create.foundation.item.render.CustomRenderedItemModel; import com.simibubi.create.foundation.item.render.CustomRenderedItemModelRenderer; import com.simibubi.create.foundation.item.render.PartialItemModelRenderer;