Set cna coil stress to 0 instead of compansating
This commit is contained in:
@@ -6,9 +6,12 @@ import com.gregtechceu.gtceu.api.registry.registrate.GTRegistrate;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
import com.imbgt.kineticbridge.compat.create.CnaStressCompat;
|
||||
import com.imbgt.kineticbridge.compat.create.KineticBridgeCreateCompat;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import org.slf4j.Logger;
|
||||
@@ -25,10 +28,17 @@ public class KineticBridge {
|
||||
|
||||
REGISTRATE.registerRegistrate();
|
||||
KineticBridgeCreateCompat.init(modBus);
|
||||
modBus.addListener(this::onCommonSetup);
|
||||
|
||||
modBus.addGenericListener(MachineDefinition.class, this::registerMachines);
|
||||
}
|
||||
|
||||
private void onCommonSetup(FMLCommonSetupEvent event) {
|
||||
if (ModList.get().isLoaded("create_new_age")) {
|
||||
event.enqueueWork(CnaStressCompat::suppressCoilStressImpact);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerMachines(GTCEuAPI.RegisterEvent<ResourceLocation, MachineDefinition> event) {
|
||||
KineticBridgeMachines.init();
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
@@ -32,7 +31,6 @@ import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import com.imbgt.kineticbridge.machine.KineticOutputHatchPartMachine;
|
||||
import com.simibubi.create.content.kinetics.KineticNetwork;
|
||||
@@ -42,7 +40,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -66,7 +63,6 @@ public class KineticOutputHatchBlockEntity extends GeneratingKineticBlockEntity
|
||||
private float lastGeneratedSpeed = 0.0f;
|
||||
private boolean metaUnloaded = false;
|
||||
private long turbineOcV = 0L;
|
||||
private int lastCoils = 0;
|
||||
|
||||
public KineticOutputHatchBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState blockState) {
|
||||
super(type, pos, blockState);
|
||||
@@ -131,12 +127,9 @@ public class KineticOutputHatchBlockEntity extends GeneratingKineticBlockEntity
|
||||
}
|
||||
|
||||
private void finalizeKinetics() {
|
||||
int coils = countCoils();
|
||||
boolean coilsChanged = this.lastCoils != coils;
|
||||
boolean speedChanged = Math.abs(this.lastGeneratedSpeed - this.generatedSpeed) >= 1;
|
||||
|
||||
if (coilsChanged || speedChanged) {
|
||||
this.lastCoils = coils;
|
||||
if (speedChanged) {
|
||||
updateGeneratedRotation();
|
||||
this.lastGeneratedSpeed = this.generatedSpeed;
|
||||
}
|
||||
@@ -210,24 +203,7 @@ public class KineticOutputHatchBlockEntity extends GeneratingKineticBlockEntity
|
||||
|
||||
double suTurbine = this.turbineOcV * EU_TO_SU / TARGET_RPM;
|
||||
|
||||
return (float) Math.min(suTurbine, suMAx) + this.lastCoils * 24;
|
||||
}
|
||||
|
||||
private static final ResourceLocation CNA_COIL_ID = new ResourceLocation("create_new_age", "generator_coil");
|
||||
|
||||
private int countCoils() {
|
||||
if (hasNetwork()) {
|
||||
KineticNetwork net = getOrCreateNetwork();
|
||||
if (net != null) {
|
||||
return (int) net.members.keySet().stream()
|
||||
.map(kbe -> kbe.getBlockState().getBlock())
|
||||
.map(ForgeRegistries.BLOCKS::getKey)
|
||||
.filter(Objects::nonNull)
|
||||
.filter(id -> id.equals(CNA_COIL_ID))
|
||||
.count();
|
||||
}
|
||||
}
|
||||
return this.lastCoils;
|
||||
return (float) Math.min(suTurbine, suMAx);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -243,7 +219,6 @@ public class KineticOutputHatchBlockEntity extends GeneratingKineticBlockEntity
|
||||
super.read(tag, clientPacket);
|
||||
this.generatedSpeed = tag.getFloat("GeneratedSpeed");
|
||||
this.turbineOcV = tag.getLong("TurbineOcV");
|
||||
this.lastCoils = tag.getInt("LastCoils");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -251,7 +226,6 @@ public class KineticOutputHatchBlockEntity extends GeneratingKineticBlockEntity
|
||||
super.write(tag, clientPacket);
|
||||
tag.putFloat("GeneratedSpeed", this.generatedSpeed);
|
||||
tag.putLong("TurbineOcV", this.turbineOcV);
|
||||
tag.putInt("LastCoils", this.lastCoils);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.imbgt.kineticbridge.compat.create;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import com.imbgt.kineticbridge.KineticBridge;
|
||||
import com.imbgt.kineticbridge.mixin.SimpleRegistryImplAccessor;
|
||||
import com.simibubi.create.api.registry.SimpleRegistry;
|
||||
import com.simibubi.create.api.stress.BlockStressValues;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.DoubleSupplier;
|
||||
|
||||
/**
|
||||
* Handles Create: New Age-specific adjustments for Create stress values.
|
||||
*/
|
||||
public final class CnaStressCompat {
|
||||
|
||||
private static final ResourceLocation CNA_COIL_ID = new ResourceLocation("create_new_age", "generator_coil");
|
||||
|
||||
private CnaStressCompat() {}
|
||||
|
||||
public static void suppressCoilStressImpact() {
|
||||
Block coil = ForgeRegistries.BLOCKS.getValue(CNA_COIL_ID);
|
||||
if (coil == null) {
|
||||
KineticBridge.LOGGER.warn("CNA coil not found while trying to zero Create stress impact.");
|
||||
return;
|
||||
}
|
||||
|
||||
SimpleRegistry<Block, DoubleSupplier> impacts = BlockStressValues.IMPACTS;
|
||||
if (!(impacts instanceof SimpleRegistryImplAccessor<?, ?> accessor)) {
|
||||
KineticBridge.LOGGER.warn("Unable to access Create stress registry; CNA coil impact unchanged.");
|
||||
return;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<Block, DoubleSupplier> registrations = ((SimpleRegistryImplAccessor<Block, DoubleSupplier>) accessor)
|
||||
.kineticbridge$getRegistrations();
|
||||
|
||||
registrations.put(coil, () -> 0.0d);
|
||||
impacts.invalidate();
|
||||
|
||||
KineticBridge.LOGGER.debug("Zeroed Create stress impact for CNA generator coil.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.imbgt.kineticbridge.mixin;
|
||||
|
||||
import com.simibubi.create.impl.registry.SimpleRegistryImpl;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Accessor for Create's internal stress registry so we can adjust entries after
|
||||
* Create: New Age registers its values.
|
||||
*/
|
||||
@Mixin(SimpleRegistryImpl.class)
|
||||
public interface SimpleRegistryImplAccessor<K, V> {
|
||||
|
||||
@Accessor(value = "registrations", remap = false)
|
||||
Map<K, V> kineticbridge$getRegistrations();
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"minVersion": "0.8",
|
||||
"mixins": [
|
||||
"SimpleRegistryImplAccessor"
|
||||
],
|
||||
"client": [
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user