mango deserves the death penalty istg

This commit is contained in:
DaCodia
2024-08-07 23:39:18 -05:00
parent e6c8effe4c
commit dd9acfcb94
35 changed files with 458 additions and 558 deletions

View File

@@ -28,10 +28,9 @@ public class CreateTFMG implements ModInitializer {
public static final Logger LOGGER = LogUtils.getLogger(); public static final Logger LOGGER = LogUtils.getLogger();
static { static {
REGISTRATE.setTooltipModifierFactory(item -> { REGISTRATE.setTooltipModifierFactory(item ->
return new ItemDescription.Modifier(item, TooltipHelper.Palette.STANDARD_CREATE) new ItemDescription.Modifier(item, TooltipHelper.Palette.STANDARD_CREATE)
.andThen(TooltipModifier.mapNull(KineticStats.create(item))); .andThen(TooltipModifier.mapNull(KineticStats.create(item))));
});
} }
@Override @Override

View File

@@ -4,8 +4,10 @@ import java.util.Collection;
import com.drmangotea.createindustry.CreateTFMG; import com.drmangotea.createindustry.CreateTFMG;
import com.simibubi.create.compat.jei.CreateJEI; import com.simibubi.create.compat.jei.CreateJEI;
import com.simibubi.create.infrastructure.item.CreateCreativeModeTab;
import com.tterrag.registrate.util.entry.RegistryEntry; 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.Minecraft;
import net.minecraft.client.renderer.entity.ItemRenderer; import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.client.resources.model.BakedModel; import net.minecraft.client.resources.model.BakedModel;
@@ -18,7 +20,7 @@ import net.minecraft.world.item.ItemStack;
public abstract class TFMGCreativeModeTab extends CreativeModeTab { public abstract class TFMGCreativeModeTab extends CreativeModeTab {
public TFMGCreativeModeTab(String id) { public TFMGCreativeModeTab(String id) {
super(CreateTFMG.MOD_ID + "." + id); super(ItemGroupUtil.expandArrayAndGetId(), CreateTFMG.MOD_ID + "." + id);
} }
@Override @Override

View File

@@ -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<ItemVariant, Storage<ItemVariant>> {
@SafeVarargs
public CombinedStorageWrapper(Storage<ItemVariant>... parts) {
super(Arrays.stream(parts).toList());
}
// public CombinedStorageWrapper(SmartInventory... invs) {
// super();
// }
}

View File

@@ -4,14 +4,20 @@ import com.drmangotea.createindustry.base.ElectricSparkParticle;
import com.drmangotea.createindustry.base.util.spark.Spark; import com.drmangotea.createindustry.base.util.spark.Spark;
import com.drmangotea.createindustry.registry.TFMGEntityTypes; import com.drmangotea.createindustry.registry.TFMGEntityTypes;
import com.simibubi.create.Create; 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.core.BlockPos;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource; import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity; 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.Explosion;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.Arrays; 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;
// }
} }

View File

@@ -13,6 +13,7 @@ import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.entity.*; import net.minecraft.world.entity.*;
import net.minecraft.world.entity.projectile.ThrowableProjectile; import net.minecraft.world.entity.projectile.ThrowableProjectile;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.EntityHitResult;
@@ -78,7 +79,7 @@ public class BlueSpark extends ThrowableProjectile {
super.onHitBlock(p_37384_); super.onHitBlock(p_37384_);
if (!this.level.isClientSide) { if (!this.level.isClientSide) {
Entity entity = this.getOwner(); 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()); BlockPos blockpos = p_37384_.getBlockPos().relative(p_37384_.getDirection());
if (this.level.isEmptyBlock(blockpos)) { if (this.level.isEmptyBlock(blockpos)) {
this.level.setBlockAndUpdate(blockpos, BlueFireBlock.getState(this.level, blockpos)); this.level.setBlockAndUpdate(blockpos, BlueFireBlock.getState(this.level, blockpos));

View File

@@ -1,7 +1,6 @@
package com.drmangotea.createindustry.base.util.spark; 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.items.weapons.explosives.thermite_grenades.fire.GreenFireBlock;
import com.drmangotea.createindustry.registry.TFMGEntityTypes; import com.drmangotea.createindustry.registry.TFMGEntityTypes;
import com.drmangotea.createindustry.registry.TFMGItems; 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.*;
import net.minecraft.world.entity.projectile.ThrowableProjectile; import net.minecraft.world.entity.projectile.ThrowableProjectile;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.EntityHitResult;
@@ -78,7 +78,7 @@ public class GreenSpark extends ThrowableProjectile {
super.onHitBlock(p_37384_); super.onHitBlock(p_37384_);
if (!this.level.isClientSide) { if (!this.level.isClientSide) {
Entity entity = this.getOwner(); 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()); BlockPos blockpos = p_37384_.getBlockPos().relative(p_37384_.getDirection());
if (this.level.isEmptyBlock(blockpos)) { if (this.level.isEmptyBlock(blockpos)) {
this.level.setBlockAndUpdate(blockpos, GreenFireBlock.getState(this.level, blockpos)); this.level.setBlockAndUpdate(blockpos, GreenFireBlock.getState(this.level, blockpos));

View File

@@ -1,7 +1,6 @@
package com.drmangotea.createindustry.base.util.spark; 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.TFMGEntityTypes;
import com.drmangotea.createindustry.registry.TFMGItems; import com.drmangotea.createindustry.registry.TFMGItems;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder; 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.*;
import net.minecraft.world.entity.projectile.ThrowableProjectile; import net.minecraft.world.entity.projectile.ThrowableProjectile;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseFireBlock; import net.minecraft.world.level.block.BaseFireBlock;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
@@ -74,7 +74,7 @@ public class Spark extends ThrowableProjectile {
super.onHitBlock(p_37384_); super.onHitBlock(p_37384_);
if (!this.level.isClientSide) { if (!this.level.isClientSide) {
Entity entity = this.getOwner(); 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()); BlockPos blockpos = p_37384_.getBlockPos().relative(p_37384_.getDirection());
if (this.level.isEmptyBlock(blockpos)) { if (this.level.isEmptyBlock(blockpos)) {
this.level.setBlockAndUpdate(blockpos, BaseFireBlock.getState(this.level, blockpos)); this.level.setBlockAndUpdate(blockpos, BaseFireBlock.getState(this.level, blockpos));

View File

@@ -1,33 +1,39 @@
package com.drmangotea.createindustry.blocks.electricity.api; package com.drmangotea.createindustry.blocks.electricity.api;
import net.fabricmc.fabric.api.transfer.v1.storage.TransferVariant; import com.drmangotea.createindustry.blocks.electricity.base.IElectricBlock;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import org.jetbrains.annotations.Nullable;
public class Energy implements TransferVariant<Double> { import static org.apache.commons.lang3.ObjectUtils.min;
@Override
public boolean isBlank() { public class Energy {
return false; long voltage;
long current;
public Energy(long voltage, long current) {
this.current = current;
this.voltage = current;
} }
@Override public long getVoltage() {
public Double getObject() { return voltage;
return null;
} }
@Override public long getCurrent() {
public @Nullable CompoundTag getNbt() { return current;
return null;
} }
@Override public long discharge(long amount, boolean simulate) {
public CompoundTag toNbt() {
return null; return amount;
} }
@Override public long charge(long amount, boolean simulate) {
public void toPacket(FriendlyByteBuf buf) {
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);
} }
} }

View File

@@ -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<Energy> {
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;
}
}

View File

@@ -28,11 +28,6 @@ public class ConverterBlockEntity extends ElectricBlockEntity {
@Override @Override
public void tick() { public void tick() {
super.tick(); super.tick();
} }
@Override @Override

View File

@@ -1,9 +1,7 @@
package com.drmangotea.createindustry.blocks.electricity.base; package com.drmangotea.createindustry.blocks.electricity.base;
import com.drmangotea.createindustry.CreateTFMG; import com.drmangotea.createindustry.blocks.electricity.api.Energy;
import com.drmangotea.createindustry.blocks.electricity.capacitor.CapacitorBlockEntity;
import com.drmangotea.createindustry.blocks.electricity.resistors.ResistorBlockEntity; import com.drmangotea.createindustry.blocks.electricity.resistors.ResistorBlockEntity;
import com.drmangotea.createindustry.registry.TFMGBlocks;
import com.simibubi.create.Create; import com.simibubi.create.Create;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
@@ -13,24 +11,18 @@ import net.minecraft.world.level.block.entity.BlockEntity;
public interface IElectricBlock { public interface IElectricBlock {
float internalResistance(); float internalResistance();
Energy getStorage();
int getVoltage(); int getVoltage();
boolean gotFElastTick(int value);
int getCurrent(); int getCurrent();
int feGeneration();
int voltageGeneration(); int voltageGeneration();
int transferSpeed(); int transferSpeed();
void addVoltage(float amount); void addVoltage(float amount);
default float getCharge(){ default float getCharge(){
@@ -41,22 +33,14 @@ public interface IElectricBlock {
return false; return false;
} }
TFMGForgeEnergyStorage getForgeEnergy();
boolean hasElectricitySlot(Direction direction); boolean hasElectricitySlot(Direction direction);
float maxVoltage(); float maxVoltage();
void explode(); void explode();
int FECapacity();
int getDistanceFromSource(); int getDistanceFromSource();
void setDistanceFromSource(int value); void setDistanceFromSource(int value);
void sendStuff(); void sendStuff();
@@ -75,8 +59,6 @@ public interface IElectricBlock {
boolean getsVoltageFromNonTFMGBlock = false; boolean getsVoltageFromNonTFMGBlock = false;
if(canBeDisabled()){ if(canBeDisabled()){
@@ -92,37 +74,29 @@ public interface IElectricBlock {
if(be1 instanceof IElectricBlock be2){ if(be1 instanceof IElectricBlock be2){
if(be2.hasElectricitySlot(direction.getOpposite())) { if(be2.hasElectricitySlot(direction.getOpposite())) {
int distance = be2.getDistanceFromSource(); int distance = be2.getDistanceFromSource();
if(!isStorage()&&be2.isStorage()&&direction == Direction.UP) if(!isStorage()&&be2.isStorage()&&direction == Direction.UP)
distance = Integer.MAX_VALUE; distance = Integer.MAX_VALUE;
if(getVoltage()==0) { if(getVoltage()==0) {
if(distance>getDistanceFromSource()) if(distance>getDistanceFromSource())
be2.addVoltage(getVoltage()); be2.addVoltage(getVoltage());
} }
if(!(be2 instanceof ConverterBlockEntity)) if(!(be2 instanceof ConverterBlockEntity))
if(!(isStorage()&&direction == Direction.DOWN)) if(!(isStorage()&&direction == Direction.DOWN))
if(!(!isStorage()&&be2.isStorage()&&direction == Direction.DOWN)) if(!(!isStorage()&&be2.isStorage()&&direction == Direction.DOWN))
if(getVoltage()!=0) { if(getVoltage()!=0) {
// if(Create.RANDOM.nextInt(3) ==1) // if(Create.RANDOM.nextInt(3) ==1)
transferCharge(be2); transferCharge(be2);
if(distance>getDistanceFromSource()){ if(distance>getDistanceFromSource())
be2.addVoltage(getVoltage()); be2.addVoltage(getVoltage());
} }
} lowestDistance = Math.min(lowestDistance,distance);
lowestDistance = Math.min(lowestDistance,distance);
} }
if(direction.getAxis().isHorizontal()) { if(direction.getAxis().isHorizontal()) {
if (be2 instanceof ResistorBlockEntity resistorBE) 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()).isPresent()) {
if (!(be1.getCapability(ForgeCapabilities.ENERGY, direction.getOpposite()).orElse(new EnergyStorage(0)) instanceof TFMGForgeEnergyStorage)) { if (!(be1.getCapability(ForgeCapabilities.ENERGY, direction.getOpposite()).orElse(new EnergyStorage(0)) instanceof TFMGForgeEnergyStorage)) {
@@ -216,114 +186,47 @@ public interface IElectricBlock {
addVoltage(0); addVoltage(0);
} }
//PLUH
default void transferCharge(IElectricBlock be) { default void transferCharge(IElectricBlock be) {
boolean hasHigherVoltage = getStorage().getVoltage() > be.getStorage().getVoltage();
if(isStorage()) {
if(be.isStorage() && !hasHigherVoltage) {
if(!isStorage()) { long amount = getStorage().transfer(be, transferSpeed() * 10, true);
if (be.getDistanceFromSource() > getDistanceFromSource()||be.isStorage()) { getStorage().transfer(be, amount, false);
} else {
//int amount = getForgeEnergy().extractEnergy(transferSpeed(), true); long amount = be.getStorage().transfer(be, transferSpeed(), true);
//int amount2 = be.getForgeEnergy().receiveEnergy( transferSpeed(), true); getStorage().transfer(be, amount, false);
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);
} }
} 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()<getForgeEnergy().getEnergyStored())) {
// if(be.getDistanceFromSource()>=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()<be.getForgeEnergy().getMaxEnergyStored()/2) {
getForgeEnergy().extractEnergy(Math.min(amount, amount2), false);
be.getForgeEnergy().receiveEnergy(Math.min(amount, amount2), false);
//}
}
}
} }
//PLUH
default void useEnergy(int baseValue){ default void useEnergy(int baseValue){
getStorage().discharge(baseValue/(voltageGeneration()+1),false);
getForgeEnergy().extractEnergy(baseValue/(voltageGeneration()+1),false);
}
default TFMGForgeEnergyStorage createEnergyStorage(){
return new TFMGForgeEnergyStorage(FECapacity(), 99999) {
@Override
public void onEnergyChanged(int energyAmount,boolean setEnergy) {
if(setEnergy)
return;
gotFElastTick(1);
sendStuff();
}
};
} }
default void writeElectrity(CompoundTag compound){ default void writeElectrity(CompoundTag compound){
compound.putInt("Voltage",getVoltage()); compound.putDouble("Voltage",getVoltage());
compound.putInt("Current",getCurrent()); compound.putDouble("Current",getCurrent());
compound.putInt("DistanceFromSource",getDistanceFromSource()); compound.putInt("DistanceFromSource",getDistanceFromSource());
compound.putInt("ForgeEnergy", getForgeEnergy().getEnergyStored()); //compound.putInt("ForgeEnergy", getForgeEnergy().getEnergyStored());
} }
} }

View File

@@ -1,49 +0,0 @@
package com.drmangotea.createindustry.blocks.electricity.base;
public abstract class TFMGForgeEnergyStorage extends EnergyStorage {
public TFMGForgeEnergyStorage(int capacity, int maxTransfer) {
super(capacity, maxTransfer);
}
@Override
public int extractEnergy(int maxExtract, boolean simulate) {
int extractedEnergy = super.extractEnergy(maxExtract, simulate);
if(extractedEnergy != 0) {
onEnergyChanged(maxExtract*-1,false);
}
return extractedEnergy;
}
@Override
public int receiveEnergy(int maxReceive, boolean simulate) {
int receiveEnergy = super.receiveEnergy(maxReceive, simulate);
if(receiveEnergy != 0) {
onEnergyChanged(receiveEnergy,false);
}
return receiveEnergy;
}
public int setEnergy(int energy) {
this.energy = energy;
if(energy>0)
onEnergyChanged(energy,true);
return 0;
}
public abstract void onEnergyChanged(int amount, boolean setEnergy);
}

View File

@@ -1,7 +1,6 @@
package com.drmangotea.createindustry.blocks.electricity.base.cables; package com.drmangotea.createindustry.blocks.electricity.base.cables;
import com.drmangotea.createindustry.base.TFMGTools; 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.base.*;
import com.drmangotea.createindustry.blocks.electricity.resistors.ResistorBlockEntity; import com.drmangotea.createindustry.blocks.electricity.resistors.ResistorBlockEntity;
import com.drmangotea.createindustry.registry.TFMGItems; import com.drmangotea.createindustry.registry.TFMGItems;

View File

@@ -1,11 +1,8 @@
package com.drmangotea.createindustry.blocks.electricity.base.cables.test; package com.drmangotea.createindustry.blocks.electricity.base.cables.test;
import com.drmangotea.createindustry.blocks.electricity.base.TFMGForgeEnergyStorage;
public class ElectricalNetworkMember { public class ElectricalNetworkMember {
public int voltage; public int voltage;
public TFMGForgeEnergyStorage energy;
} }

View File

@@ -7,6 +7,7 @@ import com.simibubi.create.AllTags;
import com.simibubi.create.content.decoration.copycat.CopycatModel; import com.simibubi.create.content.decoration.copycat.CopycatModel;
import com.simibubi.create.content.equipment.wrench.IWrenchable; import com.simibubi.create.content.equipment.wrench.IWrenchable;
import com.simibubi.create.foundation.block.IBE; 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.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@@ -38,7 +39,7 @@ import net.minecraft.world.phys.shapes.VoxelShape;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class CopycatCableBlock extends Block implements IBE<CopycatCableBlockEntity>, IWrenchable { public class CopycatCableBlock extends Block implements IBE<CopycatCableBlockEntity>, IWrenchable, CustomSoundTypeBlock {
public CopycatCableBlock(Properties pProperties) { public CopycatCableBlock(Properties pProperties) {
super(pProperties); super(pProperties);

View File

@@ -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.base.util.TFMGUtils;
import com.drmangotea.createindustry.blocks.electricity.base.IElectricBlock; 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.content.decoration.copycat.CopycatBlockEntity;
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;

View File

@@ -2,7 +2,6 @@ package com.drmangotea.createindustry.blocks.electricity.electric_motor;
import com.drmangotea.createindustry.base.util.TFMGUtils; import com.drmangotea.createindustry.base.util.TFMGUtils;
import com.drmangotea.createindustry.blocks.electricity.base.IElectricBlock; import com.drmangotea.createindustry.blocks.electricity.base.IElectricBlock;
import com.drmangotea.createindustry.blocks.electricity.base.TFMGForgeEnergyStorage;
import com.drmangotea.createindustry.registry.TFMGBlocks; import com.drmangotea.createindustry.registry.TFMGBlocks;
import com.jozufozu.flywheel.util.transform.TransformStack; import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;

View File

@@ -24,6 +24,7 @@ import io.github.fabricators_of_create.porting_lib.util.LazyOptional;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; 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.ChatFormatting;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
@@ -43,7 +44,9 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.List; 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 com.drmangotea.createindustry.blocks.engines.diesel.DieselEngineBlock.FACE;
import static net.minecraft.world.level.block.HorizontalDirectionalBlock.FACING; 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); //airTank.drain(1, IFluidHandler.FluidAction.EXECUTE);
if(!airTank.isEmpty()) { if(!airTank.isEmpty()) {
airTank.setFluid(new FluidStack(FluidVariant.of(TFMGFluids.AIR.getSource()), airTank.getFluidAmount() - 5)); 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)); }else expansionBE.airTank.setFluid(new FluidStack(FluidVariant.of(TFMGFluids.AIR.getSource()), expansionBE.airTank.getFluidAmount() - 5));
exhaustTank.fill(new FluidStack(FluidVariant.of(TFMGFluids.CARBON_DIOXIDE.getSource()),3), IFluidHandler.FluidAction.EXECUTE); 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)); //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--// //--Fluid Info--//
LazyOptional<IFluidHandler> handler = this.getCapability(ForgeCapabilities.FLUID_HANDLER); LazyOptional<CombinedTankWrapper> handler = fluidCapability;
Optional<IFluidHandler> resolve = handler.resolve(); Optional<CombinedTankWrapper> resolve = handler.resolve();
if (!resolve.isPresent()) if (!resolve.isPresent())
return false; return false;
IFluidHandler tank = resolve.get(); CombinedTankWrapper tanks = resolve.get();
if (tank.getTanks() == 0) if (tanks.parts.isEmpty())
return false; return false;
LangBuilder mb = Lang.translate("generic.unit.millibuckets"); LangBuilder mb = Lang.translate("generic.unit.millibuckets");
@@ -532,8 +535,9 @@ public class DieselEngineBlockEntity extends SmartBlockEntity implements IHaveGo
.forGoggles(tooltip); .forGoggles(tooltip);
boolean isEmpty = true; boolean isEmpty = true;
for (int i = 0; i < tank.getTanks(); i++) { for (int i = 0; i < tanks.parts.size(); i++) {
FluidStack fluidStack = tank.getFluidInTank(i); Storage<FluidVariant> tank = tanks.parts.get(i);
FluidStack fluidStack = tank.iterator();
if (fluidStack.isEmpty()) if (fluidStack.isEmpty())
continue; continue;
@@ -546,7 +550,7 @@ public class DieselEngineBlockEntity extends SmartBlockEntity implements IHaveGo
.add(mb) .add(mb)
.style(ChatFormatting.DARK_GREEN)) .style(ChatFormatting.DARK_GREEN))
.text(ChatFormatting.GRAY, " / ") .text(ChatFormatting.GRAY, " / ")
.add(Lang.number(tank.getTankCapacity(i)) .add(Lang.number(tanks.getTankCapacity(i))
.add(mb) .add(mb)
.style(ChatFormatting.DARK_GRAY)) .style(ChatFormatting.DARK_GRAY))
.forGoggles(tooltip, 1); .forGoggles(tooltip, 1);
@@ -554,7 +558,7 @@ public class DieselEngineBlockEntity extends SmartBlockEntity implements IHaveGo
isEmpty = false; isEmpty = false;
} }
if (tank.getTanks() > 1) { if (tanks.getTanks() > 1) {
if (isEmpty) if (isEmpty)
tooltip.remove(tooltip.size() - 1); tooltip.remove(tooltip.size() - 1);
return true; return true;
@@ -564,7 +568,7 @@ public class DieselEngineBlockEntity extends SmartBlockEntity implements IHaveGo
return true; return true;
Lang.translate("gui.goggles.fluid_container.capacity") Lang.translate("gui.goggles.fluid_container.capacity")
.add(Lang.number(tank.getTankCapacity(0)) .add(Lang.number(tanks.getTankCapacity(0))
.add(mb) .add(mb)
.style(ChatFormatting.DARK_GREEN)) .style(ChatFormatting.DARK_GREEN))
.style(ChatFormatting.DARK_GRAY) .style(ChatFormatting.DARK_GRAY)

View File

@@ -13,7 +13,6 @@ import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.minecraftforge.fluids.FluidStack;
import java.util.function.Supplier; import java.util.function.Supplier;

View File

@@ -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.transfer.fluid.FluidTank;
import io.github.fabricators_of_create.porting_lib.util.FluidStack; import io.github.fabricators_of_create.porting_lib.util.FluidStack;
import io.github.fabricators_of_create.porting_lib.util.LazyOptional; 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.ChatFormatting;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
@@ -31,7 +33,7 @@ public class TFMGMachineBlockEntity extends SmartBlockEntity implements IHaveGo
private boolean contentsChanged; private boolean contentsChanged;
protected LazyOptional<FluidTank> fluidCapability; protected LazyOptional<CombinedTankWrapper> fluidCapability;
public TFMGMachineBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) { public TFMGMachineBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state); super(type, pos, state);
@@ -68,9 +70,9 @@ public class TFMGMachineBlockEntity extends SmartBlockEntity implements IHaveGo
behaviours.add(tank2); behaviours.add(tank2);
fluidCapability = LazyOptional.of(() -> { fluidCapability = LazyOptional.of(() -> {
LazyOptional<? extends FluidTank> inputCap = tank1.getCapability(); Storage<FluidVariant> inputCap = tank1.getCapability();
LazyOptional<? extends FluidTank> outputCap = tank2.getCapability(); Storage<FluidVariant> outputCap = tank2.getCapability();
return new CombinedTankWrapper(outputCap.orElse(null), inputCap.orElse(null)); return new CombinedTankWrapper(outputCap, inputCap);
}); });

View File

@@ -1,5 +1,6 @@
package com.drmangotea.createindustry.blocks.machines.metal_processing.blast_furnace; 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.blocks.machines.TFMGMachineBlockEntity;
import com.drmangotea.createindustry.recipes.industrial_blasting.IndustrialBlastingRecipe; import com.drmangotea.createindustry.recipes.industrial_blasting.IndustrialBlastingRecipe;
import com.drmangotea.createindustry.registry.TFMGBlocks; import com.drmangotea.createindustry.registry.TFMGBlocks;
@@ -7,19 +8,25 @@ import com.drmangotea.createindustry.registry.TFMGItems;
import com.drmangotea.createindustry.registry.TFMGRecipeTypes; import com.drmangotea.createindustry.registry.TFMGRecipeTypes;
import com.simibubi.create.Create; import com.simibubi.create.Create;
import com.simibubi.create.content.equipment.goggles.IHaveGoggleInformation; 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.blockEntity.behaviour.BlockEntityBehaviour;
import com.simibubi.create.foundation.item.ItemHelper; import com.simibubi.create.foundation.item.ItemHelper;
import com.simibubi.create.foundation.item.SmartInventory; import com.simibubi.create.foundation.item.SmartInventory;
import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.foundation.utility.animation.LerpedFloat; 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.transfer.item.RecipeWrapper;
import io.github.fabricators_of_create.porting_lib.util.LazyOptional; 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.ChatFormatting;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntityType; 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 net.minecraft.world.phys.AABB;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@@ -58,14 +66,12 @@ public class BlastFurnaceOutputBlockEntity extends TFMGMachineBlockEntity implem
public LerpedFloat coalCokeHeight = LerpedFloat.linear(); public LerpedFloat coalCokeHeight = LerpedFloat.linear();
//item storage //item storage
public LazyOptional<IItemHandlerModifiable> itemCapability; public LazyOptional<CombinedStorageWrapper> itemCapability;
public SmartInventory inputInventory; public SmartInventory inputInventory;
public SmartInventory fuelInventory; public SmartInventory fuelInventory;
int debug = 0;
@@ -79,7 +85,7 @@ public class BlastFurnaceOutputBlockEntity extends TFMGMachineBlockEntity implem
fuelInventory = new SmartInventory(1, this).forbidInsertion().forbidExtraction() fuelInventory = new SmartInventory(1, this).forbidInsertion().forbidExtraction()
.withMaxStackSize(64); .withMaxStackSize(64);
itemCapability = LazyOptional.of(() -> new Combined(inputInventory,fuelInventory)); itemCapability = LazyOptional.of(() -> new CombinedStorageWrapper(inputInventory, fuelInventory));
tank1.getPrimaryHandler().setCapacity(8000); tank1.getPrimaryHandler().setCapacity(8000);

View File

@@ -5,14 +5,18 @@ import com.drmangotea.createindustry.blocks.tanks.SteelTankBlockEntity;
import com.drmangotea.createindustry.recipes.distillation.DistillationRecipe; import com.drmangotea.createindustry.recipes.distillation.DistillationRecipe;
import com.drmangotea.createindustry.registry.TFMGBlocks; import com.drmangotea.createindustry.registry.TFMGBlocks;
import com.simibubi.create.content.equipment.goggles.IHaveGoggleInformation; 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.SmartBlockEntity;
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
import com.simibubi.create.foundation.fluid.SmartFluidTank; import com.simibubi.create.foundation.fluid.SmartFluidTank;
import com.simibubi.create.foundation.recipe.RecipeFinder; import com.simibubi.create.foundation.recipe.RecipeFinder;
import com.simibubi.create.foundation.utility.Lang; 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.transfer.fluid.FluidTank;
import io.github.fabricators_of_create.porting_lib.util.FluidStack; import io.github.fabricators_of_create.porting_lib.util.FluidStack;
import io.github.fabricators_of_create.porting_lib.util.LazyOptional; 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.ChatFormatting;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
@@ -29,6 +33,8 @@ import javax.annotation.Nonnull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.drmangotea.createindustry.base.util.TFMGUtils.fill;
public class DistillationControllerBlockEntity extends SmartBlockEntity implements IHaveGoggleInformation { public class DistillationControllerBlockEntity extends SmartBlockEntity implements IHaveGoggleInformation {
private static final Object DistillationRecipesKey = new Object(); private static final Object DistillationRecipesKey = new Object();
@@ -99,7 +105,7 @@ public class DistillationControllerBlockEntity extends SmartBlockEntity implemen
for(DistillationOutputBlockEntity be1 : outputs){ for(DistillationOutputBlockEntity be1 : outputs){
if(be1.tank==0) if(be1.tank.isEmpty())
return; return;
} }
@@ -114,15 +120,17 @@ public class DistillationControllerBlockEntity extends SmartBlockEntity implemen
if(fluidStack.isEmpty()) if(fluidStack.isEmpty())
break; 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; 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); int consumption = (recipe.getInputFluid().getRequiredAmount()/6);
try (Transaction t = TransferUtil.getTransaction()) {
tank.drain((int) (consumption*speedModifier), IFluidHandler.FluidAction.EXECUTE); tank.extract(tank.variant, (long) (consumption*speedModifier), t);
t.commit();
}
numero++; numero++;

View File

@@ -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.SmartBlockEntity;
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
import com.simibubi.create.foundation.fluid.SmartFluidTank; 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.transfer.fluid.FluidTank;
import io.github.fabricators_of_create.porting_lib.util.FluidStack; import io.github.fabricators_of_create.porting_lib.util.FluidStack;
import io.github.fabricators_of_create.porting_lib.util.LazyOptional; 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.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@@ -20,12 +24,12 @@ import java.util.List;
public class DistillationOutputBlockEntity extends SmartBlockEntity implements IHaveGoggleInformation { public class DistillationOutputBlockEntity extends SmartBlockEntity implements IHaveGoggleInformation {
protected LazyOptional<FluidTank> fluidCapability; protected Storage<FluidVariant> fluidCapability;
public final FluidTank tank = new SmartFluidTank(8000,this::onFluidStackChanged); public final FluidTank tank = new SmartFluidTank(8000,this::onFluidStackChanged);
public DistillationOutputBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) { public DistillationOutputBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state); super(type, pos, state);
fluidCapability = LazyOptional.of(()->tank); fluidCapability = tank.getSlot(0);
} }
@Override @Override
@@ -66,8 +70,6 @@ public class DistillationOutputBlockEntity extends SmartBlockEntity implements I
return containedFluidTooltip(tooltip, isPlayerSneaking, return containedFluidTooltip(tooltip, isPlayerSneaking,
getCapability(ForgeCapabilities.FLUID_HANDLER)); fluidCapability);
} }
} }

View File

@@ -10,10 +10,12 @@ import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour
import com.simibubi.create.foundation.fluid.SmartFluidTank; import com.simibubi.create.foundation.fluid.SmartFluidTank;
import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.foundation.utility.LangBuilder; 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.transfer.fluid.FluidTank;
import io.github.fabricators_of_create.porting_lib.util.FluidStack; import io.github.fabricators_of_create.porting_lib.util.FluidStack;
import io.github.fabricators_of_create.porting_lib.util.LazyOptional; 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.FluidVariant;
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
@@ -183,52 +185,36 @@ public class PumpjackBaseBlockEntity extends SmartBlockEntity implements IHaveGo
} }
//--Fluid Info--// //--Fluid Info--//
LazyOptional<FluidTank> handler = this.getCapability(ForgeCapabilities.FLUID_HANDLER); LazyOptional<FluidTank> handler = fluidCapability;
Optional<FluidTank> resolve = handler.resolve(); Optional<FluidTank> resolve = handler.resolve();
if (!resolve.isPresent()) if (!resolve.isPresent())
return false; return false;
FluidTank tank = resolve.get(); 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; boolean isEmpty = tank.isEmpty();
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;
}
if (!isEmpty) if (!isEmpty)
return true; return true;
Lang.translate("gui.goggles.fluid_container.capacity") Lang.translate("gui.goggles.fluid_container.capacity")
.add(Lang.number(tank.getTankCapacity(0)) .add(Lang.number(tank.getCapacity())
.add(mb) .add(mb)
.style(ChatFormatting.DARK_GREEN)) .style(ChatFormatting.DARK_GREEN))
.style(ChatFormatting.DARK_GRAY) .style(ChatFormatting.DARK_GRAY)

View File

@@ -88,7 +88,7 @@ public class WeldingBehaviour extends BeltProcessingBehaviour {
super.write(compound, clientPacket); super.write(compound, clientPacket);
if (clientPacket) { if (clientPacket) {
compound.put("ParticleItems", NBTHelper.writeCompoundList(particleItems, ItemStack::serializeNBT)); compound.put("ParticleItems", NBTHelper.writeCompoundList(particleItems, ItemStack::getTag));
particleItems.clear(); particleItems.clear();
} }
} }

View File

@@ -2,15 +2,14 @@ package com.drmangotea.createindustry.blocks.tanks;
import com.drmangotea.createindustry.base.TFMGSpriteShifts; import com.drmangotea.createindustry.base.TFMGSpriteShifts;
import com.simibubi.create.AllSpriteShifts;
import com.simibubi.create.api.connectivity.ConnectivityHandler; import com.simibubi.create.api.connectivity.ConnectivityHandler;
import com.simibubi.create.content.fluids.tank.FluidTankCTBehaviour; 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.CTModel;
import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry; import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry;
import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.Iterate;
import io.github.fabricators_of_create.porting_lib.model.data.ModelData; import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
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.minecraft.client.resources.model.BakedModel; import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; 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.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.function.Supplier;
import java.util.List;
public class SteelFluidTankModel extends CTModel { public class SteelFluidTankModel extends CTModel {
protected static final ModelProperty<CullData> CULL_PROPERTY = new ModelProperty<>();
public static SteelFluidTankModel standard(BakedModel originalModel) { public static SteelFluidTankModel standard(BakedModel originalModel) {
return new SteelFluidTankModel(originalModel, TFMGSpriteShifts.STEEL_FLUID_TANK, TFMGSpriteShifts.STEEL_FLUID_TANK_TOP, return new SteelFluidTankModel(originalModel, TFMGSpriteShifts.STEEL_FLUID_TANK, TFMGSpriteShifts.STEEL_FLUID_TANK_TOP,
TFMGSpriteShifts.STEEL_FLUID_TANK_INNER); TFMGSpriteShifts.STEEL_FLUID_TANK_INNER);
} }
private SteelFluidTankModel(BakedModel originalModel, CTSpriteShiftEntry side, CTSpriteShiftEntry top, private SteelFluidTankModel(BakedModel originalModel, CTSpriteShiftEntry side, CTSpriteShiftEntry top,
CTSpriteShiftEntry inner) { CTSpriteShiftEntry inner) {
super(originalModel, new FluidTankCTBehaviour(side, top, inner)); super(originalModel, new FluidTankCTBehaviour(side, top, inner));
} }
@Override @Override
protected ModelData.Builder gatherModelData(ModelData.Builder builder, BlockAndTintGetter world, BlockPos pos, BlockState state, public void emitBlockQuads(BlockAndTintGetter blockView, BlockState state, BlockPos pos, Supplier<RandomSource> randomSupplier, RenderContext context) {
ModelData blockEntityData) { SteelFluidTankModel.CullData cullData = new SteelFluidTankModel.CullData();
super.gatherModelData(builder, world, pos, state, blockEntityData);
CullData cullData = new CullData();
for (Direction d : Iterate.horizontalDirections) for (Direction d : Iterate.horizontalDirections)
cullData.setCulled(d, ConnectivityHandler.isConnected(world, pos, pos.relative(d))); cullData.setCulled(d, ConnectivityHandler.isConnected(blockView, pos, pos.relative(d)));
return builder.with(CULL_PROPERTY, cullData);
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 private static class CullData {
public List<BakedQuad> getQuads(BlockState state, Direction side, RandomSource rand, ModelData extraData, RenderType renderType) {
if (side != null)
return Collections.emptyList();
List<BakedQuad> 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 {
boolean[] culledFaces; boolean[] culledFaces;
public CullData() { public CullData() {
@@ -87,3 +74,4 @@ public class SteelFluidTankModel extends CTModel {
} }
} }

View File

@@ -6,6 +6,8 @@ import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
import com.simibubi.create.AllPartialModels; 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.blockEntity.renderer.SafeBlockEntityRenderer;
import com.simibubi.create.foundation.fluid.FluidRenderer; import com.simibubi.create.foundation.fluid.FluidRenderer;
import com.simibubi.create.foundation.render.CachedBufferer; 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 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.transfer.fluid.FluidTank;
import io.github.fabricators_of_create.porting_lib.util.FluidStack; 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.MultiBufferSource;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
@@ -25,40 +28,40 @@ public class SteelFluidTankRenderer extends SafeBlockEntityRenderer<SteelTankBlo
public SteelFluidTankRenderer(BlockEntityRendererProvider.Context context) {} public SteelFluidTankRenderer(BlockEntityRendererProvider.Context context) {}
@Override @Override
protected void renderSafe(SteelTankBlockEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, protected void renderSafe(SteelTankBlockEntity be, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) { int light, int overlay) {
if (!te.isController()) if (!be.isController())
return; return;
if (!te.window) { if (!be.window) {
if (te.isDistillationTower) if (be.isDistillationTower)
renderAsDistillationTower(te, partialTicks, ms, buffer, light, overlay); renderAsDistillationTower(be, partialTicks, ms, buffer, light, overlay);
return; return;
} }
LerpedFloat fluidLevel = te.getFluidLevel(); LerpedFloat fluidLevel = be.getFluidLevel();
if (fluidLevel == null) if (fluidLevel == null)
return; return;
float capHeight = 1 / 4f; float capHeight = 1 / 4f;
float tankHullWidth = 1 / 16f + 1 / 128f; float tankHullWidth = 1 / 16f + 1 / 128f;
float minPuddleHeight = 1 / 16f; float minPuddleHeight = 1 / 16f;
float totalHeight = te.height - 2 * capHeight - minPuddleHeight; float totalHeight = be.height - 2 * capHeight - minPuddleHeight;
float level = fluidLevel.getValue(partialTicks); float level = fluidLevel.getValue(partialTicks);
if (level < 1 / (512f * totalHeight)) if (level < 1 / (512f * totalHeight))
return; return;
float clampedLevel = Mth.clamp(level * totalHeight, 0, totalHeight); float clampedLevel = Mth.clamp(level * totalHeight, 0, totalHeight);
FluidTank tank = te.tankInventory; FluidTank tank = be.tankInventory;
FluidStack fluidStack = tank.getFluid(); FluidStack fluidStack = tank.getFluid();
if (fluidStack.isEmpty()) if (fluidStack.isEmpty())
return; return;
boolean top = fluidStack.getType().getFluid().defaultFluidState().is; boolean top = FluidVariantAttributes.isLighterThanAir(fluidStack.getType());
float xMin = tankHullWidth; float xMin = tankHullWidth;
float xMax = xMin + te.width - 2 * tankHullWidth; float xMax = xMin + be.width - 2 * tankHullWidth;
float yMin = totalHeight + capHeight + minPuddleHeight - clampedLevel; float yMin = totalHeight + capHeight + minPuddleHeight - clampedLevel;
float yMax = yMin + clampedLevel; float yMax = yMin + clampedLevel;
@@ -68,7 +71,7 @@ public class SteelFluidTankRenderer extends SafeBlockEntityRenderer<SteelTankBlo
} }
float zMin = tankHullWidth; float zMin = tankHullWidth;
float zMax = zMin + te.width - 2 * tankHullWidth; float zMax = zMin + be.width - 2 * tankHullWidth;
ms.pushPose(); ms.pushPose();
ms.translate(0, clampedLevel - totalHeight, 0); ms.translate(0, clampedLevel - totalHeight, 0);
@@ -76,13 +79,13 @@ public class SteelFluidTankRenderer extends SafeBlockEntityRenderer<SteelTankBlo
ms.popPose(); ms.popPose();
} }
protected void renderAsDistillationTower(SteelTankBlockEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, protected void renderAsDistillationTower(SteelTankBlockEntity be, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) { int light, int overlay) {
BlockState blockState = te.getBlockState(); BlockState blockState = be.getBlockState();
VertexConsumer vb = buffer.getBuffer(RenderType.solid()); VertexConsumer vb = buffer.getBuffer(RenderType.solid());
ms.pushPose(); ms.pushPose();
TransformStack msr = TransformStack.cast(ms); TransformStack msr = TransformStack.cast(ms);
msr.translate(te.width / 2f, 0.5, te.width / 2f); msr.translate(be.width / 2f, 0.5, be.width / 2f);
float dialPivot = 5.75f / 16; float dialPivot = 5.75f / 16;
@@ -92,15 +95,15 @@ public class SteelFluidTankRenderer extends SafeBlockEntityRenderer<SteelTankBlo
CachedBufferer.partial(TFMGPartialModels.TOWER_GAUGE, blockState) CachedBufferer.partial(TFMGPartialModels.TOWER_GAUGE, blockState)
.rotateY(d.toYRot()) .rotateY(d.toYRot())
.unCentre() .unCentre()
.translate(te.width / 2f - 6 / 16f, 0, 0) .translate(be.width / 2f - 6 / 16f, 0, 0)
.light(light) .light(light)
.renderInto(ms, vb); .renderInto(ms, vb);
CachedBufferer.partial(AllPartialModels.BOILER_GAUGE_DIAL, blockState) CachedBufferer.partial(AllPartialModels.BOILER_GAUGE_DIAL, blockState)
.rotateY(d.toYRot()) .rotateY(d.toYRot())
.unCentre() .unCentre()
.translate(te.width / 2f - 6 / 16f, 0, 0) .translate(be.width / 2f - 6 / 16f, 0, 0)
.translate(0, dialPivot, dialPivot) .translate(0, dialPivot, dialPivot)
.rotateX(-te.visualGaugeRotation.getValue(partialTicks)) .rotateX(-be.visualGaugeRotation.getValue(partialTicks))
.translate(0, -dialPivot, -dialPivot) .translate(0, -dialPivot, -dialPivot)
.light(light) .light(light)
.renderInto(ms, vb); .renderInto(ms, vb);
@@ -111,8 +114,7 @@ public class SteelFluidTankRenderer extends SafeBlockEntityRenderer<SteelTankBlo
} }
@Override @Override
public boolean shouldRenderOffScreen(SteelTankBlockEntity te) { public boolean shouldRenderOffScreen(SteelTankBlockEntity be) {
return te.isController(); return be.isController();
} }
} }

View File

@@ -4,25 +4,34 @@ package com.drmangotea.createindustry.blocks.tanks;
import com.drmangotea.createindustry.registry.TFMGBlockEntities; import com.drmangotea.createindustry.registry.TFMGBlockEntities;
import com.simibubi.create.api.connectivity.ConnectivityHandler; import com.simibubi.create.api.connectivity.ConnectivityHandler;
import com.simibubi.create.content.equipment.wrench.IWrenchable; import com.simibubi.create.content.equipment.wrench.IWrenchable;
import com.simibubi.create.content.fluids.tank.FluidTankBlockEntity;
import com.simibubi.create.content.fluids.tank.FluidTankItem;
import com.simibubi.create.content.fluids.transfer.GenericItemEmptying; import com.simibubi.create.content.fluids.transfer.GenericItemEmptying;
import com.simibubi.create.content.fluids.transfer.GenericItemFilling; import com.simibubi.create.content.fluids.transfer.GenericItemFilling;
import com.simibubi.create.foundation.advancement.AdvancementBehaviour;
import com.simibubi.create.foundation.block.IBE; import com.simibubi.create.foundation.block.IBE;
import com.simibubi.create.foundation.blockEntity.ComparatorUtil; import com.simibubi.create.foundation.blockEntity.ComparatorUtil;
import com.simibubi.create.foundation.fluid.FluidHelper; import com.simibubi.create.foundation.fluid.FluidHelper;
import com.simibubi.create.foundation.fluid.FluidHelper.FluidExchange; import com.simibubi.create.foundation.fluid.FluidHelper.FluidExchange;
import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Lang;
import io.github.fabricators_of_create.porting_lib.block.CustomSoundTypeBlock;
import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil;
import io.github.fabricators_of_create.porting_lib.util.FluidStack;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributes;
import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.particles.BlockParticleOption; import net.minecraft.core.particles.BlockParticleOption;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource; import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.util.StringRepresentable; import net.minecraft.util.StringRepresentable;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.item.context.UseOnContext;
@@ -40,6 +49,7 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition.Builder; import net.minecraft.world.level.block.state.StateDefinition.Builder;
import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty; import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
@@ -47,33 +57,40 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
public class SteelTankBlock extends Block implements IWrenchable, IBE<SteelTankBlockEntity> { import java.util.function.Consumer;
public static final BooleanProperty TOP = BooleanProperty.create("top"); import static com.simibubi.create.content.fluids.tank.FluidTankBlock.SILENCED_METAL;
public static final BooleanProperty BOTTOM = BooleanProperty.create("bottom");
public static final EnumProperty<Shape> SHAPE = EnumProperty.create("shape", Shape.class);
private boolean creative; public class SteelTankBlock extends Block implements IWrenchable, IBE<SteelTankBlockEntity>, CustomSoundTypeBlock {
public static SteelTankBlock regular(Properties p_i48440_1_) { public static final BooleanProperty TOP = BooleanProperty.create("top");
return new SteelTankBlock(p_i48440_1_, false); public static final BooleanProperty BOTTOM = BooleanProperty.create("bottom");
public static final EnumProperty<Shape> 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_) { @Override
return new SteelTankBlock(p_i48440_1_, true); 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) { public static boolean isTank(BlockState state) {
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) {
return state.getBlock() instanceof SteelTankBlock; return state.getBlock() instanceof SteelTankBlock;
} }
@@ -83,7 +100,10 @@ public class SteelTankBlock extends Block implements IWrenchable, IBE<SteelTankB
return; return;
if (moved) if (moved)
return; return;
withBlockEntityDo(world, pos, SteelTankBlockEntity::updateConnectivity); Consumer<SteelTankBlockEntity> consumer = FluidTankItem.IS_PLACING_NBT
? SteelTankBlockEntity::queueConnectivityUpdate
: SteelTankBlockEntity::updateConnectivity;
withBlockEntityDo(world, pos, consumer);
} }
@Override @Override
@@ -91,17 +111,6 @@ public class SteelTankBlock extends Block implements IWrenchable, IBE<SteelTankB
p_206840_1_.add(TOP, BOTTOM, SHAPE); p_206840_1_.add(TOP, BOTTOM, SHAPE);
} }
@Override
public int getLightEmission(BlockState state, BlockGetter world, BlockPos pos) {
SteelTankBlockEntity tankAt = ConnectivityHandler.partAt(getBlockEntityType(), world, pos);
if (tankAt == null)
return 0;
SteelTankBlockEntity controllerTE = (SteelTankBlockEntity) tankAt.getControllerBE();
if (controllerTE == null || !controllerTE.window)
return 0;
return tankAt.luminosity;
}
@Override @Override
public InteractionResult onWrenched(BlockState state, UseOnContext context) { public InteractionResult onWrenched(BlockState state, UseOnContext context) {
withBlockEntityDo(context.getLevel(), context.getClickedPos(), SteelTankBlockEntity::toggleWindows); withBlockEntityDo(context.getLevel(), context.getClickedPos(), SteelTankBlockEntity::toggleWindows);
@@ -110,149 +119,143 @@ public class SteelTankBlock extends Block implements IWrenchable, IBE<SteelTankB
static final VoxelShape CAMPFIRE_SMOKE_CLIP = Block.box(0, 4, 0, 16, 16, 16); static final VoxelShape CAMPFIRE_SMOKE_CLIP = Block.box(0, 4, 0, 16, 16, 16);
@Override @Override
public VoxelShape getCollisionShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, public VoxelShape getCollisionShape(BlockState pState, BlockGetter pLevel, BlockPos pPos,
CollisionContext pContext) { CollisionContext pContext) {
if (pContext == CollisionContext.empty()) if (pContext == CollisionContext.empty())
return CAMPFIRE_SMOKE_CLIP; return CAMPFIRE_SMOKE_CLIP;
return pState.getShape(pLevel, pPos); return pState.getShape(pLevel, pPos);
}
@Override
public VoxelShape getBlockSupportShape(BlockState pState, BlockGetter pReader, BlockPos pPos) {
return Shapes.block();
}
@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, FluidTankBlockEntity::updateBoilerTemperature);
return pState;
}
@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 (heldItem.isEmpty())
return InteractionResult.PASS;
if (!player.isCreative())
return InteractionResult.PASS;
FluidExchange exchange = null;
SteelTankBlockEntity be = ConnectivityHandler.partAt(getBlockEntityType(), world, pos);
if (be == null)
return InteractionResult.FAIL;
Direction direction = ray.getDirection();
Storage<FluidVariant> 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 SoundEvent soundevent = null;
public VoxelShape getBlockSupportShape(BlockState pState, BlockGetter pReader, BlockPos pPos) { BlockState fluidState = null;
return Shapes.block(); 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 if (exchange == FluidExchange.TANK_TO_ITEM) {
public BlockState updateShape(BlockState pState, Direction pDirection, BlockState pNeighborState, Fluid fluid = prevFluidInTank.getFluid();
LevelAccessor pLevel, BlockPos pCurrentPos, BlockPos pNeighborPos) { fluidState = fluid.defaultFluidState()
if (pDirection == Direction.DOWN && pNeighborState.getBlock() != this) .createLegacyBlock();
withBlockEntityDo(pLevel, pCurrentPos, SteelTankBlockEntity::updateBoilerTemperature); soundevent = FluidVariantAttributes.getFillSound(FluidVariant.of(fluid));
return pState;
} }
@Override if (soundevent != null && !onClient) {
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, float pitch = Mth
BlockHitResult ray) { .clamp(1 - (1f * fluidInTank.getAmount() / (FluidTankBlockEntity.getCapacityMultiplier() * 16)), 0, 1);
ItemStack heldItem = player.getItemInHand(hand); pitch /= 1.5f;
boolean onClient = world.isClientSide; pitch += .5f;
pitch += (world.random.nextFloat() - .5f) / 4f;
world.playSound(null, pos, soundevent, SoundSource.BLOCKS, .5f, pitch);
}
if (heldItem.isEmpty()) if (!fluidInTank.isFluidEqual(prevFluidInTank)) {
return InteractionResult.PASS; if (be instanceof SteelTankBlockEntity) {
if (!player.isCreative() && !creative) SteelTankBlockEntity controllerBE = be.getControllerBE();
return InteractionResult.PASS; 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; boolean reversed = FluidVariantAttributes.isLighterThanAir(fluidInTank.getType());
SteelTankBlockEntity te = ConnectivityHandler.partAt(getBlockEntityType(), world, pos); if (reversed)
if (te == null) level = 1 - level;
return InteractionResult.FAIL;
LazyOptional<IFluidHandler> tankCapability = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY); Vec3 vec = ray.getLocation();
if (!tankCapability.isPresent()) vec = new Vec3(vec.x, controllerBE.getBlockPos()
return InteractionResult.PASS; .getY() + level * (controllerBE.height - .5f) + .25f, vec.z);
IFluidHandler fluidTank = tankCapability.orElse(null); Vec3 motion = player.position()
FluidStack prevFluidInTank = fluidTank.getFluidInTank(0) .subtract(vec)
.copy(); .scale(1 / 20f);
vec = vec.add(motion);
if (FluidHelper.tryEmptyItemIntoBE(world, player, hand, heldItem, te)) world.addParticle(blockParticleData, vec.x, vec.y, vec.z, motion.x, motion.y, motion.z);
exchange = FluidExchange.ITEM_TO_TANK; return InteractionResult.SUCCESS;
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();
} }
controllerBE.sendDataImmediately();
controllerBE.setChanged();
} }
} }
return InteractionResult.SUCCESS;
} }
@Override return InteractionResult.SUCCESS;
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);
}
}
@Override @Override
public Class<SteelTankBlockEntity> getBlockEntityClass() { 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<SteelTankBlockEntity> getBlockEntityClass() {
return SteelTankBlockEntity.class; return SteelTankBlockEntity.class;
} }
@Override @Override
public BlockEntityType<? extends SteelTankBlockEntity> getBlockEntityType() { public BlockEntityType<? extends SteelTankBlockEntity> getBlockEntityType() {
return creative ? TFMGBlockEntities.STEEL_FLUID_TANK.get() : TFMGBlockEntities.STEEL_FLUID_TANK.get(); return TFMGBlockEntities.STEEL_FLUID_TANK.get();
} }
@Override @Override
public BlockState mirror(BlockState state, Mirror mirror) { public BlockState mirror(BlockState state, Mirror mirror) {
@@ -304,15 +307,10 @@ public class SteelTankBlock extends Block implements IWrenchable, IBE<SteelTankB
} }
} }
// Tanks are less noisy when placed in batch
public static final SoundType SILENCED_METAL =
new ForgeSoundType(0.1F, 1.5F, () -> SoundEvents.METAL_BREAK, () -> SoundEvents.METAL_STEP,
() -> SoundEvents.METAL_PLACE, () -> SoundEvents.METAL_HIT, () -> SoundEvents.METAL_FALL);
@Override @Override
public SoundType getSoundType(BlockState state, LevelReader world, BlockPos pos, Entity entity) { public SoundType getSoundType(BlockState state, LevelReader world, BlockPos pos, Entity entity) {
SoundType soundType = super.getSoundType(state, world, pos, entity); SoundType soundType = getSoundType(state);
if (entity != null && entity.getPersistentData() if (entity != null && entity.getExtraCustomData()
.contains("SilenceTankSound")) .contains("SilenceTankSound"))
return SILENCED_METAL; return SILENCED_METAL;
return soundType; return soundType;

View File

@@ -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;
import com.simibubi.create.foundation.utility.animation.LerpedFloat.Chaser; import com.simibubi.create.foundation.utility.animation.LerpedFloat.Chaser;
import com.simibubi.create.infrastructure.config.AllConfigs; 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.transfer.fluid.FluidTank;
import io.github.fabricators_of_create.porting_lib.util.FluidStack; import io.github.fabricators_of_create.porting_lib.util.FluidStack;
import io.github.fabricators_of_create.porting_lib.util.LazyOptional; 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.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.Transaction;
import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@@ -147,14 +150,14 @@ public class SteelTankBlockEntity extends FluidTankBlockEntity implements IHaveG
removeController(true); removeController(true);
lastKnownPos = worldPosition; lastKnownPos = worldPosition;
} }
protected void onFluidStackChanged(FluidStack newFluidStack) { protected void onFluidStackChanged(FluidStack newFluidStack) {
if (!hasLevel()) if (!hasLevel())
return; return;
FluidVariant attributes = newFluidStack.getType(); FluidVariantAttributeHandler handler = FluidVariantAttributes.getHandlerOrDefault(newFluidStack.getFluid());
int luminosity = (int) (attributes.getLightLevel(newFluidStack) / 1.2f); FluidVariant variant = newFluidStack.getType();
boolean reversed = attributes.isLighterThanAir(); int luminosity = (int) (handler.getLuminance(variant) / 1.2f);
boolean reversed = handler.isLighterThanAir(variant);
int maxY = (int) ((getFillState() * height) + 1); int maxY = (int) ((getFillState() * height) + 1);
for (int yOffset = 0; yOffset < height; yOffset++) { for (int yOffset = 0; yOffset < height; yOffset++) {
@@ -446,17 +449,14 @@ public class SteelTankBlockEntity extends FluidTankBlockEntity implements IHaveG
@Override @Override
public boolean addToGoggleTooltip(List<Component> tooltip, boolean isPlayerSneaking) { public boolean addToGoggleTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
SteelTankBlockEntity controllerTE = getControllerBE(); SteelTankBlockEntity controllerBE = getControllerBE();
if(isDistillationTower) if (isDistillationTower)
return false; return false;
if (controllerBE != null && controllerBE.isDistillationTower)
if(getControllerBE()!=null) return true;
if(getControllerBE().isDistillationTower)
return false;
return containedFluidTooltip(tooltip, isPlayerSneaking, return containedFluidTooltip(tooltip, isPlayerSneaking,
controllerTE.getCapability(ForgeCapabilities.FLUID_HANDLER)); controllerBE.getFluidStorage(null));
} }
@Override @Override
@@ -486,7 +486,10 @@ public class SteelTankBlockEntity extends FluidTankBlockEntity implements IHaveG
tankInventory.setCapacity(getTotalTankSize() * getCapacityMultiplier()); tankInventory.setCapacity(getTotalTankSize() * getCapacityMultiplier());
tankInventory.readFromNBT(compound.getCompound("TankContent")); tankInventory.readFromNBT(compound.getCompound("TankContent"));
if (tankInventory.getSpace() < 0) 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; return MAX_SIZE;
} }
public static int getCapacityMultiplier() { public static long getCapacityMultiplier() {
return AllConfigs.server().fluids.fluidTankCapacity.get() * 1000; return AllConfigs.server().fluids.fluidTankCapacity.get() * 1000;
} }

View File

@@ -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);
}
}

