Skip to content

Commit

Permalink
Add supplementaries bomb support
Browse files Browse the repository at this point in the history
  • Loading branch information
WenXin20 committed Jan 3, 2025
1 parent 8ca6b53 commit 1fc1c4e
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 3 deletions.
58 changes: 56 additions & 2 deletions src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,58 @@ public void spawnFromQuestionBlock(Level world, BlockPos pos, ItemStack stack, E
entity.setDeltaMovement(new Vec3(
world.random.triangle(0.0, 0.3),
world.random.triangle(0.5, 0.3),
world.random.triangle(0.0, 0.3)
));
world.random.triangle(0.0, 0.3)));
} else {
entity.setPos(pos.getX() + 0.5D, pos.getY() - entity.getBbHeight(), pos.getZ() + 0.5D);
entity.setDeltaMovement(new Vec3(0, -0.5, 0));
}
world.addFreshEntity(entity);
stack.copyWithCount(1);
} else spawnItem(world, pos, stack, dropItemsAtPos);
} else if (stack.getItem() == CompatRegistry.BOMB_ITEM.get()) {
Entity entity = CompatRegistry.BOMB.get().create(serverWorld);

if (entity != null && !entity.getType().is(TagRegistry.QUESTION_BLOCK_CANNOT_SPAWN)) {
if (world.getBlockState(pos.above()).isAir() || world.getFluidState(pos.above()).is(FluidTags.WATER)) {
entity.setPos(pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D);
entity.setDeltaMovement(new Vec3(
world.random.triangle(0.0, 0.2),
world.random.triangle(0.5, 0.2),
world.random.triangle(0.0, 0.2)));
} else {
entity.setPos(pos.getX() + 0.5D, pos.getY() - entity.getBbHeight(), pos.getZ() + 0.5D);
entity.setDeltaMovement(new Vec3(0, -0.5, 0));
}
world.addFreshEntity(entity);
stack.copyWithCount(1);
} else spawnItem(world, pos, stack, dropItemsAtPos);
} else if (stack.getItem() == CompatRegistry.BOMB_BLUE_ITEM.get()) {
Entity entity = CompatRegistry.BOMB_BLUE.get().create(serverWorld);

if (entity != null && !entity.getType().is(TagRegistry.QUESTION_BLOCK_CANNOT_SPAWN)) {
if (world.getBlockState(pos.above()).isAir() || world.getFluidState(pos.above()).is(FluidTags.WATER)) {
entity.setPos(pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D);
entity.setDeltaMovement(new Vec3(
world.random.triangle(0.0, 0.2),
world.random.triangle(0.5, 0.2),
world.random.triangle(0.0, 0.2)));
} else {
entity.setPos(pos.getX() + 0.5D, pos.getY() - entity.getBbHeight(), pos.getZ() + 0.5D);
entity.setDeltaMovement(new Vec3(0, -0.5, 0));
}
world.addFreshEntity(entity);
stack.copyWithCount(1);
} else spawnItem(world, pos, stack, dropItemsAtPos);
} else if (stack.getItem() == CompatRegistry.BOMB_SPIKY_ITEM.get()) {
Entity entity = CompatRegistry.BOMB_SPIKY.get().create(serverWorld);

if (entity != null && !entity.getType().is(TagRegistry.QUESTION_BLOCK_CANNOT_SPAWN)) {
if (world.getBlockState(pos.above()).isAir() || world.getFluidState(pos.above()).is(FluidTags.WATER)) {
entity.setPos(pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D);
entity.setDeltaMovement(new Vec3(
world.random.triangle(0.0, 0.2),
world.random.triangle(0.5, 0.2),
world.random.triangle(0.0, 0.2)));
} else {
entity.setPos(pos.getX() + 0.5D, pos.getY() - entity.getBbHeight(), pos.getZ() + 0.5D);
entity.setDeltaMovement(new Vec3(0, -0.5, 0));
Expand Down Expand Up @@ -433,6 +483,10 @@ else if (stack.getItem() == CompatRegistry.HAT_STAND_ITEM.get())
world.playSound(null, pos, SoundEvents.ARMOR_STAND_PLACE, SoundSource.BLOCKS, 1.0F, 1.0F);
else if (stack.getItem() == CompatRegistry.CANNONBALL_ITEM.get())
world.playSound(null, pos, CompatRegistry.CANNON_SOUND.get(), SoundSource.BLOCKS, 1.0F, 1.0F);
else if (stack.getItem() == CompatRegistry.BOMB_ITEM.get()
|| stack.getItem() == CompatRegistry.BOMB_BLUE_ITEM.get()
|| stack.getItem() == CompatRegistry.BOMB_SPIKY_ITEM.get())
world.playSound(null, pos, CompatRegistry.BOMB_SOUND.get(), SoundSource.BLOCKS, 1.0F, 1.0F);
else world.playSound(null, pos, SoundRegistry.ITEM_SPAWNS.get(), SoundSource.BLOCKS, 1.0F, 1.0F);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@

public class CompatRegistry {
public static final Supplier<Item> ANTIQUE_INK = make("supplementaries:antique_ink", BuiltInRegistries.ITEM);
public static final Supplier<Item> BOMB_ITEM = make("supplementaries:bomb", BuiltInRegistries.ITEM);
public static final Supplier<Item> BOMB_BLUE_ITEM = make("supplementaries:bomb_blue", BuiltInRegistries.ITEM);
public static final Supplier<Item> BOMB_SPIKY_ITEM = make("supplementaries:bomb_spiky", BuiltInRegistries.ITEM);
public static final Supplier<Item> BUBBLE_BLOWER = make("supplementaries:bubble_blower", BuiltInRegistries.ITEM);
public static final Supplier<Item> CANNONBALL_ITEM = make("supplementaries:cannonball", BuiltInRegistries.ITEM);
public static final Supplier<Item> HAT_STAND_ITEM = make("supplementaries:hat_stand", BuiltInRegistries.ITEM);
public static final Supplier<Item> SOAP = make("supplementaries:soap", BuiltInRegistries.ITEM);

public static final Supplier<EntityType<?>> BOMB = make("supplementaries:bomb", BuiltInRegistries.ENTITY_TYPE);
public static final Supplier<EntityType<?>> BOMB_BLUE = make("supplementaries:bomb_blue", BuiltInRegistries.ENTITY_TYPE);
public static final Supplier<EntityType<?>> BOMB_SPIKY = make("supplementaries:bomb_spiky", BuiltInRegistries.ENTITY_TYPE);
public static final Supplier<EntityType<?>> CANNONBALL = make("supplementaries:cannonball", BuiltInRegistries.ENTITY_TYPE);
public static final Supplier<EntityType<?>> HAT_STAND = make("supplementaries:hat_stand", BuiltInRegistries.ENTITY_TYPE);
public static final Supplier<Item> SOAP = make("supplementaries:soap", BuiltInRegistries.ITEM);

public static final Supplier<ParticleType<?>> SUDS_PARTICLE = make("supplementaries:suds", BuiltInRegistries.PARTICLE_TYPE);

public static final Supplier<SoundEvent> BOMB_SOUND = make("supplementaries:item.bomb", BuiltInRegistries.SOUND_EVENT);
public static final Supplier<SoundEvent> CANNON_SOUND = make("supplementaries:block.cannon.fire", BuiltInRegistries.SOUND_EVENT);
public static final Supplier<SoundEvent> BUBBLE_BLOWER_SOUND = make("supplementaries:item.bubble_blower", BuiltInRegistries.SOUND_EVENT);

Expand Down
55 changes: 55 additions & 0 deletions src/main/java/com/wenxin2/marioverse/mixin/ContainersMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,57 @@ private static void dropContents(Level world, double x, double y, double z, Cont
world.addFreshEntity(entity);
stack.copyWithCount(1);
} else marioverse$spawnItem(world, pos, stack);
} else if (stack.getItem() == CompatRegistry.BOMB_ITEM.get()) {
Entity entity = CompatRegistry.BOMB.get().create(serverWorld);

if (entity != null && !entity.getType().is(cannotSpawn)) {
if (world.getBlockState(pos.above()).isAir() || world.getFluidState(pos.above()).is(FluidTags.WATER)) {
entity.setPos(pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D);
entity.setDeltaMovement(new Vec3(
world.random.triangle(0.0, 0.2),
world.random.triangle(0.5, 0.2),
world.random.triangle(0.0, 0.2)));
} else {
entity.setPos(pos.getX() + 0.5D, pos.getY() - entity.getBbHeight(), pos.getZ() + 0.5D);
entity.setDeltaMovement(new Vec3(0, -0.5, 0));
}
world.addFreshEntity(entity);
stack.copyWithCount(1);
} else marioverse$spawnItem(world, pos, stack);
} else if (stack.getItem() == CompatRegistry.BOMB_BLUE_ITEM.get()) {
Entity entity = CompatRegistry.BOMB_BLUE.get().create(serverWorld);

if (entity != null && !entity.getType().is(cannotSpawn)) {
if (world.getBlockState(pos.above()).isAir() || world.getFluidState(pos.above()).is(FluidTags.WATER)) {
entity.setPos(pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D);
entity.setDeltaMovement(new Vec3(
world.random.triangle(0.0, 0.2),
world.random.triangle(0.5, 0.2),
world.random.triangle(0.0, 0.2)));
} else {
entity.setPos(pos.getX() + 0.5D, pos.getY() - entity.getBbHeight(), pos.getZ() + 0.5D);
entity.setDeltaMovement(new Vec3(0, -0.5, 0));
}
world.addFreshEntity(entity);
stack.copyWithCount(1);
} else marioverse$spawnItem(world, pos, stack);
} else if (stack.getItem() == CompatRegistry.BOMB_SPIKY_ITEM.get()) {
Entity entity = CompatRegistry.BOMB_SPIKY.get().create(serverWorld);

if (entity != null && !entity.getType().is(cannotSpawn)) {
if (world.getBlockState(pos.above()).isAir() || world.getFluidState(pos.above()).is(FluidTags.WATER)) {
entity.setPos(pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D);
entity.setDeltaMovement(new Vec3(
world.random.triangle(0.0, 0.2),
world.random.triangle(0.5, 0.2),
world.random.triangle(0.0, 0.2)));
} else {
entity.setPos(pos.getX() + 0.5D, pos.getY() - entity.getBbHeight(), pos.getZ() + 0.5D);
entity.setDeltaMovement(new Vec3(0, -0.5, 0));
}
world.addFreshEntity(entity);
stack.copyWithCount(1);
} else marioverse$spawnItem(world, pos, stack);
} else marioverse$spawnItem(world, pos, stack);
}
}
Expand Down Expand Up @@ -288,6 +339,10 @@ else if (stack.getItem() == CompatRegistry.HAT_STAND_ITEM.get())
world.playSound(null, pos, SoundEvents.ARMOR_STAND_PLACE, SoundSource.BLOCKS, 1.0F, 1.0F);
else if (stack.getItem() == CompatRegistry.CANNONBALL_ITEM.get())
world.playSound(null, pos, CompatRegistry.CANNON_SOUND.get(), SoundSource.BLOCKS, 1.0F, 1.0F);
else if (stack.getItem() == CompatRegistry.BOMB_ITEM.get()
|| stack.getItem() == CompatRegistry.BOMB_BLUE_ITEM.get()
|| stack.getItem() == CompatRegistry.BOMB_SPIKY_ITEM.get())
world.playSound(null, pos, CompatRegistry.BOMB_SOUND.get(), SoundSource.BLOCKS, 1.0F, 1.0F);
else if (!stack.isEmpty() && !(container instanceof DecoratedPotBlockEntity))
world.playSound(null, pos, SoundRegistry.ITEM_SPAWNS.get(), SoundSource.BLOCKS, 1.0F, 1.0F);
}
Expand Down

0 comments on commit 1fc1c4e

Please sign in to comment.