Skip to content
Closed
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.mo_guang.ctpp.common.blockentity.IKineticBlockEntityExtension;
import com.mo_guang.ctpp.common.blockentity.KineticMachineBlockEntity;
import com.mo_guang.ctpp.common.machine.IKineticMachine;
import com.mo_guang.ctpp.common.machine.multiblock.IMultiblockKineticOwner;
import com.mo_guang.ctpp.common.machine.multiblock.part.KineticPartMachine;
import com.simibubi.create.content.kinetics.base.KineticBlockEntity;
import it.unimi.dsi.fastutil.longs.LongSet;
Expand All @@ -44,7 +45,8 @@
import java.util.Objects;

public class KineticElectricMultiblockMachine extends RecipeMultiblockMachine implements IFancyUIMachine,
IDisplayUIMachine, ITieredMachine, IOverclockMachine {
IDisplayUIMachine, ITieredMachine, IOverclockMachine,
IMultiblockKineticOwner {

public KineticElectricMultiblockMachine(IMachineBlockEntity holder) {
super(holder, new Object[0]);
Expand All @@ -67,17 +69,13 @@ public KineticElectricMultiblockMachine(IMachineBlockEntity holder) {
@Override
public void onStructureInvalid() {
super.onStructureInvalid();
if (this.rotateBlocks != null && getLevel() != null) {
for (Long pos : this.rotateBlocks) {
BlockEntity blockEntity = getLevel().getBlockEntity(BlockPos.of(pos));
if (blockEntity instanceof KineticBlockEntity kineticBlockEntity &&
kineticBlockEntity instanceof IKineticBlockEntityExtension extension) {
extension.setCTNHVisualSpeed(0);
extension.setCTNHInMultiblock(false);
}
}
}
releaseRotateBlocks(this.rotateBlocks, null);
this.rotateBlocks = null;
this.energyContainer = null;
this.maxTorque = 0.0F;
this.speed = 0.0F;
this.Ktier = 0;
this.inputPartsMax.clear();
this.tier = 0;
}

Expand All @@ -86,15 +84,10 @@ public void onStructureFormed() {
super.onStructureFormed();
this.energyContainer = getEnergyContainer();
getKineticContainer();
this.rotateBlocks = (LongSet) this.getMultiblockState().getMatchContext().getOrDefault("roBlocks",
LongSet newRotateBlocks = (LongSet) this.getMultiblockState().getMatchContext().getOrDefault("roBlocks",
LongSets.emptySet());
for (Long pos : this.rotateBlocks) {
BlockEntity blockEntity = getLevel().getBlockEntity(BlockPos.of(pos));
if (blockEntity instanceof KineticBlockEntity kineticBlockEntity &&
kineticBlockEntity instanceof IKineticBlockEntityExtension extension) {
extension.setCTNHInMultiblock(true);
}
}
releaseRotateBlocks(this.rotateBlocks, newRotateBlocks);
this.rotateBlocks = newRotateBlocks;
this.updateActiveBlocks(this.recipeLogic.isWorking());

this.tier = getTier();
Expand All @@ -114,12 +107,22 @@ public void onPartUnload() {
this.tier = 0;
}

@Override
protected void onStructureRevalidationChanged(boolean pending) {
super.onStructureRevalidationChanged(pending);
if (pending) {
// Retain exact ownership across chunk unloads, while withdrawing this controller's visual request.
updateRotateBlocks(false);
}
}

//////////////////////////////////////
// ********** ACTIVE ***********//
//////////////////////////////////////
public void updateActiveBlocks(boolean active) {
super.updateActiveBlocks(active);
this.updateRotateBlocks(active);
boolean operationalActive = active && isStructureOperational();
super.updateActiveBlocks(operationalActive);
this.updateRotateBlocks(operationalActive);
}

public void updateRotateBlocks(boolean active) {
Expand All @@ -129,6 +132,7 @@ public void updateRotateBlocks(boolean active) {
while (a.hasNext()) {
Long pos = a.next();
BlockPos blockPos = BlockPos.of(pos);
if (!Objects.requireNonNull(this.getLevel()).isLoaded(blockPos)) continue;
BlockEntity blockEntity = ((Level) Objects.requireNonNull(this.getLevel())).getBlockEntity(blockPos);
this.updateRotateBlock(active, blockEntity);
}
Expand All @@ -139,10 +143,21 @@ public void updateRotateBlock(boolean active, BlockEntity blockEntity) {
if (blockEntity instanceof KineticBlockEntity kineticBlockEntity &&
kineticBlockEntity instanceof IKineticBlockEntityExtension extension &&
!(kineticBlockEntity instanceof KineticMachineBlockEntity)) {
extension.setCTNHVisualSpeed(active ? this.speed - 1 : 0);
extension.ctpp$claimMultiblockOwner(getPos(), getStructureInstanceId(),
active ? this.speed - 1 : 0.0F);
}
}

@Override
public boolean ownsKineticVisual(BlockPos pos) {
return rotateBlocks != null && rotateBlocks.contains(pos.asLong());
}

@Override
public float getKineticVisualSpeed(BlockPos pos) {
return ownsKineticVisual(pos) && isStructureOperational() && recipeLogic.isWorking() ? speed - 1 : 0.0F;
}

//////////////////////////////////////
// ********** GUI ***********//
//////////////////////////////////////
Expand Down Expand Up @@ -206,6 +221,10 @@ public void attachTooltips(TooltipsPanel tooltipsPanel) {
// ****** RECIPE LOGIC *******//
//////////////////////////////////////
public void getKineticContainer() {
this.maxTorque = 0.0F;
this.speed = 0.0F;
this.Ktier = 0;
this.inputPartsMax.clear();
// 只限输入不能输出
for (IMultiPart part : this.getParts()) {
if (part instanceof KineticPartMachine kineticPart) {
Expand All @@ -225,6 +244,20 @@ public void getKineticContainer() {
}
}

private void releaseRotateBlocks(LongSet oldRotateBlocks, LongSet retainedRotateBlocks) {
if (oldRotateBlocks == null || getLevel() == null) return;
for (long pos : oldRotateBlocks) {
if (retainedRotateBlocks != null && retainedRotateBlocks.contains(pos)) continue;
BlockPos blockPos = BlockPos.of(pos);
if (!getLevel().isLoaded(blockPos)) continue;
BlockEntity blockEntity = getLevel().getBlockEntity(blockPos);
if (blockEntity instanceof KineticBlockEntity kineticBlockEntity &&
kineticBlockEntity instanceof IKineticBlockEntityExtension extension) {
extension.ctpp$releaseMultiblockOwner(getPos(), getStructureInstanceId());
}
}
}

public EnergyContainerList getEnergyContainer() {
List<IEnergyContainer> containers = new ArrayList<>();
var handlers = getCapabilitiesFlat(IO.IN, EURecipeCapability.CAP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.lowdragmc.lowdraglib.gui.widget.Widget;
import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup;
import com.lowdragmc.lowdraglib.syncdata.ISubscription;
import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted;

import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -91,6 +92,7 @@ public class SlaughterHouseMachine extends RecipeElectricMultiblockMachine imple
private int lootCacheTotalExperience = 0;
private int lootCacheDuration = 0;
private int lootCacheRepeatTimes = 1;
private final List<ISubscription> structureSubscriptions = new ArrayList<>();

private final LinkedHashMap<String, LivingEntity> entityCache = new LinkedHashMap<>(ENTITY_CACHE_LIMIT, 0.75f,
true) {
Expand Down Expand Up @@ -128,6 +130,7 @@ public SlaughterHouseMachine(IMachineBlockEntity holder) {
@Override
public void onStructureFormed() {
super.onStructureFormed();
clearStructureSubscriptions();
if (getLevel() instanceof ServerLevel serverLevel) {
getFakePlayer(serverLevel);
}
Expand All @@ -139,6 +142,7 @@ public void onStructureFormed() {
@Override
public void onStructureInvalid() {
super.onStructureInvalid();
clearStructureSubscriptions();
mobList.clear();
markMobListDirty();
clearLootCache();
Expand All @@ -148,13 +152,21 @@ public void onStructureInvalid() {

@Override
public void onUnload() {
clearStructureSubscriptions();
super.onUnload();
entityCache.clear();
lootTableCache.clear();
clearLootCache();
mobList.clear();
}

@Override
public void onPartUnload() {
clearStructureSubscriptions();
super.onPartUnload();
markMobListDirty();
}

protected NotifiableItemStackHandler createMachineStorage(byte value) {
return new NotifiableItemStackHandler(
this, 1, IO.NONE, IO.BOTH, slots -> new CustomItemStackHandler(1) {
Expand Down Expand Up @@ -288,11 +300,16 @@ private void attachInputChangeSubscriptions() {
if (handlerList.getAllHandlers().stream()
.noneMatch(handler -> handler.getHandlerIO().support(IO.IN)))
continue;
traitSubscriptions.add(handlerList.subscribe(this::markMobListDirty, ItemRecipeCapability.CAP));
structureSubscriptions.add(handlerList.subscribe(this::markMobListDirty, ItemRecipeCapability.CAP));
}
}
}

private void clearStructureSubscriptions() {
structureSubscriptions.forEach(ISubscription::unsubscribe);
structureSubscriptions.clear();
}

private LivingEntity getOrCreateCachedEntity(ServerLevel level, String mobId) {
var cached = entityCache.get(mobId);
if (cached != null && cached.level() == level) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public BioMachine(IMachineBlockEntity holder) {
@Override
public void addDisplayText(List<Component> textList) {
super.addDisplayText(textList);
if (isFormed) {
if (isStructureOperational()) {
if (machineTemperature >= 36 && machineTemperature <= 38) {
efficiency = 1.2;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.gregtechceu.gtceu.api.recipe.handler.RecipeHandlerGroup;
import com.gregtechceu.gtceu.api.recipe.modifier.ParallelLogic;
import com.gregtechceu.gtceu.api.transfer.fluid.IFluidHandlerModifiable;
import com.gregtechceu.gtceu.common.machine.trait.multiblock.CoilMachineTrait;

import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -80,7 +81,8 @@ public void addDisplayText(@NotNull List<Component> textList) {

if (isFormed()) {
textList.add(Component.translatable("gtceu.multiblock.blast_furnace.max_temperature",
Component.literal(getCoilType().getCoilTemperature() + "K").withStyle(ChatFormatting.RED)));
Component.literal(getTrait(CoilMachineTrait.class).getCoilType().getCoilTemperature() + "K")
.withStyle(ChatFormatting.RED)));
textList.add(blazeBlastFurnaceInfoPyrotheum.translate(current));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.gregtechceu.gtceu.api.recipe.GTRecipe;
import com.gregtechceu.gtceu.api.recipe.handler.RecipeHandlerGroup;
import com.gregtechceu.gtceu.common.machine.multiblock.part.FluidHatchPartMachine;
import com.gregtechceu.gtceu.common.machine.trait.multiblock.CoilMachineTrait;
import com.gregtechceu.gtceu.utils.FormattingUtil;

import com.lowdragmc.lowdraglib.side.fluid.FluidStack;
Expand Down Expand Up @@ -58,7 +59,9 @@ public void addDisplayText(List<Component> textList) {
super.addDisplayText(textList);
textList.add(Component.translatable("gtceu.multiblock.blast_furnace.max_temperature", Component
.translatable(FormattingUtil.formatNumbers(
getCoilType().getCoilTemperature() + 100L * Math.max(0, getTier() - GTValues.MV)) + "K")
getTrait(CoilMachineTrait.class).getCoilType().getCoilTemperature() +
100L * Math.max(0, getTier() - GTValues.MV)) +
"K")
.setStyle(Style.EMPTY.withColor(ChatFormatting.RED))));
textList.add(textList.size(),
growing_temperature.translate(String.format("%.1f", Machine_Temperature))
Expand Down
Loading
Loading