Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 3 additions & 18 deletions docs/content/Modpacks/Changes/v8.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,8 @@ The constructors for a large number of machines have changed in order to simply

#### **All Machines**
- Replace the first constructor argument `IMachineBlockEntity holder` with `BlockEntityCreationInfo info`
#### `TieredEnergyMachine`
- Removed `createEnergyContainer` method
- Constructor now has an optional `NotifiableEnergyContainer` argument
#### `WorkableTieredMachine`
- Removed `createRecipeLogic`, `createImportItemHandler`, `createExportItemHandler`, `createImportFluidHandler`, `createExportFluidHandler` methods
- Added a new constructor:
- `BlockEntityCreationInfo info`
- `int tier`
- `RecipeLogic recipeLogic` Recipe logic, defaults to the standard `RecipeLogic` class.
- `int importSlots` Item import slots, defaults to the amount of slots in the machine's default recipe type.
- `int exportSlots` Same as above, but for item export slots.
- `int fluidImportSlots` As above, but for fluid import slots.
- `int fluidExportSlots` As above, but for fluid export slots.
- `boolean isEnergyEmitter` If this machine should emit/receiver energy.
- `Int2IntFunction tankScalingFunction` Fluid tank capacity scaling function.
#### `WorkableMultiblockMachine`, `WorkableElectricMultiblockMachine` and `SteamWorkableMachine`
- Removed `createRecipeLogic` method
- Constructor now has an optional `Supplier<RecipeLogic>` argument, defaults to the standard `RecipeLogic` class
#### Machines with `createX` functions (e.g. `createEnergyContainer`, `createRecipeLogic`)
- Creation functions have been removed in favor of arguments being passed into the constructor.

#### IMPORTANT MIGRATION NOTE:

Expand All @@ -110,6 +94,7 @@ When migrating, remove the `this` argument from the machine trait constructor an

A large number of machine feature interfaces have been removed, and have had their functionality merged into the standard MetaMachine class, or now use the new machine trait system:

- `IWorkableMultiController` User the `WorkableMultiblockMachine` class directly.
- `ITurbineMachine` Use the `LargeTurbineMachine` class directly.
- `IRotorHolderMachine` Use the `RotorHolderMachine` class directly.
- `IMultiController` Use the `MultiblockControllerMachine` class directly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,8 @@ public void setPlacedBy(Level pLevel, BlockPos pPos, BlockState pState, @Nullabl
machine.setOwnerUUID(sPlayer.getUUID());
}

if (machine instanceof IDropSaveMachine dropSaveMachine) {
CompoundTag tag = pStack.getTag();
if (tag != null) {
dropSaveMachine.loadFromItem(tag);
}
}
CompoundTag tag = pStack.getTag();
if (tag != null) machine.loadFromItem(tag);
}
}
}
Expand Down Expand Up @@ -177,10 +173,8 @@ public BlockState getStateForPlacement(BlockPlaceContext context) {
@Override
public ItemStack getCloneItemStack(BlockGetter level, BlockPos pos, BlockState state) {
ItemStack itemStack = super.getCloneItemStack(level, pos, state);
if (MetaMachine.getMachine(level, pos) instanceof IDropSaveMachine dropSaveMachine &&
dropSaveMachine.savePickClone()) {
dropSaveMachine.saveToItem(itemStack.getOrCreateTag());
}
var machine = MetaMachine.getMachine(level, pos);
if (machine != null) machine.saveToItem(itemStack.getOrCreateTag(), true);
return itemStack;
}

Expand Down Expand Up @@ -231,13 +225,11 @@ public List<ItemStack> getDrops(BlockState state, LootParams.Builder builder) {
BlockEntity be = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
if (be instanceof MetaMachine machine) {
machine.modifyDrops(drops);
if (machine instanceof IDropSaveMachine dropSaveMachine && dropSaveMachine.saveBreak()) {
for (ItemStack drop : drops) {
if (drop.getItem() instanceof MetaMachineItem item && item.getBlock() == this) {
dropSaveMachine.saveToItem(drop.getOrCreateTag());
// break here to not dupe contents if a machine drops multiple of itself for whatever reason.
break;
}
for (ItemStack drop : drops) {
if (drop.getItem() instanceof MetaMachineItem item && item.getBlock() == this) {
machine.saveToItem(drop.getOrCreateTag(), false);
// break here to not dupe contents if a machine drops multiple of itself for whatever reason.
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.UnknownNullability;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -101,6 +102,11 @@ public long getOffsetTimer() {
return level == null ? offset : (level.getServer().getTickCount() + offset);
}

@Override
public @UnknownNullability Level getLevel() {
return super.getLevel();
}

@Override
public void setRemoved() {
super.setRemoved();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import lombok.Setter;
import lombok.experimental.Accessors;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.EnumMap;
Expand Down Expand Up @@ -61,7 +60,7 @@ public class MachineDefinition implements Supplier<MetaMachineBlock> {
private Supplier<BlockEntityType<? extends BlockEntity>> blockEntityTypeSupplier;
@Getter
@Setter
private @NotNull GTRecipeType @NotNull [] recipeTypes;
private GTRecipeType[] recipeTypes;
@Getter
@Setter
private int tier;
Expand All @@ -74,19 +73,15 @@ public class MachineDefinition implements Supplier<MetaMachineBlock> {
@Getter
@Setter
private boolean alwaysTryModifyRecipe;
@NotNull
@Getter
@Setter
private BiPredicate<IRecipeLogicMachine, GTRecipe> beforeWorking = (machine, recipe) -> true;
@NotNull
@Getter
@Setter
private Predicate<IRecipeLogicMachine> onWorking = (machine) -> true;
@NotNull
@Getter
@Setter
private Consumer<IRecipeLogicMachine> onWaiting = (machine) -> {};
@NotNull
@Getter
@Setter
private Consumer<IRecipeLogicMachine> afterWorking = (machine) -> {};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.gregtechceu.gtceu.api.machine;

import com.gregtechceu.gtceu.api.blockentity.BlockEntityCreationInfo;

import java.util.function.Consumer;

@FunctionalInterface
public interface MachineInstanceFactory<T extends MetaMachine> {

T buildMachine(BlockEntityCreationInfo info);

default MachineInstanceFactory<T> andThen(Consumer<T> modifier) {
return (info) -> {
T machine = this.buildMachine(info);
modifier.accept(machine);
return machine;
};
}

@FunctionalInterface
interface Tiered<T extends MetaMachine> {

T buildMachine(BlockEntityCreationInfo info, int tier);

default Tiered<T> andThen(Consumer<T> modifier) {
return (info, tier) -> {
T machine = buildMachine(info, tier);
modifier.accept(machine);
return machine;
};
}
}

@FunctionalInterface
interface Steam<T extends MetaMachine> {

T buildMachine(BlockEntityCreationInfo info, boolean isHighPressure);
}
}
38 changes: 25 additions & 13 deletions src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.gregtechceu.gtceu.api.machine.trait.MachineTrait;
import com.gregtechceu.gtceu.api.machine.trait.MachineTraitHolder;
import com.gregtechceu.gtceu.api.machine.trait.MachineTraitType;
import com.gregtechceu.gtceu.api.machine.trait.ProgrammableCircuitSlotTrait;
import com.gregtechceu.gtceu.api.machine.trait.feature.IFrontFacingTrait;
import com.gregtechceu.gtceu.api.machine.trait.feature.IInteractionTrait;
import com.gregtechceu.gtceu.api.machine.trait.feature.IRedstoneSignalTrait;
Expand All @@ -40,7 +41,6 @@
import com.gregtechceu.gtceu.common.cover.FluidFilterCover;
import com.gregtechceu.gtceu.common.cover.ItemFilterCover;
import com.gregtechceu.gtceu.common.cover.data.ManualIOMode;
import com.gregtechceu.gtceu.common.item.behavior.IntCircuitBehaviour;
import com.gregtechceu.gtceu.common.item.behavior.MachineConfigCopyBehaviour;
import com.gregtechceu.gtceu.common.machine.owner.MachineOwner;
import com.gregtechceu.gtceu.common.machine.owner.PlayerOwner;
Expand Down Expand Up @@ -155,7 +155,7 @@ public MetaMachine(BlockEntityCreationInfo info) {

@Override
public void load(CompoundTag tag) {
TagCompatibilityFixer.fixMachineAutoOutputTag(tag);
TagCompatibilityFixer.fixTraitTags(this, tag);
super.load(tag);
}

Expand Down Expand Up @@ -222,6 +222,19 @@ public void onMachineDestroyed() {
*/
public void modifyDrops(List<ItemStack> drops) {}

/**
* Saves machine data to an item stack tag.
*
* @param tag The tag to save to.
* @param clone If this data is being save to an item stack created by cloning the block (pick block)
*/
public void saveToItem(CompoundTag tag, boolean clone) {}

/**
* Loads machine data from an item stack tag.
*/
public void loadFromItem(CompoundTag tag) {}

//////////////////////////////////////
// ***** Tickable Manager ****//
//////////////////////////////////////
Expand Down Expand Up @@ -331,10 +344,10 @@ public <T extends MachineTrait> T attachTrait(T trait, int callbackPriority) {
* @param traitName Unique identifier for this trait.
* @param trait The trait to register
*/
public <T extends MachineTrait> T attachPersistentTrait(String traitName, T trait) {
public MetaMachine attachPersistentTrait(String traitName, MachineTrait trait) {
traitHolder.attachTrait(trait);
traitHolder.registerPersistentTrait(traitName, trait);
return trait;
return this;
}

/**
Expand Down Expand Up @@ -463,6 +476,7 @@ protected InteractionResult onHardHammerClick(ExtendedUseOnContext context) {
return InteractionResult.PASS;
}

@SuppressWarnings("unused")
protected InteractionResult onCrowbarClick(ExtendedUseOnContext context) {
return InteractionResult.PASS;
}
Expand Down Expand Up @@ -1313,12 +1327,10 @@ public void copyConfig(CompoundTag tag) {
tag.putBoolean(MUFFLED, mufflableMachine.isMuffled());
}

if (this instanceof IHasCircuitSlot circuitMachine) {
var circuit = IntCircuitBehaviour
.getCircuitConfiguration(circuitMachine.getCircuitInventory().getStackInSlot(0));
if (circuitMachine.isCircuitSlotEnabled() && circuit != 0) {
tag.putInt(CIRCUIT, circuit);
}
var circuit = getTrait(ProgrammableCircuitSlotTrait.TYPE);

if (circuit != null && circuit.isEnabled() && circuit.getCurrentCircuit() != 0) {
tag.putInt(CIRCUIT, circuit.getCurrentCircuit());
}

var coverTag = new CompoundTag();
Expand Down Expand Up @@ -1352,9 +1364,9 @@ public void pasteConfig(ServerPlayer player, CompoundTag tag) {
if (tag.contains(MUFFLED)) mufflableMachine.setMuffled(tag.getBoolean(MUFFLED));
}

if (this instanceof IHasCircuitSlot circuitMachine) {
if (tag.contains(CIRCUIT))
circuitMachine.getCircuitInventory().setStackInSlot(0, IntCircuitBehaviour.stack(tag.getInt(CIRCUIT)));
if (tag.contains(CIRCUIT)) {
getTraitOptional(ProgrammableCircuitSlotTrait.TYPE)
.ifPresent(t -> t.setCurrentCircuit(tag.getInt(CIRCUIT)));
}

getCoverContainer().pasteConfig(player, tag.getCompound(COVER));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import it.unimi.dsi.fastutil.ints.IntArrayList;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import org.apache.commons.lang3.function.TriFunction;
import org.jetbrains.annotations.Nullable;
Expand All @@ -30,7 +29,6 @@ public class MultiblockMachineDefinition extends MachineDefinition {
private boolean generator;
@Setter
@Getter
@NonNull
private Supplier<BlockPattern> patternFactory;
@Setter
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class SimpleGeneratorMachine extends WorkableTieredMachine {

public SimpleGeneratorMachine(BlockEntityCreationInfo info, int tier,
float hazardStrengthPerOperation, Int2IntFunction tankScalingFunction) {
super(info, tier, tankScalingFunction);
super(info, tier, true, tankScalingFunction);

energyContainer.setSideOutputCondition(side -> !hasFrontFacing() || side == getFrontFacing());
this.hazardEmitter = attachTrait(
Expand All @@ -38,12 +38,6 @@ public SimpleGeneratorMachine(BlockEntityCreationInfo info, int tier, Int2IntFun

//////////////////////////////////////
// ***** Initialization ******//
//////////////////////////////////////

@Override
protected boolean isEnergyEmitter() {
return true;
}

@Override
public int tintColor(int index) {
Expand Down
Loading
Loading