From 495f9fb2e012c0af16223305cddbfefa22b325d0 Mon Sep 17 00:00:00 2001 From: MehVahdJukaar Date: Mon, 15 Jan 2024 01:05:59 +0100 Subject: [PATCH] InteractionResult.sideSuccess! --- .../block/MatrixEnchantingTableBlock.java | 2 +- .../oddities/block/MovingMagnetizedBlock.java | 2 +- .../oddities/block/TinyPotatoBlock.java | 6 +- .../oddities/block/pipe/BasePipeBlock.java | 2 +- .../oddities/block/pipe/CopperPipeBlock.java | 9 +- .../oddities/module/BackpackModule.java | 2 +- .../automation/block/FeedingTroughBlock.java | 6 +- .../content/building/block/RopeBlock.java | 8 +- .../content/building/block/StoolBlock.java | 2 +- .../building/item/QuarkItemFrameItem.java | 2 +- .../building/module/ShearVinesModule.java | 2 +- .../building/module/VariantChestsModule.java | 2 +- .../content/experimental/item/HammerItem.java | 3 +- .../module/QuickArmorSwappingModule.java | 2 +- .../quark/content/mobs/entity/Foxhound.java | 13 +-- .../quark/content/mobs/entity/Shiba.java | 33 +++--- .../quark/content/mobs/entity/Stoneling.java | 102 +++++++++--------- .../content/mobs/item/DiamondHeartItem.java | 4 +- .../quark/content/mobs/item/SoulBeadItem.java | 2 +- .../quark/content/tools/block/CloudBlock.java | 4 +- .../quark/content/tools/item/AbacusItem.java | 2 +- .../content/tools/item/BottledCloudItem.java | 4 +- .../tools/item/PathfindersQuillItem.java | 4 +- .../content/tools/item/PickarangItem.java | 2 +- .../tools/item/SlimeInABucketItem.java | 2 +- .../tools/module/BottledCloudModule.java | 2 +- .../tools/module/SlimeInABucketModule.java | 5 +- .../module/BetterElytraRocketModule.java | 2 +- .../module/ReplaceScaffoldingModule.java | 2 +- .../lootr/LootrVariantChestBlock.java | 4 +- .../lootr/LootrVariantTrappedChestBlock.java | 2 +- 31 files changed, 121 insertions(+), 118 deletions(-) diff --git a/src/main/java/org/violetmoon/quark/addons/oddities/block/MatrixEnchantingTableBlock.java b/src/main/java/org/violetmoon/quark/addons/oddities/block/MatrixEnchantingTableBlock.java index f129cd39e6..cbc00011a4 100644 --- a/src/main/java/org/violetmoon/quark/addons/oddities/block/MatrixEnchantingTableBlock.java +++ b/src/main/java/org/violetmoon/quark/addons/oddities/block/MatrixEnchantingTableBlock.java @@ -94,7 +94,7 @@ public InteractionResult use(@NotNull BlockState state, Level worldIn, @NotNull } else worldIn.setBlockAndUpdate(pos, Blocks.ENCHANTING_TABLE.defaultBlockState()); - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(worldIn.isClientSide); } @Override diff --git a/src/main/java/org/violetmoon/quark/addons/oddities/block/MovingMagnetizedBlock.java b/src/main/java/org/violetmoon/quark/addons/oddities/block/MovingMagnetizedBlock.java index c089c1240b..c38a389036 100644 --- a/src/main/java/org/violetmoon/quark/addons/oddities/block/MovingMagnetizedBlock.java +++ b/src/main/java/org/violetmoon/quark/addons/oddities/block/MovingMagnetizedBlock.java @@ -73,7 +73,7 @@ public boolean useShapeForLightOcclusion(@NotNull BlockState state) { public InteractionResult use(@NotNull BlockState state, Level worldIn, @NotNull BlockPos pos, @NotNull Player player, @NotNull InteractionHand handIn, @NotNull BlockHitResult hit) { if(!worldIn.isClientSide && worldIn.getBlockEntity(pos) == null) { worldIn.removeBlock(pos, false); - return InteractionResult.SUCCESS; + return InteractionResult.CONSUME; } else return InteractionResult.PASS; } diff --git a/src/main/java/org/violetmoon/quark/addons/oddities/block/TinyPotatoBlock.java b/src/main/java/org/violetmoon/quark/addons/oddities/block/TinyPotatoBlock.java index f5073f0234..b5ec60d970 100644 --- a/src/main/java/org/violetmoon/quark/addons/oddities/block/TinyPotatoBlock.java +++ b/src/main/java/org/violetmoon/quark/addons/oddities/block/TinyPotatoBlock.java @@ -142,12 +142,12 @@ public InteractionResult use(@NotNull BlockState state, Level world, @NotNull Bl if(player instanceof ServerPlayer sp) TinyPotatoModule.patPotatoTrigger.trigger(sp); - if(!world.isClientSide) { + if(world instanceof ServerLevel serverLevel) { AABB box = SHAPE.bounds(); - ((ServerLevel) world).sendParticles(ParticleTypes.HEART, pos.getX() + box.minX + Math.random() * (box.maxX - box.minX), pos.getY() + box.maxY, pos.getZ() + box.minZ + Math.random() * (box.maxZ - box.minZ), 1, 0, 0, 0, 0); + serverLevel.sendParticles(ParticleTypes.HEART, pos.getX() + box.minX + Math.random() * (box.maxX - box.minX), pos.getY() + box.maxY, pos.getZ() + box.minZ + Math.random() * (box.maxZ - box.minZ), 1, 0, 0, 0, 0); } } - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(world.isClientSide); } @NotNull diff --git a/src/main/java/org/violetmoon/quark/addons/oddities/block/pipe/BasePipeBlock.java b/src/main/java/org/violetmoon/quark/addons/oddities/block/pipe/BasePipeBlock.java index d2d97ca497..a980091c2a 100644 --- a/src/main/java/org/violetmoon/quark/addons/oddities/block/pipe/BasePipeBlock.java +++ b/src/main/java/org/violetmoon/quark/addons/oddities/block/pipe/BasePipeBlock.java @@ -132,7 +132,7 @@ public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Play } while(!candidates.isEmpty()); if(fixedAny) - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(worldIn.isClientSide); } return super.use(state, worldIn, pos, player, handIn, hit); diff --git a/src/main/java/org/violetmoon/quark/addons/oddities/block/pipe/CopperPipeBlock.java b/src/main/java/org/violetmoon/quark/addons/oddities/block/pipe/CopperPipeBlock.java index 4fc087c091..e934ecd58a 100644 --- a/src/main/java/org/violetmoon/quark/addons/oddities/block/pipe/CopperPipeBlock.java +++ b/src/main/java/org/violetmoon/quark/addons/oddities/block/pipe/CopperPipeBlock.java @@ -51,7 +51,7 @@ public class CopperPipeBlock extends BasePipeBlock implements SimpleWaterloggedB DOWN_SHAPE, UP_SHAPE, NORTH_SHAPE, SOUTH_SHAPE, WEST_SHAPE, EAST_SHAPE }; - private static final VoxelShape[] shapeCache = new VoxelShape[64]; + private static final VoxelShape[] SHAPE_CACHE = new VoxelShape[64]; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; @@ -59,6 +59,7 @@ public CopperPipeBlock(@Nullable ZetaModule module) { super("pipe", SoundType.COPPER, module); } + // Convert to encased @Override public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) { ItemStack stack = player.getItemInHand(handIn); @@ -84,7 +85,7 @@ public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Play stack.shrink(1); } } - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(worldIn.isClientSide); } return super.use(state, worldIn, pos, player, handIn, hit); @@ -136,7 +137,7 @@ public VoxelShape getShape(@NotNull BlockState state, @NotNull BlockGetter world index += (1 << dir.ordinal()); } - VoxelShape cached = shapeCache[index]; + VoxelShape cached = SHAPE_CACHE[index]; if(cached == null) { VoxelShape currShape = CENTER_SHAPE; @@ -146,7 +147,7 @@ public VoxelShape getShape(@NotNull BlockState state, @NotNull BlockGetter world currShape = Shapes.or(currShape, SIDE_BOXES[dir.ordinal()]); } - shapeCache[index] = currShape; + SHAPE_CACHE[index] = currShape; cached = currShape; } diff --git a/src/main/java/org/violetmoon/quark/addons/oddities/module/BackpackModule.java b/src/main/java/org/violetmoon/quark/addons/oddities/module/BackpackModule.java index 5787c75baf..9ba83f8a9f 100644 --- a/src/main/java/org/violetmoon/quark/addons/oddities/module/BackpackModule.java +++ b/src/main/java/org/violetmoon/quark/addons/oddities/module/BackpackModule.java @@ -156,7 +156,7 @@ public void onArmorStandInteract(ZPlayerInteract.EntityInteractSpecific event) { player.playSound(SoundEvents.ARMOR_EQUIP_LEATHER); event.setCanceled(true); - event.setCancellationResult(InteractionResult.SUCCESS); + event.setCancellationResult(InteractionResult.sidedSuccess(player.level().isClientSide)); } } } diff --git a/src/main/java/org/violetmoon/quark/content/automation/block/FeedingTroughBlock.java b/src/main/java/org/violetmoon/quark/content/automation/block/FeedingTroughBlock.java index abefd09332..87355d7f17 100644 --- a/src/main/java/org/violetmoon/quark/content/automation/block/FeedingTroughBlock.java +++ b/src/main/java/org/violetmoon/quark/content/automation/block/FeedingTroughBlock.java @@ -1,6 +1,7 @@ package org.violetmoon.quark.content.automation.block; import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.Containers; import net.minecraft.world.InteractionHand; @@ -28,6 +29,7 @@ import net.minecraft.world.phys.shapes.*; import net.minecraftforge.common.util.ForgeSoundType; +import net.minecraftforge.network.NetworkHooks; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -133,9 +135,9 @@ public InteractionResult use(@NotNull BlockState state, Level world, @NotNull Bl else { MenuProvider container = this.getMenuProvider(state, world, pos); if(container != null) - player.openMenu(container); + NetworkHooks.openScreen((ServerPlayer) player, container); - return InteractionResult.SUCCESS; + return InteractionResult.CONSUME; } } diff --git a/src/main/java/org/violetmoon/quark/content/building/block/RopeBlock.java b/src/main/java/org/violetmoon/quark/content/building/block/RopeBlock.java index 6ab6d8ec1b..a3332bda75 100755 --- a/src/main/java/org/violetmoon/quark/content/building/block/RopeBlock.java +++ b/src/main/java/org/violetmoon/quark/content/building/block/RopeBlock.java @@ -128,10 +128,10 @@ public InteractionResult use(@NotNull BlockState state, @NotNull Level worldIn, stack.shrink(1); worldIn.playSound(null, pos, soundType.getPlaceSound(), SoundSource.BLOCKS, 0.5F, 1F); - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(worldIn.isClientSide); } } else if(stack.getCapability(ForgeCapabilities.FLUID_HANDLER_ITEM).isPresent()) { //TODO: Forge extension - return FluidUtil.interactWithFluidHandler(player, hand, worldIn, getBottomPos(worldIn, pos), Direction.UP) ? InteractionResult.SUCCESS : InteractionResult.PASS; + return FluidUtil.interactWithFluidHandler(player, hand, worldIn, getBottomPos(worldIn, pos), Direction.UP) ? InteractionResult.sidedSuccess(worldIn.isClientSide) : InteractionResult.PASS; } else if(stack.getItem() == Items.GLASS_BOTTLE) { BlockPos bottomPos = getBottomPos(worldIn, pos); BlockState stateAt = worldIn.getBlockState(bottomPos); @@ -147,7 +147,7 @@ public InteractionResult use(@NotNull BlockState state, @NotNull Level worldIn, else if(!player.getInventory().add(bottleStack)) player.drop(bottleStack, false); - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(worldIn.isClientSide); } return InteractionResult.PASS; @@ -159,7 +159,7 @@ else if(!player.getInventory().add(bottleStack)) } worldIn.playSound(null, pos, soundType.getBreakSound(), SoundSource.BLOCKS, 0.5F, 1F); - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(worldIn.isClientSide); } } } diff --git a/src/main/java/org/violetmoon/quark/content/building/block/StoolBlock.java b/src/main/java/org/violetmoon/quark/content/building/block/StoolBlock.java index 3f8ad15220..094a7a3490 100644 --- a/src/main/java/org/violetmoon/quark/content/building/block/StoolBlock.java +++ b/src/main/java/org/violetmoon/quark/content/building/block/StoolBlock.java @@ -108,7 +108,7 @@ public InteractionResult use(BlockState state, @NotNull Level worldIn, @NotNull worldIn.setBlockAndUpdate(pos, state.setValue(SAT_IN, true)); } - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(worldIn.isClientSide); } @Override diff --git a/src/main/java/org/violetmoon/quark/content/building/item/QuarkItemFrameItem.java b/src/main/java/org/violetmoon/quark/content/building/item/QuarkItemFrameItem.java index cd7d6d3f3c..4cfe919d13 100644 --- a/src/main/java/org/violetmoon/quark/content/building/item/QuarkItemFrameItem.java +++ b/src/main/java/org/violetmoon/quark/content/building/item/QuarkItemFrameItem.java @@ -64,7 +64,7 @@ public InteractionResult useOn(UseOnContext context) { stack.shrink(1); } - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(world.isClientSide); } } diff --git a/src/main/java/org/violetmoon/quark/content/building/module/ShearVinesModule.java b/src/main/java/org/violetmoon/quark/content/building/module/ShearVinesModule.java index addc7f84eb..a1a2907d34 100644 --- a/src/main/java/org/violetmoon/quark/content/building/module/ShearVinesModule.java +++ b/src/main/java/org/violetmoon/quark/content/building/module/ShearVinesModule.java @@ -75,7 +75,7 @@ public void onRightClick(ZRightClickBlock event) { if(!player.getAbilities().instabuild) MiscUtil.damageStack(player, event.getHand(), stack, 1); - event.setCancellationResult(InteractionResult.SUCCESS); + event.setCancellationResult(InteractionResult.sidedSuccess(world.isClientSide)); event.setCanceled(true); } } diff --git a/src/main/java/org/violetmoon/quark/content/building/module/VariantChestsModule.java b/src/main/java/org/violetmoon/quark/content/building/module/VariantChestsModule.java index 005fab7935..9f14629186 100644 --- a/src/main/java/org/violetmoon/quark/content/building/module/VariantChestsModule.java +++ b/src/main/java/org/violetmoon/quark/content/building/module/VariantChestsModule.java @@ -232,7 +232,7 @@ public void onClickEntity(ZPlayerInteract.EntityInteractSpecific event) { if(!horse.hasChest() && held.getItem() != Items.CHEST) { if(held.is(Tags.Items.CHESTS_WOODEN)) { event.setCanceled(true); - event.setCancellationResult(InteractionResult.SUCCESS); + event.setCancellationResult(InteractionResult.sidedSuccess(player.level().isClientSide)); if(!target.level().isClientSide) { ItemStack copy = held.copy(); diff --git a/src/main/java/org/violetmoon/quark/content/experimental/item/HammerItem.java b/src/main/java/org/violetmoon/quark/content/experimental/item/HammerItem.java index 3147840831..9e5f5b46ef 100644 --- a/src/main/java/org/violetmoon/quark/content/experimental/item/HammerItem.java +++ b/src/main/java/org/violetmoon/quark/content/experimental/item/HammerItem.java @@ -57,8 +57,7 @@ public InteractionResult useOn(UseOnContext context) { } else { level.setBlock(pos, state, 0); } - - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(level.isClientSide); } } diff --git a/src/main/java/org/violetmoon/quark/content/management/module/QuickArmorSwappingModule.java b/src/main/java/org/violetmoon/quark/content/management/module/QuickArmorSwappingModule.java index c4b544014d..1f4444d109 100644 --- a/src/main/java/org/violetmoon/quark/content/management/module/QuickArmorSwappingModule.java +++ b/src/main/java/org/violetmoon/quark/content/management/module/QuickArmorSwappingModule.java @@ -29,7 +29,7 @@ public void onEntityInteractSpecific(ZPlayerInteract.EntityInteractSpecific even if(player.isCrouching()) { event.setCanceled(true); - event.setCancellationResult(InteractionResult.SUCCESS); + event.setCancellationResult(InteractionResult.sidedSuccess(player.level().isClientSide)); swapSlot(player, armorStand, EquipmentSlot.HEAD); swapSlot(player, armorStand, EquipmentSlot.CHEST); diff --git a/src/main/java/org/violetmoon/quark/content/mobs/entity/Foxhound.java b/src/main/java/org/violetmoon/quark/content/mobs/entity/Foxhound.java index a26d08878d..0f14cde0dd 100755 --- a/src/main/java/org/violetmoon/quark/content/mobs/entity/Foxhound.java +++ b/src/main/java/org/violetmoon/quark/content/mobs/entity/Foxhound.java @@ -295,6 +295,7 @@ public InteractionResult mobInteract(Player player, @NotNull InteractionHand han if(itemstack.getItem() == Items.BONE && !isTame()) return InteractionResult.PASS; + Level level = level(); if(this.isTame()) { if(timeUntilPotatoEmerges <= 0 && itemstack.is(TinyPotatoModule.tiny_potato.asItem())) { timeUntilPotatoEmerges = 600; @@ -302,31 +303,31 @@ public InteractionResult mobInteract(Player player, @NotNull InteractionHand han playSound(QuarkSounds.ENTITY_FOXHOUND_EAT, 1f, 1f); if(!player.getAbilities().instabuild) itemstack.shrink(1); - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(level.isClientSide); } } else { if(!itemstack.isEmpty()) { - if(itemstack.getItem() == Items.COAL && (level().getDifficulty() == Difficulty.PEACEFUL || player.getAbilities().invulnerable || player.getEffect(MobEffects.FIRE_RESISTANCE) != null) && !level().isClientSide) { + if(itemstack.getItem() == Items.COAL && (level.getDifficulty() == Difficulty.PEACEFUL || player.getAbilities().invulnerable || player.getEffect(MobEffects.FIRE_RESISTANCE) != null) && !level.isClientSide) { if(random.nextDouble() < FoxhoundModule.tameChance) { this.tame(player); this.navigation.stop(); this.setTarget(null); this.setOrderedToSit(true); this.setHealth(20.0F); - this.level().broadcastEntityEvent(this, (byte) 7); + level.broadcastEntityEvent(this, (byte) 7); } else { - this.level().broadcastEntityEvent(this, (byte) 6); + level.broadcastEntityEvent(this, (byte) 6); } if(!player.getAbilities().instabuild) itemstack.shrink(1); - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(level.isClientSide); } } } InteractionResult res = super.mobInteract(player, hand); - if(res == InteractionResult.SUCCESS && !level().isClientSide) + if(res.consumesAction() && !level.isClientSide) setWoke(); return res; diff --git a/src/main/java/org/violetmoon/quark/content/mobs/entity/Shiba.java b/src/main/java/org/violetmoon/quark/content/mobs/entity/Shiba.java index b625999842..7780883fa4 100644 --- a/src/main/java/org/violetmoon/quark/content/mobs/entity/Shiba.java +++ b/src/main/java/org/violetmoon/quark/content/mobs/entity/Shiba.java @@ -255,22 +255,22 @@ public void readAdditionalSaveData(@NotNull CompoundTag compound) { public InteractionResult mobInteract(Player player, @NotNull InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); Item item = itemstack.getItem(); + Level level = this.level(); if(player.isDiscrete() && player.getMainHandItem().isEmpty()) { if(hand == InteractionHand.MAIN_HAND && WantLoveGoal.canPet(this)) { - if(player.level() instanceof ServerLevel serverLevel) { + if(level instanceof ServerLevel serverLevel) { Vec3 pos = position(); serverLevel.sendParticles(ParticleTypes.HEART, pos.x, pos.y + 0.5, pos.z, 1, 0, 0, 0, 0.1); playSound(QuarkSounds.ENTITY_SHIBA_WHINE, 0.6F, 0.5F + (float) Math.random() * 0.5F); - } else - player.swing(InteractionHand.MAIN_HAND); + } WantLoveGoal.setPetTime(this); + return InteractionResult.sidedSuccess(level.isClientSide); } - - return InteractionResult.SUCCESS; - } else if(this.level().isClientSide) { + } + else if(level.isClientSide) { boolean flag = this.isOwnedBy(player) || this.isTame() || item == Items.BONE && !this.isTame(); - return flag ? InteractionResult.CONSUME : InteractionResult.PASS; + return flag ? InteractionResult.SUCCESS : InteractionResult.PASS; } else { if(this.isTame()) { ItemStack mouthItem = getMouthItem(); @@ -285,7 +285,7 @@ public InteractionResult mobInteract(Player player, @NotNull InteractionHand han playSound(QuarkSounds.ENTITY_SHIBA_WHINE, 0.6F, 0.5F + (float) Math.random() * 0.5F); } setMouthItem(ItemStack.EMPTY); - return InteractionResult.SUCCESS; + return InteractionResult.CONSUME; } if(this.isFood(itemstack) && this.getHealth() < this.getMaxHealth()) { @@ -294,7 +294,7 @@ public InteractionResult mobInteract(Player player, @NotNull InteractionHand han } this.heal((float) item.getFoodProperties().getNutrition()); - return InteractionResult.SUCCESS; + return InteractionResult.CONSUME; } if(!(item instanceof DyeItem)) { @@ -304,7 +304,7 @@ public InteractionResult mobInteract(Player player, @NotNull InteractionHand han itemstack.setCount(itemstack.getCount() - 1); setMouthItem(copy); - return InteractionResult.SUCCESS; + return InteractionResult.CONSUME; } InteractionResult actionresulttype = super.mobInteract(player, hand); @@ -313,7 +313,7 @@ public InteractionResult mobInteract(Player player, @NotNull InteractionHand han this.jumping = false; this.navigation.stop(); this.setTarget(null); - return InteractionResult.SUCCESS; + return InteractionResult.CONSUME; } return actionresulttype; @@ -326,7 +326,7 @@ public InteractionResult mobInteract(Player player, @NotNull InteractionHand han itemstack.shrink(1); } - return InteractionResult.SUCCESS; + return InteractionResult.CONSUME; } } else if(item == Items.BONE) { if(!player.getAbilities().instabuild) { @@ -340,16 +340,15 @@ public InteractionResult mobInteract(Player player, @NotNull InteractionHand han this.navigation.stop(); this.setTarget(null); this.setOrderedToSit(true); - this.level().broadcastEntityEvent(this, (byte) 7); + level.broadcastEntityEvent(this, (byte) 7); } else { - this.level().broadcastEntityEvent(this, (byte) 6); + level.broadcastEntityEvent(this, (byte) 6); } - return InteractionResult.SUCCESS; + return InteractionResult.CONSUME; } - - return super.mobInteract(player, hand); } + return super.mobInteract(player, hand); } @Override diff --git a/src/main/java/org/violetmoon/quark/content/mobs/entity/Stoneling.java b/src/main/java/org/violetmoon/quark/content/mobs/entity/Stoneling.java index d3219c28ca..e77cbb7f42 100755 --- a/src/main/java/org/violetmoon/quark/content/mobs/entity/Stoneling.java +++ b/src/main/java/org/violetmoon/quark/content/mobs/entity/Stoneling.java @@ -173,73 +173,75 @@ public InteractionResult interactAt(@NotNull Player player, @NotNull Vec3 vec, @ ItemStack playerItem = player.getItemInHand(hand); Vec3 pos = position(); - if(!level().isClientSide) { - if(isPlayerMade()) { - if(!player.isDiscrete() && !playerItem.isEmpty()) { - StonelingVariant currentVariant = getVariant(); - StonelingVariant targetVariant = null; - Block targetBlock = null; - mainLoop: for(StonelingVariant variant : StonelingVariant.values()) { - for(Block block : variant.getBlocks()) { - if(block.asItem() == playerItem.getItem()) { - targetVariant = variant; - targetBlock = block; - break mainLoop; - } + Level level = level(); + if(isPlayerMade()) { + if(!player.isDiscrete() && !playerItem.isEmpty()) { + StonelingVariant currentVariant = getVariant(); + StonelingVariant targetVariant = null; + Block targetBlock = null; + mainLoop: for(StonelingVariant variant : StonelingVariant.values()) { + for(Block block : variant.getBlocks()) { + if(block.asItem() == playerItem.getItem()) { + targetVariant = variant; + targetBlock = block; + break mainLoop; } } + } - if(targetVariant != null) { - if(level() instanceof ServerLevel serverLevel) { - serverLevel.sendParticles(ParticleTypes.HEART, pos.x, pos.y + getBbHeight(), pos.z, 1, 0.1, 0.1, 0.1, 0.1); - if(targetVariant != currentVariant) - serverLevel.sendParticles(new BlockParticleOption(ParticleTypes.BLOCK, targetBlock.defaultBlockState()), pos.x, pos.y + getBbHeight() / 2, pos.z, 16, 0.1, 0.1, 0.1, 0.25); - } - - if(targetVariant != currentVariant) { - playSound(QuarkSounds.ENTITY_STONELING_EAT, 1F, 1F); - entityData.set(VARIANT, targetVariant.getIndex()); - } + if(targetVariant != null) { + if(level instanceof ServerLevel serverLevel) { + serverLevel.sendParticles(ParticleTypes.HEART, pos.x, pos.y + getBbHeight(), pos.z, 1, 0.1, 0.1, 0.1, 0.1); + if(targetVariant != currentVariant) + serverLevel.sendParticles(new BlockParticleOption(ParticleTypes.BLOCK, targetBlock.defaultBlockState()), pos.x, pos.y + getBbHeight() / 2, pos.z, 16, 0.1, 0.1, 0.1, 0.25); + } - playSound(QuarkSounds.ENTITY_STONELING_PURR, 1F, 1F + level().random.nextFloat()); + if(targetVariant != currentVariant) { + playSound(QuarkSounds.ENTITY_STONELING_EAT, 1F, 1F); + entityData.set(VARIANT, targetVariant.getIndex()); + } - heal(1); + playSound(QuarkSounds.ENTITY_STONELING_PURR, 1F, 1F + level.random.nextFloat()); - if(!player.getAbilities().instabuild) - playerItem.shrink(1); + heal(1); - return InteractionResult.SUCCESS; - } + if(!player.getAbilities().instabuild) + playerItem.shrink(1); - return InteractionResult.PASS; + return InteractionResult.sidedSuccess(level.isClientSide); } - ItemStack stonelingItem = entityData.get(CARRYING_ITEM); + return InteractionResult.PASS; + } - if(!stonelingItem.isEmpty() || !playerItem.isEmpty()) { - player.setItemInHand(hand, stonelingItem.copy()); - entityData.set(CARRYING_ITEM, playerItem.copy()); + ItemStack stonelingItem = entityData.get(CARRYING_ITEM); - if(playerItem.isEmpty()) - playSound(QuarkSounds.ENTITY_STONELING_GIVE, 1F, 1F); - else - playSound(QuarkSounds.ENTITY_STONELING_TAKE, 1F, 1F); - } - } else if(StonelingsModule.tamableStonelings && playerItem.is(temptTag())) { - heal(8); + if(!stonelingItem.isEmpty() || !playerItem.isEmpty()) { + player.setItemInHand(hand, stonelingItem.copy()); + entityData.set(CARRYING_ITEM, playerItem.copy()); - setPlayerMade(true); + if(playerItem.isEmpty()) + playSound(QuarkSounds.ENTITY_STONELING_GIVE, 1F, 1F); + else + playSound(QuarkSounds.ENTITY_STONELING_TAKE, 1F, 1F); - playSound(QuarkSounds.ENTITY_STONELING_PURR, 1F, 1F + level().random.nextFloat()); + return InteractionResult.sidedSuccess(level.isClientSide); + } - if(!player.getAbilities().instabuild) - playerItem.shrink(1); + } else if(StonelingsModule.tamableStonelings && playerItem.is(temptTag())) { + heal(8); - if(level() instanceof ServerLevel) - ((ServerLevel) level()).sendParticles(ParticleTypes.HEART, pos.x, pos.y + getBbHeight(), pos.z, 4, 0.1, 0.1, 0.1, 0.1); + setPlayerMade(true); - return InteractionResult.SUCCESS; - } + playSound(QuarkSounds.ENTITY_STONELING_PURR, 1F, 1F + level.random.nextFloat()); + + if(!player.getAbilities().instabuild) + playerItem.shrink(1); + + if(level instanceof ServerLevel serverLevel) + serverLevel.sendParticles(ParticleTypes.HEART, pos.x, pos.y + getBbHeight(), pos.z, 4, 0.1, 0.1, 0.1, 0.1); + + return InteractionResult.sidedSuccess(level.isClientSide); } } diff --git a/src/main/java/org/violetmoon/quark/content/mobs/item/DiamondHeartItem.java b/src/main/java/org/violetmoon/quark/content/mobs/item/DiamondHeartItem.java index e9eb7e8bed..644dcc7c06 100755 --- a/src/main/java/org/violetmoon/quark/content/mobs/item/DiamondHeartItem.java +++ b/src/main/java/org/violetmoon/quark/content/mobs/item/DiamondHeartItem.java @@ -58,7 +58,7 @@ public InteractionResult useOn(UseOnContext context) { } if(variant != null) { - if(!world.isClientSide && world instanceof ServerLevelAccessor serverLevel) { + if(world instanceof ServerLevelAccessor serverLevel) { world.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState()); world.levelEvent(LevelEvent.PARTICLES_DESTROY_BLOCK, pos, Block.getId(stateAt)); @@ -78,7 +78,7 @@ public InteractionResult useOn(UseOnContext context) { stack.shrink(1); } - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(world.isClientSide); } } } diff --git a/src/main/java/org/violetmoon/quark/content/mobs/item/SoulBeadItem.java b/src/main/java/org/violetmoon/quark/content/mobs/item/SoulBeadItem.java index 7c334e17f2..f94200dd9c 100644 --- a/src/main/java/org/violetmoon/quark/content/mobs/item/SoulBeadItem.java +++ b/src/main/java/org/violetmoon/quark/content/mobs/item/SoulBeadItem.java @@ -54,7 +54,7 @@ public InteractionResultHolder use(Level worldIn, Player playerIn, @N playerIn.swing(handIn); playerIn.awardStat(Stats.ITEM_USED.get(this)); - return new InteractionResultHolder<>(InteractionResult.SUCCESS, itemstack); + return InteractionResultHolder.sidedSuccess(itemstack, worldIn.isClientSide); } } diff --git a/src/main/java/org/violetmoon/quark/content/tools/block/CloudBlock.java b/src/main/java/org/violetmoon/quark/content/tools/block/CloudBlock.java index ac2b10615d..c5e760a27c 100644 --- a/src/main/java/org/violetmoon/quark/content/tools/block/CloudBlock.java +++ b/src/main/java/org/violetmoon/quark/content/tools/block/CloudBlock.java @@ -60,7 +60,7 @@ public InteractionResult use(@NotNull BlockState state, @NotNull Level world, @N if(stack.getItem() == Items.GLASS_BOTTLE) { fillBottle(player, player.getInventory().selected); world.removeBlock(pos, false); - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(world.isClientSide); } if(stack.getItem() instanceof BlockItem bitem) { @@ -79,7 +79,7 @@ public InteractionResult use(@NotNull BlockState state, @NotNull Level world, @N fillBottle(player, 0); } - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(world.isClientSide); } } diff --git a/src/main/java/org/violetmoon/quark/content/tools/item/AbacusItem.java b/src/main/java/org/violetmoon/quark/content/tools/item/AbacusItem.java index 20b1891807..94c4bb1001 100644 --- a/src/main/java/org/violetmoon/quark/content/tools/item/AbacusItem.java +++ b/src/main/java/org/violetmoon/quark/content/tools/item/AbacusItem.java @@ -47,7 +47,7 @@ public InteractionResult useOn(UseOnContext context) { else setBlockPos(stack, context.getClickedPos()); - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(context.getLevel().isClientSide); } public static void setBlockPos(ItemStack stack, BlockPos pos) { diff --git a/src/main/java/org/violetmoon/quark/content/tools/item/BottledCloudItem.java b/src/main/java/org/violetmoon/quark/content/tools/item/BottledCloudItem.java index 67aa817ebc..03ba01f636 100644 --- a/src/main/java/org/violetmoon/quark/content/tools/item/BottledCloudItem.java +++ b/src/main/java/org/violetmoon/quark/content/tools/item/BottledCloudItem.java @@ -60,11 +60,11 @@ else if(!player.addItem(returnStack)) } player.getCooldowns().addCooldown(this, 10); - return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack); + return InteractionResultHolder.sidedSuccess(stack, world.isClientSide); } } - return new InteractionResultHolder<>(InteractionResult.PASS, stack); + return InteractionResultHolder.pass(stack); } } diff --git a/src/main/java/org/violetmoon/quark/content/tools/item/PathfindersQuillItem.java b/src/main/java/org/violetmoon/quark/content/tools/item/PathfindersQuillItem.java index 2588a98a45..02d9e70328 100644 --- a/src/main/java/org/violetmoon/quark/content/tools/item/PathfindersQuillItem.java +++ b/src/main/java/org/violetmoon/quark/content/tools/item/PathfindersQuillItem.java @@ -157,7 +157,7 @@ public InteractionResultHolder use(Level level, Player player, Intera ItemNBTHelper.setBoolean(stack, TAG_IS_SEARCHING, true); ItemNBTHelper.setInt(stack, TAG_SOURCE_X, player.getBlockX()); ItemNBTHelper.setInt(stack, TAG_SOURCE_Z, player.getBlockZ()); - return InteractionResultHolder.success(stack); + return InteractionResultHolder.sidedSuccess(stack, level.isClientSide); } public ResourceLocation getTarget(ItemStack stack) { @@ -311,7 +311,7 @@ protected InteractionResultHolder searchIterative( if(holder.is(searchKey)) { BlockPos mapPos = new BlockPos(testX, testY, testZ); - return InteractionResultHolder.success(mapPos); + return InteractionResultHolder.sidedSuccess(mapPos, level.isClientSide); } } } diff --git a/src/main/java/org/violetmoon/quark/content/tools/item/PickarangItem.java b/src/main/java/org/violetmoon/quark/content/tools/item/PickarangItem.java index 550bf00830..ac89d3a339 100755 --- a/src/main/java/org/violetmoon/quark/content/tools/item/PickarangItem.java +++ b/src/main/java/org/violetmoon/quark/content/tools/item/PickarangItem.java @@ -123,7 +123,7 @@ public InteractionResultHolder use(Level worldIn, Player playerIn, @N playerIn.awardStat(Stats.ITEM_USED.get(this)); - return new InteractionResultHolder<>(InteractionResult.SUCCESS, itemstack); + return InteractionResultHolder.sidedSuccess( itemstack, worldIn.isClientSide); } @SuppressWarnings("deprecation") //Avoiding FOrge extension diff --git a/src/main/java/org/violetmoon/quark/content/tools/item/SlimeInABucketItem.java b/src/main/java/org/violetmoon/quark/content/tools/item/SlimeInABucketItem.java index 948233f0dc..7ff9526804 100644 --- a/src/main/java/org/violetmoon/quark/content/tools/item/SlimeInABucketItem.java +++ b/src/main/java/org/violetmoon/quark/content/tools/item/SlimeInABucketItem.java @@ -96,7 +96,7 @@ public InteractionResult useOn(UseOnContext context) { if(!playerIn.getAbilities().instabuild) playerIn.setItemInHand(hand, new ItemStack(Items.BUCKET)); - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(worldIn.isClientSide); } @NotNull diff --git a/src/main/java/org/violetmoon/quark/content/tools/module/BottledCloudModule.java b/src/main/java/org/violetmoon/quark/content/tools/module/BottledCloudModule.java index aafdb047cf..967ffb902b 100644 --- a/src/main/java/org/violetmoon/quark/content/tools/module/BottledCloudModule.java +++ b/src/main/java/org/violetmoon/quark/content/tools/module/BottledCloudModule.java @@ -60,7 +60,7 @@ public void onRightClick(ZPlayerInteract.RightClickItem event) { player.drop(returnStack, false); event.setCanceled(true); - event.setCancellationResult(InteractionResult.SUCCESS); + event.setCancellationResult(InteractionResult.sidedSuccess(player.level().isClientSide)); } } diff --git a/src/main/java/org/violetmoon/quark/content/tools/module/SlimeInABucketModule.java b/src/main/java/org/violetmoon/quark/content/tools/module/SlimeInABucketModule.java index d5824fd996..eb48bac2e9 100644 --- a/src/main/java/org/violetmoon/quark/content/tools/module/SlimeInABucketModule.java +++ b/src/main/java/org/violetmoon/quark/content/tools/module/SlimeInABucketModule.java @@ -65,11 +65,10 @@ else if(!player.getInventory().add(outStack)) event.getLevel().gameEvent(player, GameEvent.ENTITY_INTERACT, event.getTarget().position()); event.getTarget().discard(); - } else - player.swing(hand); + } event.setCanceled(true); - event.setCancellationResult(InteractionResult.SUCCESS); + event.setCancellationResult(InteractionResult.sidedSuccess(player.level().isClientSide)); } } } diff --git a/src/main/java/org/violetmoon/quark/content/tweaks/module/BetterElytraRocketModule.java b/src/main/java/org/violetmoon/quark/content/tweaks/module/BetterElytraRocketModule.java index b71e206914..cd1efe2d94 100644 --- a/src/main/java/org/violetmoon/quark/content/tweaks/module/BetterElytraRocketModule.java +++ b/src/main/java/org/violetmoon/quark/content/tweaks/module/BetterElytraRocketModule.java @@ -35,7 +35,7 @@ public void onUseRocket(ZRightClickItem event) { player.jumpFromGround(); event.setCanceled(true); - event.setCancellationResult(world.isClientSide ? InteractionResult.SUCCESS : InteractionResult.CONSUME); + event.setCancellationResult(InteractionResult.sidedSuccess(world.isClientSide)); } } diff --git a/src/main/java/org/violetmoon/quark/content/tweaks/module/ReplaceScaffoldingModule.java b/src/main/java/org/violetmoon/quark/content/tweaks/module/ReplaceScaffoldingModule.java index df3ebe049d..6ab791101e 100644 --- a/src/main/java/org/violetmoon/quark/content/tweaks/module/ReplaceScaffoldingModule.java +++ b/src/main/java/org/violetmoon/quark/content/tweaks/module/ReplaceScaffoldingModule.java @@ -80,7 +80,7 @@ public void onInteract(ZRightClickBlock event) { } event.setCanceled(true); - event.setCancellationResult(InteractionResult.SUCCESS); + event.setCancellationResult(InteractionResult.sidedSuccess(world.isClientSide)); } } } diff --git a/src/main/java/org/violetmoon/quark/integration/lootr/LootrVariantChestBlock.java b/src/main/java/org/violetmoon/quark/integration/lootr/LootrVariantChestBlock.java index 2398c4495b..7359562f23 100644 --- a/src/main/java/org/violetmoon/quark/integration/lootr/LootrVariantChestBlock.java +++ b/src/main/java/org/violetmoon/quark/integration/lootr/LootrVariantChestBlock.java @@ -76,7 +76,7 @@ public InteractionResult use(BlockState state, Level world, BlockPos pos, Player } else if(!ChestBlock.isChestBlockedAt(world, pos)) { ChestUtil.handleLootChest(this, world, pos, player); } - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(world.isClientSide); } @Override @@ -182,7 +182,7 @@ public InteractionResult onItemUseFirstZeta(ItemStack stack, UseOnContext contex if(newEntity != null && nbt != null) newEntity.load(nbt); - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(level.isClientSide); } } } diff --git a/src/main/java/org/violetmoon/quark/integration/lootr/LootrVariantTrappedChestBlock.java b/src/main/java/org/violetmoon/quark/integration/lootr/LootrVariantTrappedChestBlock.java index 419875d97c..b80418070a 100644 --- a/src/main/java/org/violetmoon/quark/integration/lootr/LootrVariantTrappedChestBlock.java +++ b/src/main/java/org/violetmoon/quark/integration/lootr/LootrVariantTrappedChestBlock.java @@ -85,7 +85,7 @@ public InteractionResult use(BlockState state, Level world, BlockPos pos, Player } else if(!ChestBlock.isChestBlockedAt(world, pos)) { ChestUtil.handleLootChest(this, world, pos, player); } - return InteractionResult.SUCCESS; + return InteractionResult.sidedSuccess(world.isClientSide); } @Override