-
Notifications
You must be signed in to change notification settings - Fork 353
Add explodable machine trait #4567
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
81d48c3
explodable machine
gustovafing dd404e5
move explosion static method to utils
gustovafing ceadf06
spotless
gustovafing ac14a54
review changes
gustovafing c95db91
Merge branch '1.20.1-v8.0.0' into gus/explodable-machine-trait
gustovafing 0305be2
sotplsess
gustovafing efd1e5e
change if statements
gustovafing 289150e
Merge branch '1.20.1-v8.0.0' into gus/explodable-machine-trait
gustovafing 40ef98b
merge issue
gustovafing c3c8b0b
Update IDisplayUIMachine.java
gustovafing c79522d
spotless
gustovafing 1f0d47e
Merge branch '1.20.1-v8.0.0' into gus/explodable-machine-trait
gustovafing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 0 additions & 84 deletions
84
src/main/java/com/gregtechceu/gtceu/api/machine/feature/IExplosionMachine.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/main/java/com/gregtechceu/gtceu/api/machine/trait/EnvironmentalExplosionTrait.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| package com.gregtechceu.gtceu.api.machine.trait; | ||
|
|
||
| import com.gregtechceu.gtceu.api.GTValues; | ||
| import com.gregtechceu.gtceu.api.machine.MetaMachine; | ||
| import com.gregtechceu.gtceu.api.machine.TickableSubscription; | ||
| import com.gregtechceu.gtceu.config.ConfigHolder; | ||
| import com.gregtechceu.gtceu.utils.GTUtil; | ||
|
|
||
| import net.minecraft.core.Direction; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| import java.util.function.BooleanSupplier; | ||
|
|
||
| public class EnvironmentalExplosionTrait extends MachineTrait { | ||
|
|
||
| public static final MachineTraitType<EnvironmentalExplosionTrait> TYPE = new MachineTraitType<>( | ||
| EnvironmentalExplosionTrait.class); | ||
|
|
||
| private @Nullable TickableSubscription explosionSub = null; | ||
|
|
||
| private boolean enableEnvironmentalExplosions; | ||
| @Getter | ||
| @Setter | ||
| private float explosionPower, fireChance; | ||
| @Setter | ||
| private BooleanSupplier explosionPredicate; | ||
|
|
||
| public EnvironmentalExplosionTrait(MetaMachine machine, float explosionPower, float fireChance, | ||
| BooleanSupplier explosionPredicate) { | ||
| super(machine); | ||
| enableEnvironmentalExplosions = true; | ||
| this.explosionPredicate = explosionPredicate; | ||
| this.explosionPower = explosionPower; | ||
| this.fireChance = fireChance; | ||
| } | ||
|
|
||
| public EnvironmentalExplosionTrait(MetaMachine machine, float explosionPower, float fireChance) { | ||
| this(machine, explosionPower, fireChance, () -> true); | ||
| } | ||
|
|
||
| @Override | ||
| public MachineTraitType<EnvironmentalExplosionTrait> getTraitType() { | ||
| return TYPE; | ||
| } | ||
|
|
||
| public boolean enableEnvironmentalExplosions() { | ||
| return enableEnvironmentalExplosions; | ||
| } | ||
|
|
||
| public void setEnableEnvironmentalExplosions(boolean value) { | ||
| enableEnvironmentalExplosions = value; | ||
| updateSubscription(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onMachineLoad() { | ||
| super.onMachineLoad(); | ||
| if (!isRemote()) updateSubscription(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onMachineUnload() { | ||
| super.onMachineUnload(); | ||
| } | ||
|
|
||
| private void updateSubscription() { | ||
| if (!isRemote() && enableEnvironmentalExplosions && | ||
| ConfigHolder.INSTANCE.machines.shouldWeatherOrTerrainExplosion) { | ||
| explosionSub = subscribeServerTick(explosionSub, this::checkEnvironment); | ||
| } else { | ||
| if (explosionSub != null) explosionSub.unsubscribe(); | ||
| explosionSub = null; | ||
| } | ||
| } | ||
|
|
||
| private void checkEnvironment() { | ||
| if (!enableEnvironmentalExplosions || !explosionPredicate.getAsBoolean()) return; | ||
| var level = machine.getLevel(); | ||
| var pos = getBlockPos(); | ||
| if (GTValues.RNG.nextInt(1000) == 0) { | ||
| for (Direction side : GTUtil.DIRECTIONS) { | ||
| var fluidState = level.getBlockState(pos.relative(side)).getFluidState(); | ||
| if (!fluidState.isEmpty()) { | ||
| GTUtil.doExplosion(level, pos, explosionPower); | ||
| return; | ||
| } | ||
| } | ||
| } | ||
| if (level.isRainingAt(pos) || level.isRainingAt(pos.east()) || level.isRainingAt(pos.west()) || | ||
| level.isRainingAt(pos.north()) || level.isRainingAt(pos.south())) { | ||
| if (level.isThundering() && GTValues.RNG.nextInt(3) == 0) { | ||
| if (GTValues.RNG.nextInt(1000) == 0) GTUtil.doExplosion(level, pos, explosionPower); | ||
| } else if (GTValues.RNG.nextInt(10) == 0) { | ||
| if (GTValues.RNG.nextInt(1000) == 0) GTUtil.doExplosion(level, pos, explosionPower); | ||
| } else if (GTValues.RNG.nextInt(1000) == 0) GTUtil.setOnFire(level, pos, fireChance); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.