diff --git a/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java b/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java index 85bbfd4e..bb3c32ad 100644 --- a/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java +++ b/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java @@ -6,8 +6,10 @@ import com.wenxin2.marioverse.init.TagRegistry; import com.wenxin2.marioverse.init.SoundRegistry; import com.wenxin2.marioverse.items.BasePowerUpItem; +import java.util.function.Consumer; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.world.Containers; import net.minecraft.world.InteractionHand; @@ -17,20 +19,30 @@ import net.minecraft.world.entity.MobSpawnType; import net.minecraft.world.entity.decoration.ArmorStand; import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.item.PrimedTnt; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.vehicle.AbstractMinecart; +import net.minecraft.world.entity.vehicle.Boat; +import net.minecraft.world.entity.vehicle.ChestBoat; +import net.minecraft.world.entity.vehicle.Minecart; import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.ArmorStandItem; import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.BoatItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.minecraft.world.item.MinecartItem; import net.minecraft.world.item.SpawnEggItem; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.TntBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.BlockHitResult; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -143,8 +155,18 @@ protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Lev if (storedItem.getItem() instanceof BlockItem blockItem && blockItem.getBlock() instanceof CoinBlock) this.playCoinSound(world, pos); + else if (storedItem.getItem() instanceof BlockItem blockItem && blockItem.getBlock() instanceof TntBlock) + this.playPrimedTNTSound(world, pos); + else if (storedItem.getItem() instanceof BasePowerUpItem) + this.playPowerUpSound(world, pos); else if (storedItem.getItem() instanceof SpawnEggItem) this.playMobSound(world, pos); + else if (storedItem.getItem() instanceof ArmorStandItem) + this.playArmorStandSound(world, pos); + else if (storedItem.getItem() instanceof BoatItem) + this.playBoatSound(world, pos); + else if (storedItem.getItem() instanceof MinecartItem) + this.playMinecartSound(world, pos); else this.playItemSound(world, pos); questionBlockEntity.removeItems(); @@ -197,11 +219,41 @@ public void spawnEntity(Level world, BlockPos pos, ItemStack stack) { ItemEntity itemEntity = new ItemEntity(world, pos.getX() + 0.5D, pos.getY() - 0.5D, pos.getZ() + 0.5D, stack.copyWithCount(1)); world.addFreshEntity(itemEntity); } - } else if (stack.getItem() == Items.ARMOR_STAND) { - ArmorStand armorStand = new ArmorStand(EntityType.ARMOR_STAND, world); - armorStand.setPos(pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D); - world.addFreshEntity(armorStand); + } else if (stack.getItem() instanceof ArmorStandItem && world instanceof ServerLevel serverWorld) { + Consumer consumer = EntityType.createDefaultStackConfig(serverWorld, stack, null); + ArmorStand armorStand = EntityType.ARMOR_STAND.create(serverWorld, consumer, pos, MobSpawnType.SPAWN_EGG, true, true); + if (armorStand != null) { + if (world.getBlockState(pos.above()).isAir()) + armorStand.setPos(pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D); + else armorStand.setPos(pos.getX() + 0.5D, pos.below((int) Math.max(1, armorStand.getBbHeight())).getY(), pos.getZ() + 0.5D); + world.addFreshEntity(armorStand); + stack.copyWithCount(1); + } + } else if (stack.getItem() instanceof MinecartItem cart && world instanceof ServerLevel serverWorld) { + AbstractMinecart abstractMinecart = + AbstractMinecart.createMinecart(serverWorld, pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D, cart.type, stack, null); + if (world.getBlockState(pos.above()).isAir()) + abstractMinecart.setPos(pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D); + else abstractMinecart.setPos(pos.getX() + 0.5D, pos.below((int) Math.max(1, abstractMinecart.getBbHeight())).getY(), pos.getZ() + 0.5D); + world.addFreshEntity(abstractMinecart); + stack.copyWithCount(1); + } else if (stack.getItem() instanceof BoatItem boatItem && world instanceof ServerLevel serverWorld) { + Boat boat = boatItem.hasChest ? new ChestBoat(serverWorld, pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D) + : new Boat(serverWorld, pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D); + if (world.getBlockState(pos.above()).isAir()) + boat.setPos(pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D); + else boat.setPos(pos.getX() + 0.5D, pos.below((int) Math.max(1, boat.getBbHeight())).getY(), pos.getZ() + 0.5D); + boat.setVariant(boatItem.type); + world.addFreshEntity(boat); stack.copyWithCount(1); + } else if (stack.getItem() instanceof BlockItem blockItem && blockItem.getBlock() instanceof TntBlock && world instanceof ServerLevel serverWorld) { + PrimedTnt primedtnt = new PrimedTnt(serverWorld, pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, null); + if (world.getBlockState(pos.above()).isAir()) + primedtnt.setPos(pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D); + else primedtnt.setPos(pos.getX() + 0.5D, pos.below((int) Math.max(1, primedtnt.getBbHeight())).getY(), pos.getZ() + 0.5D); + world.addFreshEntity(primedtnt); + stack.copyWithCount(1); + serverWorld.gameEvent(null, GameEvent.PRIME_FUSE, pos); } else { if (world.getBlockState(pos.above()).isAir()) { ItemEntity itemEntity = new ItemEntity(world, pos.getX() + 0.5D, pos.getY() + 1.0D, pos.getZ() + 0.5D, stack.copyWithCount(1)); @@ -213,20 +265,36 @@ public void spawnEntity(Level world, BlockPos pos, ItemStack stack) { } } - public void playMobSound(Level world, BlockPos pos) { - world.playSound(null, pos, SoundRegistry.MOB_SPAWNS.get(), SoundSource.BLOCKS, 1.0F, 1.0F); + public void playArmorStandSound(Level world, BlockPos pos) { + world.playSound(null, pos, SoundEvents.ARMOR_STAND_PLACE, SoundSource.BLOCKS, 1.0F, 1.0F); + } + + public void playBoatSound(Level world, BlockPos pos) { + world.playSound(null, pos, SoundEvents.BOAT_PADDLE_WATER, SoundSource.BLOCKS, 1.0F, 1.0F); + } + + public void playCoinSound(Level world, BlockPos pos) { + world.playSound(null, pos, SoundRegistry.COIN_PICKUP.get(), SoundSource.BLOCKS, 1.0F, 1.0F); } public void playItemSound(Level world, BlockPos pos) { world.playSound(null, pos, SoundRegistry.ITEM_SPAWNS.get(), SoundSource.BLOCKS, 1.0F, 1.0F); } + public void playMobSound(Level world, BlockPos pos) { + world.playSound(null, pos, SoundRegistry.MOB_SPAWNS.get(), SoundSource.BLOCKS, 1.0F, 1.0F); + } + + public void playMinecartSound(Level world, BlockPos pos) { + world.playSound(null, pos, SoundEvents.MINECART_RIDING, SoundSource.BLOCKS, 1.0F, 1.0F); + } + public void playPowerUpSound(Level world, BlockPos pos) { world.playSound(null, pos, SoundRegistry.POWER_UP_SPAWNS.get(), SoundSource.BLOCKS, 1.0F, 1.0F); } - public void playCoinSound(Level world, BlockPos pos) { - world.playSound(null, pos, SoundRegistry.COIN_PICKUP.get(), SoundSource.BLOCKS, 1.0F, 1.0F); + public void playPrimedTNTSound(Level world, BlockPos pos) { + world.playSound(null, pos, SoundEvents.TNT_PRIMED, SoundSource.BLOCKS, 1.0F, 1.0F); } public void unpackLootTable(Entity entity, QuestionBlockEntity questionBlockEntity) { diff --git a/src/main/java/com/wenxin2/marioverse/mixin/PlayerMixin.java b/src/main/java/com/wenxin2/marioverse/mixin/PlayerMixin.java index db535c9d..736e71b6 100644 --- a/src/main/java/com/wenxin2/marioverse/mixin/PlayerMixin.java +++ b/src/main/java/com/wenxin2/marioverse/mixin/PlayerMixin.java @@ -8,6 +8,7 @@ import com.wenxin2.marioverse.init.ConfigRegistry; import com.wenxin2.marioverse.init.SoundRegistry; import com.wenxin2.marioverse.init.TagRegistry; +import com.wenxin2.marioverse.items.BasePowerUpItem; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -19,10 +20,14 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ArmorStandItem; import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.BoatItem; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.MinecartItem; import net.minecraft.world.item.SpawnEggItem; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.TntBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.asm.mixin.Mixin; @@ -123,10 +128,21 @@ else if (!(stateAboveEntity.getBlock() instanceof QuestionBlock)) ItemStack storedItem = questionBlockEntity.getItems().getFirst(); if (!storedItem.isEmpty() && !world.getBlockState(pos).getValue(QuestionBlock.EMPTY)) { + if (storedItem.getItem() instanceof BlockItem blockItem && blockItem.getBlock() instanceof CoinBlock) questionBlock.playCoinSound(world, pos); + else if (storedItem.getItem() instanceof BlockItem blockItem && blockItem.getBlock() instanceof TntBlock) + questionBlock.playPrimedTNTSound(world, pos); + else if (storedItem.getItem() instanceof BasePowerUpItem) + questionBlock.playPowerUpSound(world, pos); else if (storedItem.getItem() instanceof SpawnEggItem) questionBlock.playMobSound(world, pos); + else if (storedItem.getItem() instanceof ArmorStandItem) + questionBlock.playArmorStandSound(world, pos); + else if (storedItem.getItem() instanceof BoatItem) + questionBlock.playBoatSound(world, pos); + else if (storedItem.getItem() instanceof MinecartItem) + questionBlock.playMinecartSound(world, pos); else questionBlock.playItemSound(world, pos); if (!world.isClientSide) diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 358a4b69..a0a46c7c 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -11,4 +11,8 @@ public net.minecraft.world.entity.animal.IronGolem decreaseAirSupply(I)I # decre public net.minecraft.world.level.block.BaseEntityBlock createTickerHelper(Lnet/minecraft/world/level/block/entity/BlockEntityType;Lnet/minecraft/world/level/block/entity/BlockEntityType;Lnet/minecraft/world/level/block/entity/BlockEntityTicker;)Lnet/minecraft/world/level/block/entity/BlockEntityTicker; # createTickerHelper public net.minecraft.world.level.block.BubbleColumnBlock canExistIn(Lnet/minecraft/world/level/block/state/BlockState;)Z # canExistIn -public net.minecraft.world.level.block.BubbleColumnBlock getColumnState(Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/level/block/state/BlockState; # getColumnState \ No newline at end of file +public net.minecraft.world.level.block.BubbleColumnBlock getColumnState(Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/level/block/state/BlockState; # getColumnState + +public net.minecraft.world.item.MinecartItem type # type +public net.minecraft.world.item.BoatItem type # type +public net.minecraft.world.item.BoatItem hasChest # hasChest \ No newline at end of file