Skip to content

Commit

Permalink
Remove LDLib FluidTransfer stuffs for prep for 1.4.7 (#58)
Browse files Browse the repository at this point in the history
* remove all uses of ldlib fluid transfer in preparation for 1.4.7

* fixes and renaming broken gcym path
  • Loading branch information
YoungOnionMC authored Nov 12, 2024
1 parent cf43d6a commit 57aa068
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 72 deletions.
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ dependencyResolutionManagement {
def vineFlowerVersion = "1.+"
def macheteVersion = "1.+"
def configurationVersion = "2.2.0"
def gtCeuVersion = "1.4.4"
def ldLibVersion = "1.0.29.a"
def gtCeuVersion = "1.4.7-SNAPSHOT"
def ldLibVersion = "1.0.30.a"
def mixinExtrasVersion = "0.2.0"
def mixinVersion = "0.8.6-SNAPSHOT"

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/argent_matter/gcyr/GCYRGTAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@
import com.gregtechceu.gtceu.api.addon.GTAddon;
import com.gregtechceu.gtceu.api.addon.IGTAddon;
import com.gregtechceu.gtceu.api.addon.events.MaterialCasingCollectionEvent;
import com.gregtechceu.gtceu.api.data.chemical.material.event.PostMaterialEvent;
import com.gregtechceu.gtceu.api.data.chemical.material.properties.FluidProperty;
import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey;
import com.gregtechceu.gtceu.api.data.tag.TagPrefix;
import com.gregtechceu.gtceu.api.fluids.FluidBuilder;
import com.gregtechceu.gtceu.api.fluids.store.FluidStorageKeys;
import com.gregtechceu.gtceu.api.registry.registrate.GTRegistrate;
import com.gregtechceu.gtceu.common.data.GTMaterials;
import net.minecraft.data.recipes.FinishedRecipe;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.MapColor;
import net.minecraftforge.eventbus.api.SubscribeEvent;

import java.util.function.Consumer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ public interface IFuelTankProperties extends StringRepresentable {
/**
* @return how much fuel this tank can store at maximum.
*/
long getFuelStorage();
int getFuelStorage();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class SimpleFuelTankProperties implements IFuelTankProperties {
@Getter
private final int tier;
@Getter
private final long fuelStorage;
private final int fuelStorage;

public SimpleFuelTankProperties(String name, int tier, long fuelStorage) {
public SimpleFuelTankProperties(String name, int tier, int fuelStorage) {
this.tier = tier;
this.fuelStorage = fuelStorage;
this.serializedName = name;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/argent_matter/gcyr/common/block/FuelTankBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import argent_matter.gcyr.api.block.IFuelTankProperties;
import argent_matter.gcyr.api.block.IRocketPart;
import com.lowdragmc.lowdraglib.side.fluid.FluidHelper;
import lombok.Getter;
import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraftforge.fluids.FluidType;

public class FuelTankBlock extends RotatedPillarBlock implements IRocketPart {

Expand All @@ -22,19 +22,19 @@ public int getTier() {
}

public enum FuelTankProperties implements IFuelTankProperties {
BASIC("basic", 1, 5 * FluidHelper.getBucket()),
ADVANCED("advanced", 2, 7 * FluidHelper.getBucket()),
ELITE("elite", 3, 12 * FluidHelper.getBucket()),
BASIC("basic", 1, 5 * FluidType.BUCKET_VOLUME),
ADVANCED("advanced", 2, 7 * FluidType.BUCKET_VOLUME),
ELITE("elite", 3, 12 * FluidType.BUCKET_VOLUME),
;

@Getter
private final String serializedName;
@Getter
private final int tier;
@Getter
private final long fuelStorage;
private final int fuelStorage;

FuelTankProperties(String serializedName, int tier, long fuelStorage) {
FuelTankProperties(String serializedName, int tier, int fuelStorage) {
this.tier = tier;
this.fuelStorage = fuelStorage;
this.serializedName = serializedName;
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/argent_matter/gcyr/common/data/GCYRMachines.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@
import com.gregtechceu.gtceu.common.data.GTRecipeModifiers;
import com.gregtechceu.gtceu.common.data.GTRecipeTypes;
import com.gregtechceu.gtceu.config.ConfigHolder;
import com.lowdragmc.lowdraglib.side.fluid.FluidHelper;
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
import it.unimi.dsi.fastutil.ints.Int2LongFunction;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.DoorBlock;
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
import net.minecraftforge.fluids.FluidType;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -44,7 +45,7 @@
import static argent_matter.gcyr.common.data.GCYRBlocks.*;
import static com.gregtechceu.gtceu.api.GTValues.*;
import static com.gregtechceu.gtceu.api.pattern.Predicates.*;
import static com.gregtechceu.gtceu.common.data.GCyMBlocks.CASING_ATOMIC;
import static com.gregtechceu.gtceu.common.data.GCYMBlocks.CASING_ATOMIC;
import static com.gregtechceu.gtceu.common.data.GTBlocks.*;
import static com.gregtechceu.gtceu.common.data.GTMachines.POWER_TRANSFORMER;
import static com.gregtechceu.gtceu.utils.FormattingUtil.toEnglishName;
Expand All @@ -54,7 +55,7 @@ public class GCYRMachines {
public final static int[] ELECTRIC_TIERS = GTValues.tiersBetween(LV, GTCEuAPI.isHighTier() ? OpV : UV);
public final static int[] LOW_TIERS = GTValues.tiersBetween(LV, EV);
public final static int[] HIGH_TIERS = GTValues.tiersBetween(IV, GTCEuAPI.isHighTier() ? OpV : UHV);
public static final Int2LongFunction defaultTankSizeFunction = tier -> (tier <= GTValues.LV ? 8 : tier == GTValues.MV ? 12 : tier == GTValues.HV ? 16 : tier == GTValues.EV ? 32 : 64) * FluidHelper.getBucket();
public static final Int2IntFunction defaultTankSizeFunction = tier -> (tier <= GTValues.LV ? 8 : tier == GTValues.MV ? 12 : tier == GTValues.HV ? 16 : tier == GTValues.EV ? 32 : 64) * FluidType.BUCKET_VOLUME;


public final static MachineDefinition[] OXYGEN_SPREADER = registerTieredMachines("oxygen_spreader", OxygenSpreaderMachine::new,
Expand Down Expand Up @@ -164,7 +165,7 @@ public class GCYRMachines {

public static final MultiblockMachineDefinition DYSON_SYSTEM_CONTROLLER = REGISTRATE.multiblock("dyson_system_controller", DysonSystemControllerMachine::new)
.rotationState(RotationState.NON_Y_AXIS)
.appearanceBlock(() -> CASING_ATOMIC.get()) // You MUST do it like this, so that the GTBlocks/GCyMBlocks class isn't loaded too early. Because that causes a crash.
.appearanceBlock(() -> CASING_ATOMIC.get()) // You MUST do it like this, so that the GTBlocks/GCYMBlocks class isn't loaded too early. Because that causes a crash.
.recipeType(GCYRRecipeTypes.DYSON_ENERGY_RECIPES)
.tier(GTValues.UV)
.pattern(definition -> FactoryBlockPattern.start()
Expand Down Expand Up @@ -253,7 +254,7 @@ public class GCYRMachines {

public static MachineDefinition[] registerSimpleMachines(String name,
GTRecipeType recipeType,
Int2LongFunction tankScalingFunction,
Int2IntFunction tankScalingFunction,
int... tiers) {
return registerTieredMachines(name, (holder, tier) -> new SimpleTieredMachine(holder, tier, tankScalingFunction), (tier, builder) -> builder
.langValue("%s %s %s".formatted(VLVH[tier], toEnglishName(name), VLVT[tier]))
Expand All @@ -267,7 +268,7 @@ public static MachineDefinition[] registerSimpleMachines(String name,
.register(), tiers);
}

public static MachineDefinition[] registerSimpleMachines(String name, GTRecipeType recipeType, Int2LongFunction tankScalingFunction) {
public static MachineDefinition[] registerSimpleMachines(String name, GTRecipeType recipeType, Int2IntFunction tankScalingFunction) {
return registerSimpleMachines(name, recipeType, tankScalingFunction, ELECTRIC_TIERS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.gregtechceu.gtceu.api.fluids.FluidBuilder;
import com.gregtechceu.gtceu.api.fluids.attribute.FluidAttributes;
import com.gregtechceu.gtceu.api.fluids.store.FluidStorageKeys;
import com.gregtechceu.gtceu.common.data.GTMaterials;

import static com.gregtechceu.gtceu.api.data.chemical.material.info.MaterialFlags.*;
import static com.gregtechceu.gtceu.api.data.chemical.material.info.MaterialFlags.GENERATE_PLATE;
Expand All @@ -27,6 +28,8 @@ public static void modifyMaterials() {
IronMagnetic.addFlags(GENERATE_FOIL);
TitaniumTungstenCarbide.addFlags(GENERATE_ROD);
Titanium.setProperty(PropertyKey.ORE, new OreProperty());

GTMaterials.Hydrogen.getProperty(PropertyKey.FLUID).enqueueRegistration(FluidStorageKeys.PLASMA, new FluidBuilder());
}

//region first degree mats
Expand Down
44 changes: 23 additions & 21 deletions src/main/java/argent_matter/gcyr/common/entity/RocketEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
import com.gregtechceu.gtceu.api.capability.recipe.FluidRecipeCapability;
import com.gregtechceu.gtceu.api.gui.GuiTextures;
import com.gregtechceu.gtceu.api.gui.UITemplate;
import com.gregtechceu.gtceu.api.gui.widget.TankWidget;
import com.gregtechceu.gtceu.api.item.ComponentItem;
import com.gregtechceu.gtceu.api.item.component.IItemComponent;
import com.gregtechceu.gtceu.api.recipe.GTRecipe;
import com.gregtechceu.gtceu.api.recipe.RecipeHelper;
import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank;
import com.lowdragmc.lowdraglib.gui.modular.IUIHolder;
import com.lowdragmc.lowdraglib.gui.modular.ModularUI;
import com.lowdragmc.lowdraglib.gui.texture.GuiTextureGroup;
Expand All @@ -40,10 +42,7 @@
import com.lowdragmc.lowdraglib.gui.widget.ButtonWidget;
import com.lowdragmc.lowdraglib.gui.widget.LabelWidget;
import com.lowdragmc.lowdraglib.gui.widget.SlotWidget;
import com.lowdragmc.lowdraglib.gui.widget.TankWidget;
import com.lowdragmc.lowdraglib.misc.FluidStorage;
import com.lowdragmc.lowdraglib.misc.ItemStackTransfer;
import com.lowdragmc.lowdraglib.side.fluid.FluidStack;
import com.mojang.datafixers.util.Pair;
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
Expand Down Expand Up @@ -90,6 +89,8 @@
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.entity.IEntityAdditionalSpawnData;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.network.NetworkHooks;

import javax.annotation.Nullable;
Expand All @@ -104,8 +105,8 @@ public class RocketEntity extends Entity implements HasCustomInventoryScreen, IU

// protected static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(RocketEntity.class);
public static final EntityDataAccessor<Boolean> ROCKET_STARTED = SynchedEntityData.defineId(RocketEntity.class, EntityDataSerializers.BOOLEAN);
public static final EntityDataAccessor<Long> FUEL_CAPACITY = SynchedEntityData.defineId(RocketEntity.class, GCYREntityDataSerializers.LONG);
public static final EntityDataAccessor<Long> FUEL_AMOUNT = SynchedEntityData.defineId(RocketEntity.class, GCYREntityDataSerializers.LONG);
public static final EntityDataAccessor<Integer> FUEL_CAPACITY = SynchedEntityData.defineId(RocketEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> FUEL_AMOUNT = SynchedEntityData.defineId(RocketEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> THRUSTER_COUNT = SynchedEntityData.defineId(RocketEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> WEIGHT = SynchedEntityData.defineId(RocketEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> RECIPE_DURATION = SynchedEntityData.defineId(RocketEntity.class, EntityDataSerializers.INT);
Expand All @@ -118,7 +119,7 @@ public class RocketEntity extends Entity implements HasCustomInventoryScreen, IU
// @Getter
// private final FieldManagedStorage syncStorage = new FieldManagedStorage(this);

private final FluidStorage fuelTank;
private final CustomFluidTank fuelTank;
private final ItemStackTransfer configSlot, satelliteSlot;
private boolean destinationIsSpaceStation;
private final Object2IntMap<IRocketPart> partCounts = new Object2IntOpenHashMap<>();
Expand All @@ -140,9 +141,10 @@ public RocketEntity(EntityType<?> entityType, Level level) {
this.satelliteSlot = new ItemStackTransfer(1);
this.satelliteSlot.setFilter(stack -> GCYRItems.SPACE_STATION_PACKAGE.isIn(stack) || stack.is(GCYRTags.SATELLITES));

this.fuelTank = new FluidStorage(0, fluid -> FUEL_CACHE.computeIfAbsent(fluid.getFluid(), f -> {
this.fuelTank = new CustomFluidTank(0, fluid -> FUEL_CACHE.computeIfAbsent(fluid.getFluid(), f-> {
return this.getServer().getRecipeManager().getAllRecipesFor(GCYRRecipeTypes.ROCKET_FUEL_RECIPES).stream().anyMatch(recipe -> {
if (RecipeHelper.getInputEUt(recipe) > motorTier) return false; // don't allow > motor tier fuels to be used.
if (RecipeHelper.getInputEUt(recipe) > motorTier)
return false; // don't allow > motor tier fuels to be used.

var list = recipe.inputs.getOrDefault(FluidRecipeCapability.CAP, Collections.emptyList());
if (!list.isEmpty()) {
Expand Down Expand Up @@ -383,10 +385,10 @@ public void rotateRocket() {
}
}

public long computeRequiredFuelAmountForDestination(@Nullable Planet destination) {
public int computeRequiredFuelAmountForDestination(@Nullable Planet destination) {
Planet current = PlanetData.getPlanetFromLevelOrOrbit(this.level().dimension()).orElse(null);
if (current == null || destination == null) {
return (long) (this.getFuelCapacity() * 0.85);
return (int)(this.getFuelCapacity() * 0.85);
} else if (destination.parentWorld() == current.level() || current.parentWorld() == destination.level() || current == destination) {
return GCYRConfig.INSTANCE.rocket.moonFuelAmount;
} else if (current.solarSystem().equals(destination.solarSystem())) {
Expand Down Expand Up @@ -549,7 +551,7 @@ private boolean consumeFuel() {
}

var drain = (getThrusterCount() + destinationRocketTier) / (recipeDuration / 20.0 + 1) * 2;
var ldrain = (long)drain;
var ldrain = (int)drain;

// estimate fuel consumption client side; client needs to know if
// it should run the flight tick and if it should slow down in fall(),
Expand All @@ -559,8 +561,8 @@ private boolean consumeFuel() {
return (fuelAmount - ldrain) > 0;
}

if (!this.fuelTank.drain(ldrain, true).isEmpty()) {
return !this.fuelTank.drain(ldrain, false).isEmpty();
if (!this.fuelTank.drain(ldrain, IFluidHandler.FluidAction.SIMULATE).isEmpty()) {
return !this.fuelTank.drain(ldrain, IFluidHandler.FluidAction.EXECUTE).isEmpty();
}
return false;
}
Expand Down Expand Up @@ -596,7 +598,7 @@ private void goToDestination() {
ResourceKey<Level> destinationDim = this.destinationIsSpaceStation ? getDestination().orbitWorld() : getDestination().level();

// Go to a random valid planet if rocket doesn't have enough fuel to get to actual destination somehow.
if (this.fuelTank.drain(computeRequiredFuelAmountForDestination(this.getDestination()) / 3, true).isEmpty()) {
if (this.fuelTank.drain(computeRequiredFuelAmountForDestination(this.getDestination()) / 3, IFluidHandler.FluidAction.SIMULATE).isEmpty()) {
List<Planet> validPlanets = new ArrayList<>();
for (Planet planet : PlanetData.planets().values()) {
if (planet.solarSystem().equals(this.getDestination().solarSystem())) {
Expand Down Expand Up @@ -794,11 +796,11 @@ public boolean canBeCollidedWith() {
return true;
}

public long getFuelCapacity() {
public int getFuelCapacity() {
return this.entityData.get(FUEL_CAPACITY);
}

public void setFuelCapacity(long fuelCapacity) {
public void setFuelCapacity(int fuelCapacity) {
this.entityData.set(FUEL_CAPACITY, fuelCapacity);
this.reinitializeFluidStorage();
}
Expand Down Expand Up @@ -945,12 +947,12 @@ public double getRocketSpeed() {
@Override
protected void defineSynchedData() {
this.entityData.define(ROCKET_STARTED, false);
this.entityData.define(FUEL_CAPACITY, 0L);
this.entityData.define(FUEL_CAPACITY, 0);
this.entityData.define(THRUSTER_COUNT, 0);
this.entityData.define(WEIGHT, 0);
this.entityData.define(RECIPE_DURATION, 0);
this.entityData.define(START_TIMER, 0);
this.entityData.define(FUEL_AMOUNT, 0L);
this.entityData.define(FUEL_AMOUNT, 0);
this.entityData.define(POSITIONED_STATES, new ArrayList<>());
this.entityData.define(SEAT_POSITIONS, new ArrayList<>());
this.entityData.define(SIZE, BlockPos.ZERO);
Expand All @@ -965,8 +967,8 @@ protected void readAdditionalSaveData(CompoundTag compound) {
this.addBlock(PosWithState.readFromTag(blocks.getCompound(i)));
}

this.setFuelCapacity(compound.getLong("fuelCapacity"));
this.fuelTank.setFluid(FluidStack.loadFromTag(compound.getCompound("fuel")));
this.setFuelCapacity(compound.getInt("fuelCapacity"));
this.fuelTank.setFluid(FluidStack.loadFluidStackFromNBT(compound.getCompound("fuel")));
this.configSlot.deserializeNBT(compound.getCompound("config"));
this.returnToStart = compound.getBoolean("returnToStart");
if (compound.contains("satelliteToLaunch")) {
Expand Down Expand Up @@ -995,7 +997,7 @@ protected void addAdditionalSaveData(CompoundTag compound) {

compound.putLong("fuelCapacity", this.getFuelCapacity());
CompoundTag fuel = new CompoundTag();
fuelTank.getFluid().saveToTag(fuel);
fuelTank.getFluid().writeToNBT(fuel);
compound.put("fuel", fuel);
compound.put("config", this.configSlot.serializeNBT());
compound.putBoolean("returnToStart", this.returnToStart);
Expand Down
Loading

0 comments on commit 57aa068

Please sign in to comment.