Skip to content

Commit b3fb169

Browse files
committed
Update deps, bump min neo version to 21.0.31-beta, and adjust to support the damage pipeline update
1 parent 57832e8 commit b3fb169

File tree

9 files changed

+94
-138
lines changed

9 files changed

+94
-138
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ dependencies {
8686
Add the following to your `gradle.properties` file (see [Maven](https://modmaven.dev/mekanism/Mekanism/) for the list of available versions):
8787

8888
```properties
89-
mekanism_version=1.21-10.6.0.44
89+
mekanism_version=1.21-10.6.2.46
9090
```
9191

9292
# Credits #

build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ plugins {
1919
id('eclipse')
2020
id('idea')
2121
id('maven-publish')
22-
id('net.neoforged.gradle.userdev') version('7.0.145')//https://projects.neoforged.net/neoforged/neogradle
22+
id('net.neoforged.gradle.userdev') version('7.0.149')//https://projects.neoforged.net/neoforged/neogradle
2323
}
2424

2525
tasks.named('wrapper', Wrapper).configure {
@@ -389,7 +389,8 @@ dependencies {
389389

390390
def crt = "com.blamejared.crafttweaker:CraftTweaker-neoforge-${minecraft_version}:${crafttweaker_version}"
391391
compileOnly(crt)
392-
localRuntime(crt)
392+
//TODO: Re-enable when it updates to account for Neo's changes
393+
//localRuntime(crt)
393394
def jeiTweaker = "com.blamejared.jeitweaker:JeiTweaker-forge-1.20.1:${jeitweaker_version}"
394395
compileOnly(jeiTweaker)
395396
//TODO: Re-enable when it updates
@@ -404,7 +405,7 @@ dependencies {
404405
compileOnly("top.theillusivec4.curios:curios-neoforge:${curios_version}:api")
405406
compileOnly("com.blamejared.recipestages:RecipeStages:${recipe_stages_version}")
406407
compileOnly("curse.maven:opencomputers2-437654:${oc2_id}")
407-
compileOnly("cc.tweaked:cc-tweaked-${previous_minor_minecraft_version}-forge-api:${cc_tweaked_version}")
408+
compileOnly("cc.tweaked:cc-tweaked-${minecraft_version}-forge-api:${cc_tweaked_version}")
408409
//localRuntime("cc.tweaked:cc-tweaked-${minecraft_version}-forge:${cc_tweaked_version}")
409410
compileOnly("curse.maven:female-gender-forge-481655:${wildfire_gender_mod_id}")
410411

gradle.properties

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ minecraft_version=1.21
99
previous_minecraft_version=1.20.4
1010
previous_minor_minecraft_version=1.20.6
1111
loader_version_range=[4,)
12-
forge_version=21.0.29-beta
12+
forge_version=21.0.31-beta
1313
mod_version=10.6.2
1414
#This determines the minimum version of forge required to use Mekanism
1515
# Only bump it whenever we need access to a feature in forge that is not available in earlier versions
16-
forge_version_range=[21.0.28-beta,)
16+
forge_version_range=[21.0.31-beta,)
1717
minecraft_version_range=[1.21]
1818
#This specifies what type of release it will be uploaded to CurseForge and Modrinth as
1919
# options are: alpha, beta, release
@@ -24,25 +24,26 @@ junit_version=5.10.2
2424
jqwik_version=1.8.5
2525

2626
#NeoGradle Settings
27-
neogradle.subsystems.parchment.minecraftVersion=1.20.6
28-
neogradle.subsystems.parchment.mappingsVersion=2024.06.16
27+
neogradle.subsystems.parchment.minecraftVersion=1.21
28+
neogradle.subsystems.parchment.mappingsVersion=2024.06.23
2929
neogradle.subsystems.conventions.sourcesets.enabled=false
3030

3131
#misc settings
3232
# recipe viewer, currently accepts: jei, emi, hybrid
33-
recipe_viewer=none
33+
recipe_viewer=jei
3434

3535
#datagen
3636
yamlops_version=1.2.0
3737

3838
#Mod dependencies
39-
crafttweaker_version=20.0.6
39+
cc_tweaked_version=1.111.0
40+
crafttweaker_version=20.0.11
4041
ctm_version=1.2.0+1
4142
curios_version=9.0.2+1.21
4243
emi_version=1.1.7
4344
jade_api_id=5427895
4445
jade_id=5444008
45-
jei_version=19.0.0.9
46+
jei_version=19.0.0.10
4647
top_version=1.21_neo-12.0.0-1
4748
wthit_version=12.2.1
4849

@@ -59,7 +60,6 @@ glitchcore_version=2.0.0.1
5960
terrablender_version=4.0.0.1
6061

6162
#Outdated mod dependencies
62-
cc_tweaked_version=1.111.0
6363
flux_networks_id=5234697
6464
jeitweaker_version=8.0.5
6565
json_things_version=0.10.0

src/main/java/mekanism/common/CommonPlayerTickHandler.java

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import net.minecraft.core.BlockPos;
3636
import net.minecraft.server.level.ServerPlayer;
3737
import net.minecraft.util.Mth;
38+
import net.minecraft.world.damagesource.DamageSource;
3839
import net.minecraft.world.effect.MobEffectInstance;
3940
import net.minecraft.world.entity.EquipmentSlot;
4041
import net.minecraft.world.entity.LivingEntity;
@@ -46,10 +47,10 @@
4647
import net.minecraft.world.phys.Vec3;
4748
import net.neoforged.bus.api.SubscribeEvent;
4849
import net.neoforged.neoforge.common.NeoForgeMod;
49-
import net.neoforged.neoforge.event.entity.living.LivingAttackEvent;
50+
import net.neoforged.neoforge.common.damagesource.DamageContainer;
5051
import net.neoforged.neoforge.event.entity.living.LivingEvent.LivingJumpEvent;
5152
import net.neoforged.neoforge.event.entity.living.LivingFallEvent;
52-
import net.neoforged.neoforge.event.entity.living.LivingHurtEvent;
53+
import net.neoforged.neoforge.event.entity.living.LivingIncomingDamageEvent;
5354
import net.neoforged.neoforge.event.entity.player.PlayerEvent.BreakSpeed;
5455
import net.neoforged.neoforge.event.tick.PlayerTickEvent;
5556
import org.jetbrains.annotations.Nullable;
@@ -159,9 +160,12 @@ public static boolean isGravitationalModulationOn(Player player) {
159160
}
160161

161162
@SubscribeEvent
162-
public void onEntityAttacked(LivingAttackEvent event) {
163+
@SuppressWarnings("UnstableApiUsage")//Note: DamageContainer isn't actually unstable, they just forgot to unmark it before finalizing the PR
164+
public void onEntityAttacked(LivingIncomingDamageEvent event) {
163165
LivingEntity entity = event.getEntity();
164-
if (event.getAmount() <= 0 || !entity.isAlive()) {
166+
DamageContainer damageContainer = event.getContainer();
167+
float damage = damageContainer.getNewDamage();
168+
if (damage <= 0 || !entity.isAlive()) {
165169
//If some mod does weird things and causes the damage value to be negative or zero then exit
166170
// as our logic assumes there is actually damage happening and can crash if someone tries to
167171
// use a negative number as the damage value. We also check to make sure that we don't do
@@ -171,8 +175,9 @@ public void onEntityAttacked(LivingAttackEvent event) {
171175
// entity can't take damage while dead
172176
return;
173177
}
178+
DamageSource source = damageContainer.getSource();
174179
//Gas Mask checks
175-
if (event.getSource().is(MekanismAPITags.DamageTypes.IS_PREVENTABLE_MAGIC)) {
180+
if (source.is(MekanismAPITags.DamageTypes.IS_PREVENTABLE_MAGIC)) {
176181
ItemStack headStack = entity.getItemBySlot(EquipmentSlot.HEAD);
177182
if (!headStack.isEmpty() && headStack.getItem() instanceof ItemScubaMask) {
178183
ItemStack chestStack = entity.getItemBySlot(EquipmentSlot.CHEST);
@@ -183,35 +188,16 @@ public void onEntityAttacked(LivingAttackEvent event) {
183188
}
184189
}
185190
if (entity instanceof Player player) {
186-
if (ItemMekaSuitArmor.tryAbsorbAll(player, event.getSource(), event.getAmount())) {
187-
event.setCanceled(true);
188-
}
189-
}
190-
}
191-
192-
@SubscribeEvent
193-
public void onLivingHurt(LivingHurtEvent event) {
194-
LivingEntity entity = event.getEntity();
195-
if (event.getAmount() <= 0 || !entity.isAlive()) {
196-
//If some mod does weird things and causes the damage value to be negative or zero then exit
197-
// as our logic assumes there is actually damage happening and can crash if someone tries to
198-
// use a negative number as the damage value. We also check to make sure that we don't do
199-
// anything if the entity is dead as living attack is still fired when the entity is dead
200-
// for things like fall damage if the entity dies before hitting the ground, and then energy
201-
// would be depleted regardless if keep inventory is on even if no damage was stopped as the
202-
// entity can't take damage while dead. While living hurt is not fired, we catch this case
203-
// just in case anyway because it is a simple boolean check and there is no guarantee that
204-
// other mods may not be firing the event manually even when the entity is dead
205-
return;
206-
}
207-
if (entity instanceof Player player) {
208-
float ratioAbsorbed = ItemMekaSuitArmor.getDamageAbsorbed(player, event.getSource(), event.getAmount());
191+
//TODO - 1.21: Should we rewrite this to try and take advantage of the new reduction system? It would be kind of nice to move this to the
192+
// spot that reduction from armor happens. Though then the base armor reduction will apply before our energy based reduction
193+
// Is that fine? Maybe it is better, or maybe it is worse from a balance standpoint
194+
float ratioAbsorbed = ItemMekaSuitArmor.getDamageAbsorbed(player, damageContainer.getSource(), damage);
209195
if (ratioAbsorbed > 0) {
210-
float damageRemaining = event.getAmount() * Math.max(0, 1 - ratioAbsorbed);
196+
float damageRemaining = damage * Math.max(0, 1 - ratioAbsorbed);
211197
if (damageRemaining <= 0) {
212198
event.setCanceled(true);
213199
} else {
214-
event.setAmount(damageRemaining);
200+
damageContainer.setNewDamage(damageRemaining);
215201
}
216202
}
217203
}

src/main/java/mekanism/common/entity/EntityRobit.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@
125125
import net.minecraft.world.phys.Vec3;
126126
import net.neoforged.neoforge.client.model.data.ModelData;
127127
import net.neoforged.neoforge.client.model.data.ModelProperty;
128-
import net.neoforged.neoforge.common.CommonHooks;
129128
import net.neoforged.neoforge.common.NeoForge;
129+
import net.neoforged.neoforge.common.damagesource.DamageContainer;
130130
import org.jetbrains.annotations.NotNull;
131131
import org.jetbrains.annotations.Nullable;
132132

@@ -528,15 +528,11 @@ public boolean isInvulnerableTo(@NotNull DamageSource source) {
528528
}
529529

530530
@Override
531-
protected void actuallyHurt(@NotNull DamageSource damageSource, float amount) {
532-
amount = CommonHooks.onLivingHurt(this, damageSource, amount);
533-
if (amount <= 0) {
534-
return;
535-
}
536-
amount = getDamageAfterArmorAbsorb(damageSource, amount);
537-
amount = getDamageAfterMagicAbsorb(damageSource, amount);
538-
energyContainer.extract(FloatingLong.create(1_000 * amount), Action.EXECUTE, AutomationType.INTERNAL);
539-
getCombatTracker().recordDamage(damageSource, amount);
531+
@SuppressWarnings("UnstableApiUsage")//Note: DamageContainer isn't actually unstable, they just forgot to unmark it before finalizing the PR
532+
public void onDamageTaken(@NotNull DamageContainer damageContainer) {
533+
energyContainer.extract(FloatingLong.create(1_000 * damageContainer.getNewDamage()), Action.EXECUTE, AutomationType.INTERNAL);
534+
//Don't actually allow taking damage to reduce the robit's health
535+
setHealth(getMaxHealth());
540536
}
541537

542538
@Override

src/main/java/mekanism/common/item/gear/ItemMekaSuitArmor.java

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -433,22 +433,6 @@ public boolean shouldCauseBlockBreakReset(ItemStack oldStack, ItemStack newStack
433433
}
434434

435435
public static float getDamageAbsorbed(Player player, DamageSource source, float amount) {
436-
return getDamageAbsorbed(player, source, amount, null);
437-
}
438-
439-
public static boolean tryAbsorbAll(Player player, DamageSource source, float amount) {
440-
List<Runnable> energyUsageCallbacks = new ArrayList<>(4);
441-
if (getDamageAbsorbed(player, source, amount, energyUsageCallbacks) >= 1) {
442-
//If we can fully absorb it, actually use the energy from the various pieces and then return that we absorbed it all
443-
for (Runnable energyUsageCallback : energyUsageCallbacks) {
444-
energyUsageCallback.run();
445-
}
446-
return true;
447-
}
448-
return false;
449-
}
450-
451-
private static float getDamageAbsorbed(Player player, DamageSource source, float amount, @Nullable List<Runnable> energyUseCallbacks) {
452436
if (amount <= 0) {
453437
return 0;
454438
}
@@ -525,13 +509,7 @@ private static float getDamageAbsorbed(Player player, DamageSource source, float
525509
}
526510
for (FoundArmorDetails details : armorDetails) {
527511
//Use energy/or enqueue usage for each piece as needed
528-
if (!details.usageInfo.energyUsed.isZero()) {
529-
if (energyUseCallbacks == null) {
530-
details.energyContainer.extract(details.usageInfo.energyUsed, Action.EXECUTE, AutomationType.MANUAL);
531-
} else {
532-
energyUseCallbacks.add(details);
533-
}
534-
}
512+
details.drainEnergy();
535513
}
536514
return Math.min(ratioAbsorbed, 1);
537515
}
@@ -569,7 +547,7 @@ private static float absorbDamage(EnergyUsageInfo usageInfo, float amount, float
569547
return 0;
570548
}
571549

572-
private static class FoundArmorDetails implements Runnable {
550+
private static class FoundArmorDetails {
573551

574552
private final IEnergyContainer energyContainer;
575553
private final EnergyUsageInfo usageInfo;
@@ -581,8 +559,7 @@ public FoundArmorDetails(IEnergyContainer energyContainer, ItemMekaSuitArmor arm
581559
this.armor = armor;
582560
}
583561

584-
@Override
585-
public void run() {
562+
public void drainEnergy() {
586563
energyContainer.extract(usageInfo.energyUsed, Action.EXECUTE, AutomationType.MANUAL);
587564
}
588565
}

src/main/java/mekanism/common/registries/MekanismDamageTypes.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
import java.util.Map;
99
import mekanism.api.text.IHasTranslationKey;
1010
import mekanism.common.Mekanism;
11+
import net.minecraft.core.Holder;
1112
import net.minecraft.core.RegistryAccess;
1213
import net.minecraft.core.registries.Registries;
1314
import net.minecraft.resources.ResourceKey;
1415
import net.minecraft.resources.ResourceLocation;
1516
import net.minecraft.world.damagesource.DamageSource;
1617
import net.minecraft.world.damagesource.DamageType;
1718
import net.minecraft.world.level.Level;
19+
import net.minecraft.world.phys.Vec3;
1820
import org.jetbrains.annotations.NotNull;
1921

2022
public class MekanismDamageTypes {
@@ -66,7 +68,19 @@ public DamageSource source(Level level) {
6668
}
6769

6870
public DamageSource source(RegistryAccess registryAccess) {
69-
return new DamageSource(registryAccess.registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(key()));
71+
return new DamageSource(holder(registryAccess));
72+
}
73+
74+
public DamageSource source(Level level, Vec3 position) {
75+
return source(level.registryAccess(), position);
76+
}
77+
78+
public DamageSource source(RegistryAccess registryAccess, Vec3 position) {
79+
return new DamageSource(holder(registryAccess), position);
80+
}
81+
82+
private Holder<DamageType> holder(RegistryAccess registryAccess) {
83+
return registryAccess.registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(key());
7084
}
7185
}
7286
}

0 commit comments

Comments
 (0)