Skip to content

Commit

Permalink
Add damage source for bonking blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
WenXin20 committed Mar 4, 2025
1 parent 35a8ad8 commit d668568
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// 1.21.1 2025-02-16T10:56:30.8305299 Registries
// 1.21.1 2025-03-04T12:24:09.8356997 Registries
61b72938b4d73788d68c5721a35619b143f82eb2 data/marioverse/banner_pattern/bowser.json
d4a73076526d03c9ff5d2be3525ff57d5d09ecaf data/marioverse/banner_pattern/plumber.json
8ae0af93edd40ac1cb2f40b406efa8566285ffef data/marioverse/damage_type/bonked.json
e81856322face9c5f784a3b8d077999ee3fcda91 data/marioverse/damage_type/fireball.json
845ec4e9c0a8f252b320bcada24f96fbb9d191f1 data/marioverse/damage_type/piranha_chomp.json
9575ebd164ac8e681d80825169f7bc695c375a8e data/marioverse/damage_type/player_bonked.json
991ed5f29cb11234050b7d43d6b2d14014f5497f data/marioverse/damage_type/player_fireball.json
2218aec64f0c8e6894e47b4f2b827625dc72b8fe data/marioverse/damage_type/player_piranha_chomp.json
1b8ae3ae6512812a4ef8a01cb0d7af593c7ebbb0 data/marioverse/damage_type/player_shrapnel.json
0f75cc39ca159195ea31c3a3c65a380d0d75d9cc data/marioverse/damage_type/player_stomp.json
bc67876a234d2815baf1258a7196c9b745b22bb8 data/marioverse/damage_type/player_super_star.json
78d239612c3133487f3afd450aecb82febbf9a0b data/marioverse/damage_type/shrapnel.json
0c92f4aae51ef79ff99f8fbb28072cdeaac7b5c0 data/marioverse/damage_type/stomp.json
616e93eae16b46ee49f2a4da6717f85c8b5570ce data/marioverse/damage_type/super_star.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 1.21.1 2025-02-16T15:48:32.7985169 Tags for minecraft:damage_type mod id marioverse
// 1.21.1 2025-03-04T12:24:09.8294052 Tags for minecraft:damage_type mod id marioverse
d17fa6576e98e83edf16933949729bce0a820987 data/marioverse/tags/damage_type/is_bonked.json
a8e6821f58c53ed94b2eb3995415501e2111f35d data/marioverse/tags/damage_type/is_fireball.json
596bb1ac996a2b30ecbebc669c541cb02dfcc3c0 data/marioverse/tags/damage_type/is_piranha_chomp.json
ce9c860ae5eb372d2f0ff25cf6db665ebd70f01b data/marioverse/tags/damage_type/is_shrapnel.json
57cc73e219d6d846a77b7d763520b0b5d40b9df0 data/marioverse/tags/damage_type/is_super_star.json
7d9431e9715dd54613ee4c8e9110ef996404b53b data/marioverse/tags/damage_type/shield_blocks.json
a8e6821f58c53ed94b2eb3995415501e2111f35d data/minecraft/tags/damage_type/is_fire.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"exhaustion": 0.1,
"message_id": "marioverse.bonked",
"scaling": "when_caused_by_living_non_player"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"exhaustion": 0.1,
"message_id": "marioverse.bonked.player",
"scaling": "always"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"effects": "thorns",
"exhaustion": 0.1,
"message_id": "marioverse.shrapnel.player",
"scaling": "always"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"effects": "thorns",
"exhaustion": 0.1,
"message_id": "marioverse.shrapnel",
"scaling": "when_caused_by_living_non_player"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": [
"marioverse:bonked",
"marioverse:player_bonked"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": [
"marioverse:shrapnel",
"marioverse:player_shrapnel"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ protected void addTags(HolderLookup.Provider lookupProvider) {
.add(DamageTypeRegistry.FIREBALL)
.add(DamageTypeRegistry.PLAYER_FIREBALL);

tag(TagRegistry.IS_BONKED)
.add(DamageTypeRegistry.BONKED)
.add(DamageTypeRegistry.PLAYER_BONKED);

tag(TagRegistry.IS_FIREBALL)
.add(DamageTypeRegistry.FIREBALL)
.add(DamageTypeRegistry.PLAYER_FIREBALL);
Expand All @@ -29,6 +33,10 @@ protected void addTags(HolderLookup.Provider lookupProvider) {
.add(DamageTypeRegistry.PIRANHA_CHOMP)
.add(DamageTypeRegistry.PLAYER_PIRANHA_CHOMP);

tag(TagRegistry.IS_SHRAPNEL)
.add(DamageTypeRegistry.SHRAPNEL)
.add(DamageTypeRegistry.PLAYER_SHRAPNEL);

tag(TagRegistry.IS_SUPER_STAR)
.add(DamageTypeRegistry.SUPER_STAR)
.add(DamageTypeRegistry.PLAYER_SUPER_STAR);
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/com/wenxin2/marioverse/init/DamageTypeRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
import org.jetbrains.annotations.Nullable;

public class DamageTypeRegistry {
public static final ResourceKey<DamageType> BONKED =
ResourceKey.create(Registries.DAMAGE_TYPE, ResourceLocation.fromNamespaceAndPath(Marioverse.MOD_ID, "bonked"));
public static final ResourceKey<DamageType> PLAYER_BONKED =
ResourceKey.create(Registries.DAMAGE_TYPE, ResourceLocation.fromNamespaceAndPath(Marioverse.MOD_ID, "player_bonked"));

public static final ResourceKey<DamageType> FIREBALL =
ResourceKey.create(Registries.DAMAGE_TYPE, ResourceLocation.fromNamespaceAndPath(Marioverse.MOD_ID, "fireball"));
public static final ResourceKey<DamageType> PLAYER_FIREBALL =
Expand All @@ -23,6 +28,11 @@ public class DamageTypeRegistry {
public static final ResourceKey<DamageType> PLAYER_PIRANHA_CHOMP =
ResourceKey.create(Registries.DAMAGE_TYPE, ResourceLocation.fromNamespaceAndPath(Marioverse.MOD_ID, "player_piranha_chomp"));

public static final ResourceKey<DamageType> SHRAPNEL =
ResourceKey.create(Registries.DAMAGE_TYPE, ResourceLocation.fromNamespaceAndPath(Marioverse.MOD_ID, "shrapnel"));
public static final ResourceKey<DamageType> PLAYER_SHRAPNEL =
ResourceKey.create(Registries.DAMAGE_TYPE, ResourceLocation.fromNamespaceAndPath(Marioverse.MOD_ID, "player_shrapnel"));

public static final ResourceKey<DamageType> STOMP =
ResourceKey.create(Registries.DAMAGE_TYPE, ResourceLocation.fromNamespaceAndPath(Marioverse.MOD_ID, "stomp"));
public static final ResourceKey<DamageType> PLAYER_STOMP =
Expand All @@ -33,6 +43,15 @@ public class DamageTypeRegistry {
public static final ResourceKey<DamageType> PLAYER_SUPER_STAR =
ResourceKey.create(Registries.DAMAGE_TYPE, ResourceLocation.fromNamespaceAndPath(Marioverse.MOD_ID, "player_super_star"));


public static DamageSource bonked(@Nullable Entity damagedEntity, @Nullable Entity attackingEntity) {
if (damagedEntity != null && attackingEntity != null) {
return new DamageSource(attackingEntity.level().registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(PLAYER_BONKED), damagedEntity, attackingEntity);
} else if (attackingEntity != null) {
return new DamageSource(attackingEntity.level().registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(BONKED), null, attackingEntity);
} else return null;
}

public static DamageSource fireball(@Nullable Entity projectile, @Nullable Entity shooter) {
if (shooter != null && projectile != null) {
return new DamageSource(shooter.level().registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(PLAYER_FIREBALL), projectile, shooter);
Expand All @@ -41,6 +60,14 @@ public static DamageSource fireball(@Nullable Entity projectile, @Nullable Entit
} else return null;
}

public static DamageSource shrapnel(@Nullable Entity damagedEntity, @Nullable Entity attackingEntity) {
if (damagedEntity != null && attackingEntity != null) {
return new DamageSource(attackingEntity.level().registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(PLAYER_SHRAPNEL), damagedEntity, attackingEntity);
} else if (attackingEntity != null) {
return new DamageSource(attackingEntity.level().registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(SHRAPNEL), null, attackingEntity);
} else return null;
}

public static DamageSource stomp(@Nullable Entity entity, @Nullable Entity stomper) {
if (stomper != null && entity != null) {
return new DamageSource(stomper.level().registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(PLAYER_STOMP), entity, stomper);
Expand All @@ -66,6 +93,11 @@ public static DamageSource piranhaChomp(@Nullable Entity damagedEntity, @Nullabl
}

public static void bootstrap(BootstrapContext<DamageType> context) {
context.register(BONKED, new DamageType(Marioverse.MOD_ID + ".bonked",
DamageScaling.WHEN_CAUSED_BY_LIVING_NON_PLAYER, 0.1f, DamageEffects.HURT));
context.register(PLAYER_BONKED, new DamageType(Marioverse.MOD_ID + ".bonked.player",
DamageScaling.ALWAYS, 0.1f, DamageEffects.HURT));

context.register(FIREBALL, new DamageType(Marioverse.MOD_ID + ".fireball",
DamageScaling.WHEN_CAUSED_BY_LIVING_NON_PLAYER, 0.1f, DamageEffects.BURNING));
context.register(PLAYER_FIREBALL, new DamageType(Marioverse.MOD_ID + ".fireball.player",
Expand All @@ -76,6 +108,11 @@ public static void bootstrap(BootstrapContext<DamageType> context) {
context.register(PLAYER_PIRANHA_CHOMP, new DamageType(Marioverse.MOD_ID + ".piranha_chomp.player",
DamageScaling.ALWAYS, 0.5f, DamageEffects.THORNS));

context.register(SHRAPNEL, new DamageType(Marioverse.MOD_ID + ".shrapnel",
DamageScaling.WHEN_CAUSED_BY_LIVING_NON_PLAYER, 0.1f, DamageEffects.THORNS));
context.register(PLAYER_SHRAPNEL, new DamageType(Marioverse.MOD_ID + ".shrapnel.player",
DamageScaling.ALWAYS, 0.1f, DamageEffects.THORNS));

context.register(STOMP, new DamageType(Marioverse.MOD_ID + ".stomp",
DamageScaling.WHEN_CAUSED_BY_LIVING_NON_PLAYER, 0.5f, DamageEffects.HURT));
context.register(PLAYER_STOMP, new DamageType(Marioverse.MOD_ID + ".stomp.player",
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/wenxin2/marioverse/init/TagRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ public class TagRegistry {
public static final TagKey<Block> WARP_PIPE_BLOCKS = blockTags("warp_pipes");
public static final TagKey<Block> WRENCH_EFFICIENT = blockTags("wrench_efficient");

public static final TagKey<DamageType> IS_BONKED = damageTypeTags("is_bonked");
public static final TagKey<DamageType> IS_FIREBALL = damageTypeTags("is_fireball");
public static final TagKey<DamageType> IS_PIRANHA_CHOMP = damageTypeTags("is_piranha_chomp");
public static final TagKey<DamageType> IS_SHRAPNEL = damageTypeTags("is_shrapnel");
public static final TagKey<DamageType> IS_SUPER_STAR = damageTypeTags("is_super_star");
public static final TagKey<DamageType> SHIELD_BLOCKS = damageTypeTags("shield_blocks");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ private void handleEntityEvent(byte id, CallbackInfo info) {
ItemStack storedItem = questionBlockEntity.getTheItem();

if (!world.getBlockState(pos).getValue(QuestionBlock.EMPTY)) {
marioverse$hitEntityAbove(pos, world);
marioverse$hitEntityAbove(pos, world, entity);
}

if (!storedItem.isEmpty() && !world.getBlockState(pos).getValue(QuestionBlock.EMPTY)) {
Expand Down Expand Up @@ -563,7 +563,7 @@ private void handleEntityEvent(byte id, CallbackInfo info) {
@Unique
private void marioverse$smashBlock(Level world, BlockPos pos, BlockState state, LivingEntity entity) {

marioverse$hitEntityAbove(pos, world);
marioverse$hitEntityAbove(pos, world, entity);

if (entity.getPersistentData().getBoolean("marioverse:has_mushroom")) {
if (state.getBlock() instanceof SlabBlock) {
Expand All @@ -588,16 +588,17 @@ private void handleEntityEvent(byte id, CallbackInfo info) {
}

@Unique
private static void marioverse$hitEntityAbove(BlockPos pos, Level world) {
private static void marioverse$hitEntityAbove(BlockPos pos, Level world, LivingEntity attackingEntity) {
AABB boundingBox = new AABB(pos.above()).inflate(0.01);
List<Entity> entitiesAbove = world.getEntities(null, boundingBox);

if (!entitiesAbove.isEmpty()) {
for (Entity entityAbove : entitiesAbove) {
if (entityAbove instanceof LivingEntity livingEntity && livingEntity.onGround()) {
// TODO: Add custom damage source
entityAbove.setDeltaMovement(entityAbove.getDeltaMovement().add(0, 0.5, 0));
livingEntity.hurt(world.damageSources().generic(), 4.0F);
if (world.getBlockState(pos).getBlock() instanceof QuestionBlock)
livingEntity.hurt(DamageTypeRegistry.bonked(livingEntity, attackingEntity), 4.0F);
else livingEntity.hurt(DamageTypeRegistry.shrapnel(livingEntity, attackingEntity), 4.0F);
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/assets/marioverse/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -420,14 +420,18 @@
"accessories.slot.costume_pants": "Costume Pants",
"accessories.slot.costume_shoes": "Costume Shoes",

"death.attack.marioverse.bonked": "%1$s took a hit from below",
"death.attack.marioverse.bonked.player": "%1$s took a hit from below by %2$s",
"death.attack.marioverse.fireball": "%1$s was fireballed",
"death.attack.marioverse.fireball.item": "%1$s was fireballed by %2$s using %3$s",
"death.attack.marioverse.fireball.player": "%1$s was fireballed whilst fighting %2$s",
"death.attack.marioverse.fireball.player.item": "%1$s fireballed by %2$s using %3$s",
"death.attack.marioverse.piranha_chomp": "%1$s was chomped on",
"death.attack.marioverse.piranha_chomp.player": "%1$s was chomped on by %2$s",
"death.attack.marioverse.stomp": "%1$s stomped on",
"death.attack.marioverse.stomp.player": "%1$s stomped on by %2$s",
"death.attack.marioverse.shrapnel": "%1$s was shredded by shrapnel",
"death.attack.marioverse.shrapnel.player": "%2$s caused %1$s to be shredded by shrapnel",
"death.attack.marioverse.stomp": "%1$s was stomped on",
"death.attack.marioverse.stomp.player": "%1$s was stomped on by %2$s",
"death.attack.marioverse.super_star": "%1$s was star struck!",
"death.attack.marioverse.super_star.item": "%1$s was star struck by %2$s using %3$s!",
"death.attack.marioverse.super_star.player": "%1$s was star struck whilst fighting %2$s!",
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/data/marioverse/damage_type/bonked.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"exhaustion": 0.1,
"message_id": "marioverse.bonked",
"scaling": "when_caused_by_living_non_player"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"exhaustion": 0.1,
"message_id": "marioverse.bonked.player",
"scaling": "always"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"exhaustion": 0.1,
"message_id": "marioverse.shrapnel.player",
"scaling": "always"
}
5 changes: 5 additions & 0 deletions src/main/resources/data/marioverse/damage_type/shrapnel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"exhaustion": 0.1,
"message_id": "marioverse.shrapnel",
"scaling": "when_caused_by_living_non_player"
}

0 comments on commit d668568

Please sign in to comment.