View File

@@ -11,6 +11,8 @@ import com.simibubi.create.content.equipment.zapper.ShootableGadgetItemMethods;
import com.simibubi.create.foundation.item.CustomArmPoseItem; import com.simibubi.create.foundation.item.CustomArmPoseItem;
import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.infrastructure.config.AllConfigs; 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.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@@ -35,8 +37,8 @@ import org.jetbrains.annotations.Nullable;
import java.util.Optional; import java.util.Optional;
import java.util.function.Predicate; 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 ItemStack CLIENT_CURRENT_AMMO = ItemStack.EMPTY;
public static final int MAX_DAMAGE = 500; public static final int MAX_DAMAGE = 500;
@@ -219,10 +221,6 @@ public class AdvancedPotatoCannonItem extends ProjectileWeaponItem implements Cu
return 15; return 15;
} }
@Override
@Environment(EnvType.CLIENT)
public void initializeClient(Consumer<IClientItemExtensions> consumer) {
consumer.accept(SimpleCustomRenderer.create(this, new AdvancedPotatoCannonItemRenderer()));
}
} }

View File

@@ -18,8 +18,6 @@ import net.minecraft.world.item.ItemStack;
public class AdvancedPotatoCannonItemRenderer extends CustomRenderedItemModelRenderer { public class AdvancedPotatoCannonItemRenderer extends CustomRenderedItemModelRenderer {
@Override @Override
protected void render(ItemStack stack, CustomRenderedItemModel model, PartialItemModelRenderer renderer, protected void render(ItemStack stack, CustomRenderedItemModel model, PartialItemModelRenderer renderer,
TransformType transformType, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { TransformType transformType, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {

View File

@@ -5,6 +5,7 @@ import com.drmangotea.createindustry.base.util.spark.Spark;
import com.drmangotea.createindustry.registry.TFMGCreativeModeTabs; import com.drmangotea.createindustry.registry.TFMGCreativeModeTabs;
import com.drmangotea.createindustry.registry.TFMGEntityTypes; import com.drmangotea.createindustry.registry.TFMGEntityTypes;
import com.drmangotea.createindustry.registry.TFMGItems; 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.content.fluids.tank.FluidTankBlockEntity;
import com.simibubi.create.foundation.item.CustomArmPoseItem; import com.simibubi.create.foundation.item.CustomArmPoseItem;
import net.minecraft.client.model.HumanoidModel; import net.minecraft.client.model.HumanoidModel;
@@ -27,6 +28,8 @@ import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import static com.drmangotea.createindustry.base.util.TFMGUtils.drain;
public class FlamethrowerItem extends Item implements CustomArmPoseItem { 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()); long toDrain = Math.min(FUEL_CAPACITY - nbt.getInt("amount"), be.getFluid(0).getAmount());
nbt.putString("fuel", fluid); nbt.putString("fuel", fluid);
be.getTankInventory().drain(toDrain, IFluidHandler.FluidAction.EXECUTE); drain(be.getTankInventory(), toDrain);
nbt.putLong("amount", nbt.getLong("amount") + toDrain); nbt.putLong("amount", nbt.getLong("amount") + toDrain);
context.getPlayer().getCooldowns().addCooldown(stack.getItem(), 20); context.getPlayer().getCooldowns().addCooldown(stack.getItem(), 20);

View File

@@ -14,6 +14,9 @@ import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.foundation.utility.Components; import com.simibubi.create.foundation.utility.Components;
import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.foundation.utility.VecHelper; 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.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
@@ -48,7 +51,8 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.function.Predicate; 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 ItemStack CLIENT_CURRENT_AMMO = ItemStack.EMPTY;
public static final int MAX_DAMAGE = 100; public static final int MAX_DAMAGE = 100;
@@ -74,7 +78,7 @@ public class QuadPotatoCannonItem extends ProjectileWeaponItem implements Custom
return true; return true;
if (enchantment == AllEnchantments.POTATO_RECOVERY.get()) if (enchantment == AllEnchantments.POTATO_RECOVERY.get())
return true; return true;
return super.canApplyAtEnchantingTable(stack, enchantment); return false;
} }
@Override @Override

View File

@@ -6,6 +6,7 @@ import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f; import com.mojang.math.Vector3f;
import com.simibubi.create.content.equipment.potatoCannon.PotatoCannonItem; 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.CustomRenderedItemModel;
import com.simibubi.create.foundation.item.render.CustomRenderedItemModelRenderer; import com.simibubi.create.foundation.item.render.CustomRenderedItemModelRenderer;
import com.simibubi.create.foundation.item.render.PartialItemModelRenderer; import com.simibubi.create.foundation.item.render.PartialItemModelRenderer;