Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Magic Energy Absorber Machine #2389

Open
wants to merge 26 commits into
base: 1.20.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d8d652d
magic energy absorber machine
omergunr100 Nov 17, 2024
c4e988b
register magic energy absorber
omergunr100 Nov 17, 2024
a0116c8
run data
omergunr100 Nov 17, 2024
2d1c058
magic energy absorber is EV only
omergunr100 Nov 17, 2024
b5eba6c
add recipe and move generator to ev only
omergunr100 Nov 17, 2024
622441b
file organization and data gen
omergunr100 Nov 17, 2024
24e94be
Merge branch '1.20.1' into 1.20.1-magic-energy-absorber
omergunr100 Nov 17, 2024
529dd02
Merge remote-tracking branch 'origin/1.20.1-magic-energy-absorber' in…
omergunr100 Nov 17, 2024
3aba2e0
destroy generator when in proximity to ender dragon
omergunr100 Nov 17, 2024
09d3be1
take only one crystal from any spike
omergunr100 Nov 17, 2024
4fb7c2d
take only one crystal from any spike
omergunr100 Nov 17, 2024
340b9b8
Merge remote-tracking branch 'origin/1.20.1-magic-energy-absorber' in…
omergunr100 Nov 17, 2024
f5e4605
remove unnecessary voltage and tier in name (since there's only ev)
omergunr100 Nov 17, 2024
65fc9b0
made the output power and multiplier a parameter
omergunr100 Nov 17, 2024
be413f2
rendering and data gen
omergunr100 Nov 17, 2024
ce2b0ff
okay, figure out the format
omergunr100 Nov 19, 2024
e249bf1
switched renderer
omergunr100 Nov 19, 2024
7146ea1
added rerender member
omergunr100 Nov 19, 2024
e3ec915
reduced amps to max 1
omergunr100 Nov 19, 2024
5a9aa11
Merge branch '1.20.1' into 1.20.1-magic-energy-absorber
omergunr100 Nov 22, 2024
4463b10
Merge branch '1.20.1' into 1.20.1-magic-energy-absorber
omergunr100 Nov 27, 2024
24a581b
made disabling the machine possible
omergunr100 Nov 29, 2024
b95893c
tooltip lang
omergunr100 Dec 11, 2024
070e7ca
Merge remote-tracking branch 'official/1.20.1' into 1.20.1-magic-ener…
omergunr100 Dec 11, 2024
b0a19d0
compass is kil
omergunr100 Dec 11, 2024
4beca34
run data
omergunr100 Dec 11, 2024
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
9 changes: 9 additions & 0 deletions src/generated/resources/assets/gtceu/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"block.gtceu.ev_macerator": "ɹ§III ɹoʇɐɹǝɔɐW pǝɔuɐʌpⱯϛ§",
"block.gtceu.ev_machine_casing": "buısɐƆ ǝuıɥɔɐW ΛƎ",
"block.gtceu.ev_machine_hull": "ןןnH ǝuıɥɔɐWɟ§ ΛƎϛ§",
"block.gtceu.ev_magic_energy_absorber": "ɹǝqɹosqⱯ ʎbɹǝuƎ ɔıbɐW",
"block.gtceu.ev_mixer": "ɹ§III ɹǝxıW pǝɔuɐʌpⱯϛ§",
"block.gtceu.ev_muffler_hatch": "ΛƎϛ§ ɥɔʇɐH ɹǝןɟɟnW",
"block.gtceu.ev_ore_washer": "ɹ§III ɹǝɥsɐM ǝɹO pǝɔuɐʌpⱯϛ§",
Expand Down Expand Up @@ -2894,6 +2895,14 @@
"gtceu.machine.machine_hatch.locked": "pǝʞɔoꞀ ǝɔɐɟɹǝʇuI ǝuıɥɔɐW",
"gtceu.machine.machine_hatch.processing_array": "ʎɐɹɹⱯ buıssǝɔoɹԀǝ§ ǝɥʇ uı ʞɹoʍ ʇɐɥʇ sǝuıɥɔɐɯ spןoɥ ʎןuo 'ㄥ§ʎɐɹɹⱯ buıssǝɔoɹԀǝ§ ǝɥʇ uı uǝɥM",
"gtceu.machine.machine_hatch.tooltip": "sɯǝʇı pıןɐʌ spןoɥ ʎןuo ʇɐɥʇ snᗺ ssǝɔɔⱯ pǝzıןɐıɔǝdS",
"gtceu.machine.magic_energy_absorber.name": "ɹǝqɹosqⱯ ʎbɹǝuƎ ɔıbɐW",
"gtceu.machine.magic_energy_absorber.tooltip.0": "",
"gtceu.machine.magic_energy_absorber.tooltip.1": "˙sʞɔoןq ㄥ§ㄣ9ɹ§ uıɥʇıʍ puƎ ǝɥʇ uı sɹɐןןıd uɐıpısqo pǝʇɐɹǝuǝb ʎןןɐɹnʇɐu uoㄥ§ ɹ§sןɐʇsʎɹƆ puƎq§ ɯoɹɟ ʎbɹǝuǝ sʇɔǝןןoƆㄥ§",
"gtceu.machine.magic_energy_absorber.tooltip.2": "ʇndʇno oʇ ㄥ§ʇ/∩Ǝ ᄅƐɹ§ sppɐㄥ§ ɹ§ןɐʇsʎɹƆ puƎq§ ɥɔɐƎㄥ§",
"gtceu.machine.magic_energy_absorber.tooltip.3": "ʇndʇno ʎɟıןdɯɐ oʇ doʇ uoㄥ§ ɹ§bbƎ uobɐɹᗡp§ ǝɔɐןԀㄥ§",
"gtceu.machine.magic_energy_absorber.tooltip.4": "",
"gtceu.machine.magic_energy_absorber.tooltip.5": ":pǝıɟıןdɯɐ uǝɥMㄥ§",
"gtceu.machine.magic_energy_absorber.tooltip.6": "ʇ/∩Ǝ 8ᄅƖɹ§ sppɐㄥ§ ɹ§ןɐʇsʎɹƆ puƎq§ ɥɔɐƎㄥ§",
"gtceu.machine.maintenance_hatch.tooltip": "sʞɔoןqıʇןnW buıuıɐʇuıɐɯ ɹoℲ",
"gtceu.machine.maintenance_hatch_cleanroom_auto.tooltip.0": "¡buıuɐǝןƆ ɥʇıʍ sʞɔoןqıʇןnW buıuıɐʇuıɐɯ ʎןןɐɔıʇɐɯoʇnɐ ɹoℲ",
"gtceu.machine.maintenance_hatch_cleanroom_auto.tooltip.1": ":sɐ suɐǝןƆ",
Expand Down
9 changes: 9 additions & 0 deletions src/generated/resources/assets/gtceu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
"block.gtceu.ev_macerator": "§5Advanced Macerator III§r",
"block.gtceu.ev_machine_casing": "EV Machine Casing",
"block.gtceu.ev_machine_hull": "§5EV §fMachine Hull",
"block.gtceu.ev_magic_energy_absorber": "Magic Energy Absorber",
"block.gtceu.ev_mixer": "§5Advanced Mixer III§r",
"block.gtceu.ev_muffler_hatch": "Muffler Hatch §5EV",
"block.gtceu.ev_ore_washer": "§5Advanced Ore Washer III§r",
Expand Down Expand Up @@ -2894,6 +2895,14 @@
"gtceu.machine.machine_hatch.locked": "Machine Interface Locked",
"gtceu.machine.machine_hatch.processing_array": "When in the §eProcessing Array§7, only holds machines that work in the §eProcessing Array",
"gtceu.machine.machine_hatch.tooltip": "Specialized Access Bus that only holds valid items",
"gtceu.machine.magic_energy_absorber.name": "Magic Energy Absorber",
"gtceu.machine.magic_energy_absorber.tooltip.0": "",
"gtceu.machine.magic_energy_absorber.tooltip.1": "§7Collects energy from §bEnd Crystals§r §7on naturally generated obsidian pillars in the End within §r64§7 blocks.",
"gtceu.machine.magic_energy_absorber.tooltip.2": "§7Each §bEnd Crystal§r §7adds §r32 EU/t§7 to output",
"gtceu.machine.magic_energy_absorber.tooltip.3": "§7Place §dDragon Egg§r §7on top to amplify output",
"gtceu.machine.magic_energy_absorber.tooltip.4": "",
"gtceu.machine.magic_energy_absorber.tooltip.5": "§7When amplified:",
"gtceu.machine.magic_energy_absorber.tooltip.6": "§7Each §bEnd Crystal§r §7adds §r128 EU/t",
"gtceu.machine.maintenance_hatch.tooltip": "For maintaining Multiblocks",
"gtceu.machine.maintenance_hatch_cleanroom_auto.tooltip.0": "For automatically maintaining Multiblocks with Cleaning!",
"gtceu.machine.maintenance_hatch_cleanroom_auto.tooltip.1": "Cleans as:",
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/gregtechceu/gtceu/common/data/GTMachines.java
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,24 @@ public class GTMachines {
.register(),
LV, MV, HV, EV);

public static final MachineDefinition[] MAGIC_ENERGY_ABSORBER = registerTieredMachines("magic_energy_absorber",
MagicEnergyAbsorberMachine::new,
(tier, builder) -> builder
.rotationState(RotationState.NONE)
.langValue("Magic Energy Absorber")
.workableTieredHullRenderer(GTCEu.id("block/machines/magic_energy_absorber"))
.tooltips(Component.translatable("gtceu.universal.tooltip.voltage_out",
FormattingUtil.formatNumbers(GTValues.V[tier]), GTValues.VNF[tier]),
LangHandler.getFromMultiLang("gtceu.machine.magic_energy_absorber.tooltip", 0),
LangHandler.getFromMultiLang("gtceu.machine.magic_energy_absorber.tooltip", 1),
LangHandler.getFromMultiLang("gtceu.machine.magic_energy_absorber.tooltip", 2),
LangHandler.getFromMultiLang("gtceu.machine.magic_energy_absorber.tooltip", 3),
LangHandler.getFromMultiLang("gtceu.machine.magic_energy_absorber.tooltip", 4),
LangHandler.getFromMultiLang("gtceu.machine.magic_energy_absorber.tooltip", 5),
LangHandler.getFromMultiLang("gtceu.machine.magic_energy_absorber.tooltip", 6))
.register(),
EV);

//////////////////////////////////////
// ********* Storage *********//
//////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
package com.gregtechceu.gtceu.common.machine.electric;

import com.gregtechceu.gtceu.api.capability.IWorkable;
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.TickableSubscription;
import com.gregtechceu.gtceu.api.machine.TieredEnergyMachine;
import com.gregtechceu.gtceu.utils.GTUtil;

import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced;
import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted;
import com.lowdragmc.lowdraglib.syncdata.annotation.RequireRerender;
import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder;

import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.boss.enderdragon.EndCrystal;
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
import net.minecraft.world.entity.boss.enderdragon.phases.DragonChargePlayerPhase;
import net.minecraft.world.entity.boss.enderdragon.phases.EnderDragonPhase;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.DragonEggBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.SpikeFeature;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.ParametersAreNonnullByDefault;

@ParametersAreNonnullByDefault
public class MagicEnergyAbsorberMachine extends TieredEnergyMachine implements IWorkable {

protected static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(
MagicEnergyAbsorberMachine.class,
TieredEnergyMachine.MANAGED_FIELD_HOLDER);
private static final double DRAGON_DISTANCE_THRESHOLD = 5;

@Persisted
@Getter
@Setter
protected long baseEUPerFeature;
@Persisted
@Getter
@Setter
protected long amplifierMultiplier;
@Persisted
@Getter
@Setter
protected boolean hasAmplifier;
@Getter
protected IntList connectedFeatures;
@DescSynced
@RequireRerender
protected int numFeatures;
@Getter
@Setter
@Persisted
@DescSynced
@RequireRerender
protected boolean workingEnabled = true;

// subscriptions
protected TickableSubscription onServerTickSubscription;

public MagicEnergyAbsorberMachine(IMachineBlockEntity holder, int tier, Object... args) {
this(holder, tier, 32, 4, args);
}

protected MagicEnergyAbsorberMachine(IMachineBlockEntity holder, int tier, long baseEUPerFeature,
long amplifierMultiplier, Object... args) {
super(holder, tier, args);
this.baseEUPerFeature = baseEUPerFeature;
this.amplifierMultiplier = amplifierMultiplier;
this.connectedFeatures = new IntArrayList();
}

@Override
public @NotNull ManagedFieldHolder getFieldHolder() {
return MANAGED_FIELD_HOLDER;
}

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

@Override
protected long getMaxInputOutputAmperage() {
return 1;
}

@Override
public void onLoad() {
super.onLoad();
if (!isRemote()) {
updateServerTickSubscription();
onServerTick(true);
}
}

protected void updateServerTickSubscription() {
onServerTickSubscription = this.subscribeServerTick(onServerTickSubscription, () -> onServerTick(false));
}

@Override
public void onUnload() {
super.onUnload();
if (!isRemote()) {
resetConnectedFeatures();
if (onServerTickSubscription != null)
this.unsubscribe(onServerTickSubscription);
}
}

protected void onServerTick(boolean force) {
if (!workingEnabled || !(getLevel() instanceof ServerLevel serverLevel) ||
serverLevel.dimension() != Level.END) {
return;
}

if (force || getOffsetTimer() % 20 == 0) {
updateAmplifierStatus();
}

if (force || getOffsetTimer() % 200 == 0) {
updateConnectedFeatures();
}

if (force || !serverLevel.getDragons().isEmpty()) {
updateCrystalTargets();
}

if (connectedFeatures.isEmpty()) {
return;
}

long energyPer = this.baseEUPerFeature * (hasAmplifier ? this.amplifierMultiplier : 1);
long energyGenerated = 0;
// double check end crystals
for (int i = 0; i < connectedFeatures.size(); i++) {
if (getLevel().getEntity(connectedFeatures.getInt(i)) instanceof EndCrystal)
energyGenerated += energyPer;
}

if (energyGenerated > 0) {
energyContainer.changeEnergy(energyGenerated);
}
}

protected void updateAmplifierStatus() {
if (getLevel() == null) {
this.hasAmplifier = false;
return;
}

BlockState blockState = getLevel().getBlockState(getPos().above());
this.hasAmplifier = blockState.getBlock() instanceof DragonEggBlock;
}

protected void updateConnectedFeatures() {
this.connectedFeatures.clear();
if (getLevel() == null) {
return;
}

// get all natural end crystals
final double maxDistance = 4096; // (64^2)
List<EndCrystal> endCrystals = SpikeFeature.getSpikesForLevel((WorldGenLevel) getLevel()).stream()
.map(spike -> getLevel().getEntitiesOfClass(EndCrystal.class, spike.getTopBoundingBox(),
crystal -> crystal.distanceToSqr(getPos().getCenter()) < maxDistance))
.reduce(new ArrayList<>(), (lst, crystalList) -> {
if (!crystalList.isEmpty())
lst.add(crystalList.get(0));
return lst;
});

// set end crystals beam target to this generator
endCrystals.forEach(endCrystal -> {
BlockPos beamTarget = endCrystal.getBeamTarget();
if (getPos().equals(beamTarget)) {
this.connectedFeatures.add(endCrystal.getId());
} else if (beamTarget == null) {
endCrystal.setBeamTarget(getPos());
this.connectedFeatures.add(endCrystal.getId());
}
});
numFeatures = this.connectedFeatures.size();
}

protected void checkDragonProximity(EnderDragon dragon) {
if (getPos().getCenter().distanceTo(dragon.position()) < DRAGON_DISTANCE_THRESHOLD) {
this.doExplosion(GTUtil.getExplosionPower(tier));
}
}

protected void updateCrystalTargets() {
if (getLevel() == null) {
return;
}
// ender dragon check
List<? extends EnderDragon> dragonsInRange = ((ServerLevel) getLevel()).getDragons();

for (EnderDragon dragon : dragonsInRange) {
checkDragonProximity(dragon);
if (dragon.nearestCrystal != null && connectedFeatures.contains(dragon.nearestCrystal.getId())) {
dragon.nearestCrystal = null;

if (dragon.getPhaseManager().getCurrentPhase().getPhase() == EnderDragonPhase.HOLDING_PATTERN) {
dragon.hurt(dragon.damageSources().explosion(dragon, dragon), 10.0f);
dragon.getPhaseManager().setPhase(EnderDragonPhase.CHARGING_PLAYER);
((DragonChargePlayerPhase) dragon.getPhaseManager().getCurrentPhase())
.setTarget(getPos().below(2).getCenter());
}
}
}
}

protected void resetConnectedFeatures() {
if (getLevel() == null) {
connectedFeatures.clear();
return;
}

for (int id : connectedFeatures) {
Entity entity = getLevel().getEntity(id);

if (!(entity instanceof EndCrystal endCrystal)) {
continue;
}

if (getPos().equals(endCrystal.getBeamTarget())) {
endCrystal.setBeamTarget(null);
}
}

connectedFeatures.clear();
}

@Override
@SideOnly(Side.CLIENT)
public void animateTick(RandomSource random) {
if (getLevel() == null || !isActive() || this.hasAmplifier) {
return;
}
BlockPos pos = getPos();
for (int i = 0; i < 4; i++) {
getLevel().addParticle(ParticleTypes.PORTAL, pos.getX(), pos.getY(), pos.getZ(),
(random.nextFloat() - 0.5f) * 0.5f, (random.nextFloat() - 0.5f) * 0.5f,
(random.nextFloat() - 0.5f) * 0.5f);
}
}

@Override
public int getProgress() {
return 1;
}

@Override
public int getMaxProgress() {
return 1;
}

@Override
public boolean isActive() {
return isWorkingEnabled() && numFeatures > 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@ protected static void init(RegistrateLangProvider provider) {
provider.add("gtceu.forming_press.naming.to_name", "§oItem to Name");
provider.add("gtceu.forming_press.naming.named", "§oNamed Item");

// magic energy absorber
provider.add("gtceu.machine.magic_energy_absorber.name", "Magic Energy Absorber");
multilineLang(provider, "gtceu.machine.magic_energy_absorber.tooltip",
"\n§7Collects energy from §bEnd Crystals§r §7on naturally generated obsidian pillars in the End within §r64§7 blocks.\n§7Each §bEnd Crystal§r §7adds §r32 EU/t§7 to output\n§7Place §dDragon Egg§r §7on top to amplify output\n\n§7When amplified:\n§7Each §bEnd Crystal§r §7adds §r128 EU/t");

// Scanner
provider.add("gtceu.scanner.copy_stick_from", "§oStick to Copy");
provider.add("gtceu.scanner.copy_stick_empty", "§oEmpty Stick");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,8 @@ public static void init(Consumer<FinishedRecipe> provider) {
CIRCUIT, 'W', CABLE, 'S', Tags.Items.CHESTS_WOODEN, 'G', GRINDER);
registerMachineRecipe(provider, GTMachines.MINER, "MMM", "WHW", "CSC", 'M', MOTOR, 'W', CABLE, 'H', HULL, 'C',
CIRCUIT, 'S', SENSOR);
registerMachineRecipe(provider, GTMachines.MAGIC_ENERGY_ABSORBER, "PCP", "PMP", "PCP", 'M', HULL, 'P', SENSOR,
'C', CIRCUIT);

registerMachineRecipe(provider, GTMachines.MUFFLER_HATCH, "HM", "PR", 'H', HULL, 'M', MOTOR, 'P', PIPE_NORMAL,
'R', ROTOR);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading