Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
WenXin20 committed Sep 7, 2024
1 parent e491804 commit 381933d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 29 deletions.
21 changes: 12 additions & 9 deletions src/main/java/com/wenxin2/marioverse/blocks/CoinBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.sounds.SoundSource;
import net.minecraft.tags.FluidTags;
import net.minecraft.util.ParticleUtils;
import net.minecraft.util.valueproviders.UniformInt;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -75,15 +77,16 @@ protected void entityInside(BlockState state, Level world, BlockPos pos, Entity

if (entity instanceof Player player) {
world.playSound(player, pos, SoundRegistry.COIN_PICKUP.get(), SoundSource.BLOCKS, 1.0F, 1.0F);
if (world.isClientSide) {
for (int i = 0; i < 5; i++) {
double motionX = (world.random.nextDouble() - 0.5) * 0.1;
double motionY = world.random.nextDouble() * 0.1;
double motionZ = (world.random.nextDouble() - 0.5) * 0.1;

world.addParticle(ParticleTypes.SCRAPE, player.getX() + 0.5, player.getY() + 0.5, player.getZ() + 0.5, motionX, motionY, motionZ);
}
}
ParticleUtils.spawnParticlesOnBlockFaces(world, pos, ParticleTypes.WAX_OFF, UniformInt.of(1, 1));
// if (world.isClientSide) {
// for (int i = 0; i < 5; i++) {
// double motionX = (world.random.nextDouble() - 0.5) * 0.1;
// double motionY = world.random.nextDouble() * 0.1;
// double motionZ = (world.random.nextDouble() - 0.5) * 0.1;
//
// world.addParticle(ParticleTypes.WAX_OFF, player.getX() + 0.5, player.getY() + 0.5, player.getZ() + 0.5, motionX, motionY, motionZ);
// }
// }

world.removeBlock(pos, false);
player.addItem(coinItem);
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,19 @@ protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Lev
return ItemInteractionResult.SUCCESS;
} else if (heldItem.isEmpty() && (ConfigRegistry.QUESTION_REMOVE_ITEMS.get() || player.isCreative())
&& !state.getValue(EMPTY)) {
ItemStack droppedItem = questionBlockEntity.getItems().getStackInSlot(0);
ItemStack storedItem = questionBlockEntity.getItems().getStackInSlot(0);

if (!droppedItem.isEmpty()) {
if (!storedItem.isEmpty()) {
if (!world.isClientSide)
this.spawnEntity(world, player, pos, droppedItem, false);
this.spawnEntity(world, pos, storedItem);


this.playSoundEffect(world, player, pos, droppedItem);
this.playSoundEffect(world, player, pos, storedItem);
questionBlockEntity.removeItems();
questionBlockEntity.setChanged();
world.playSound(null, pos, SoundEvents.ITEM_PICKUP, SoundSource.BLOCKS, 1.0F, 1.0F);
}

if (droppedItem.isEmpty()) {
if (storedItem.isEmpty()) {
world.setBlock(pos, state.setValue(QuestionBlock.EMPTY, Boolean.TRUE), 3);
}
return ItemInteractionResult.SUCCESS;
Expand All @@ -110,7 +109,7 @@ protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Lev
return ItemInteractionResult.CONSUME;
}

public void spawnEntity(Level world, Entity entity, BlockPos pos, ItemStack stack, Boolean dropEntireStack) {
public void spawnEntity(Level world, BlockPos pos, ItemStack stack) {
if (stack.getItem() instanceof SpawnEggItem spawnEgg && ConfigRegistry.QUESTION_SPAWNS_MOBS.get()) {
EntityType<?> entityType = spawnEgg.getType(stack);

Expand Down Expand Up @@ -143,9 +142,13 @@ public void spawnEntity(Level world, Entity entity, BlockPos pos, ItemStack stac
}

public void playSoundEffect(Level world, Entity entity, BlockPos pos, ItemStack stack) {
if (stack.getItem() instanceof BlockItem blockItem && blockItem.getBlock() instanceof CoinBlock)
world.playSound(entity, pos, SoundRegistry.COIN_PICKUP.get(), SoundSource.BLOCKS, 1.0F, 1.0F);
else {
if (stack.getItem() instanceof BlockItem blockItem) {
if (blockItem.getBlock() instanceof CoinBlock) {
world.playSound(entity, pos, SoundRegistry.COIN_PICKUP.get(), SoundSource.BLOCKS, 1.0F, 1.0F);
} else {
world.playSound(entity, pos, SoundRegistry.POWER_UP_SPAWNS.get(), SoundSource.BLOCKS, 1.0F, 1.0F);
}
} else {
world.playSound(entity, pos, SoundRegistry.POWER_UP_SPAWNS.get(), SoundSource.BLOCKS, 1.0F, 1.0F);
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/com/wenxin2/marioverse/mixin/PlayerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,32 +79,32 @@ public void baseTick() {
// }

if (world.getBlockEntity(posAboveEntity) instanceof QuestionBlockEntity questionBlockEntity
&& !stateAboveEntity.getValue(QuestionBlock.EMPTY) && this.getDeltaMovement().y > 0)
this.marioverse$hitQuestionBlock(world, state, posAboveEntity, questionBlockEntity);
&& this.getDeltaMovement().y > 0)
this.marioverse$hitQuestionBlock(world, posAboveEntity, questionBlockEntity);
}

@Unique
public void marioverse$hitQuestionBlock(Level world, BlockState state, BlockPos pos, QuestionBlockEntity questionBlockEntity) {
public void marioverse$hitQuestionBlock(Level world, BlockPos pos, QuestionBlockEntity questionBlockEntity) {

if (!world.isClientSide && world.getBlockState(pos).getBlock() instanceof QuestionBlock questionBlock) {
if (world.getBlockState(pos).getBlock() instanceof QuestionBlock questionBlock) {
world.playSound(null, pos, SoundEvents.CHISELED_BOOKSHELF_PICKUP, SoundSource.BLOCKS, 1.0F, 1.0F);
ItemStack storedItem = questionBlockEntity.getItems().getStackInSlot(0);
if (!storedItem.isEmpty()) {
questionBlock.spawnEntity(world, this, pos.above(), storedItem, false);

if (!storedItem.isEmpty() && !world.getBlockState(pos).getValue(QuestionBlock.EMPTY)) {
if (!world.isClientSide)
questionBlock.spawnEntity(world, pos, storedItem);
questionBlock.playSoundEffect(world, this, pos, storedItem);
questionBlockEntity.removeItems();
questionBlockEntity.setChanged();
world.playSound(null, pos, SoundEvents.ITEM_PICKUP, SoundSource.BLOCKS, 1.0F, 1.0F);
}

if (storedItem.isEmpty() && world.getBlockState(pos).getBlock() instanceof QuestionBlock) {
if (storedItem.isEmpty() && !world.getBlockState(pos).getValue(QuestionBlock.EMPTY)) {
BlockState currentState = world.getBlockState(pos);
if (currentState.getBlock() instanceof QuestionBlock)
world.setBlock(pos, currentState.setValue(QuestionBlock.EMPTY, Boolean.TRUE), 3);
}

if (state.getValue(QuestionBlock.EMPTY))
if (world.getBlockState(pos).getValue(QuestionBlock.EMPTY))
world.playSound(null, pos, SoundRegistry.BLOCK_BONK.get(), SoundSource.BLOCKS, 1.0F, 1.0F);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/marioverse/sounds.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{ "name": "block/iron_trapdoor/close3", "stream": false },
{ "name": "block/iron_trapdoor/close4", "stream": false }], "subtitle": "subtitles.marioverse.block.pipe_closes" },

"block.pipe_warps": {"category": "block", "sounds": [{ "name": "marioverse:block/pipe_warps", "stream": false },
"block.pipe_warps": {"category": "block", "sounds": [{ "name": "marioverse:block/pipe_warps", "stream": false, "pitch": 1.0, "volume": 1.25 },
{ "name": "marioverse:block/pipe_warps_64", "stream": false, "pitch": 1.0, "volume": 0.5 }], "subtitle": "subtitles.marioverse.block.pipe_warps" },

"block.power_up_spawns": {"category": "block", "sounds": [{ "name": "marioverse:block/power_up_spawns", "stream": false }],
Expand Down

0 comments on commit 381933d

Please sign in to comment.