diff --git a/Common/src/main/java/tschipp/carryon/CarryOnCommon.java b/Common/src/main/java/tschipp/carryon/CarryOnCommon.java index 0d0e3cf..40cba15 100644 --- a/Common/src/main/java/tschipp/carryon/CarryOnCommon.java +++ b/Common/src/main/java/tschipp/carryon/CarryOnCommon.java @@ -118,11 +118,6 @@ public class CarryOnCommon player.getServer().getCommands().performPrefixedCommand(player.getServer().createCommandSourceStack(), "/execute as " + player.getGameProfile().getName() + " run " + cmd); } - if (!Constants.COMMON_CONFIG.settings.slownessInCreative && player.isCreative()) - return; - - player.addEffect(new MobEffectInstance(MobEffects.SLOWNESS, 1, potionLevel(carry, player.level()), false, false)); - Inventory inv = player.getInventory(); inv.setSelectedSlot(carry.getSelected()); } @@ -180,7 +175,7 @@ public class CarryOnCommon } - private static int potionLevel(CarryOnData carry, Level level) + public static int potionLevel(CarryOnData carry, Level level) { if(carry.isCarrying(CarryType.PLAYER)) return 1; diff --git a/Common/src/main/java/tschipp/carryon/common/carry/PickupHandler.java b/Common/src/main/java/tschipp/carryon/common/carry/PickupHandler.java index fc68f8c..18f630a 100644 --- a/Common/src/main/java/tschipp/carryon/common/carry/PickupHandler.java +++ b/Common/src/main/java/tschipp/carryon/common/carry/PickupHandler.java @@ -26,6 +26,8 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionHand; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.AgeableMob; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity.RemovalReason; @@ -38,6 +40,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec3; +import tschipp.carryon.CarryOnCommon; import tschipp.carryon.Constants; import tschipp.carryon.common.config.ListHandler; import tschipp.carryon.common.pickupcondition.PickupCondition; @@ -145,6 +148,8 @@ public class PickupHandler { CarryOnDataManager.setCarryData(player, carry); level.playSound(null, pos, state.getSoundType().getHitSound(), SoundSource.BLOCKS, 1.0f, 0.5f); player.swing(InteractionHand.MAIN_HAND, true); + if (!player.isCreative() || Constants.COMMON_CONFIG.settings.slownessInCreative) + player.addEffect(new MobEffectInstance(MobEffects.SLOWNESS, 1000000, CarryOnCommon.potionLevel(carry, player.level()), false, false)); return true; } @@ -231,6 +236,8 @@ public class PickupHandler { player.swing(InteractionHand.MAIN_HAND, true); player.level().playSound(null, player.getOnPos(), SoundEvents.ARMOR_EQUIP_GENERIC.value(), SoundSource.AMBIENT, 1.0f, 0.5f); CarryOnDataManager.setCarryData(player, carry); + if (!player.isCreative() || Constants.COMMON_CONFIG.settings.slownessInCreative) + player.addEffect(new MobEffectInstance(MobEffects.SLOWNESS, 1000000, CarryOnCommon.potionLevel(carry, player.level()), false, false)); return true; } @@ -254,6 +261,8 @@ public class PickupHandler { player.level().playSound(null, player.getOnPos(), SoundEvents.ARMOR_EQUIP_GENERIC.value(), SoundSource.AMBIENT, 1.0f, 0.5f); CarryOnDataManager.setCarryData(player, carry); player.swing(InteractionHand.MAIN_HAND, true); + if (!player.isCreative() || Constants.COMMON_CONFIG.settings.slownessInCreative) + player.addEffect(new MobEffectInstance(MobEffects.SLOWNESS, 1000000, CarryOnCommon.potionLevel(carry, player.level()), false, false)); return true; } diff --git a/Common/src/main/java/tschipp/carryon/common/carry/PlacementHandler.java b/Common/src/main/java/tschipp/carryon/common/carry/PlacementHandler.java index a489e46..128e795 100644 --- a/Common/src/main/java/tschipp/carryon/common/carry/PlacementHandler.java +++ b/Common/src/main/java/tschipp/carryon/common/carry/PlacementHandler.java @@ -27,6 +27,8 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionHand; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.animal.horse.Horse; @@ -42,6 +44,7 @@ import net.minecraft.world.level.block.state.properties.Property; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.CollisionContext; +import tschipp.carryon.CarryOnCommon; import tschipp.carryon.Constants; import tschipp.carryon.common.carry.CarryOnData.CarryType; import tschipp.carryon.common.config.ListHandler; @@ -111,6 +114,7 @@ public class PlacementHandler player.playSound(state.getSoundType().getPlaceSound(), 1.0f, 0.5f); level.playSound(null, pos, state.getSoundType().getPlaceSound(), SoundSource.BLOCKS, 1.0f, 0.5f); player.swing(InteractionHand.MAIN_HAND, true); + player.removeEffect(MobEffects.SLOWNESS); return true; } @@ -180,6 +184,7 @@ public class PlacementHandler CarryOnDataManager.setCarryData(player, carry); otherPlayer.teleportTo(placementPos.x, placementPos.y, placementPos.z); player.swing(InteractionHand.MAIN_HAND, true); + player.removeEffect(MobEffects.SLOWNESS); return true; } @@ -204,6 +209,7 @@ public class PlacementHandler player.swing(InteractionHand.MAIN_HAND, true); carry.clear(); CarryOnDataManager.setCarryData(player, carry); + player.removeEffect(MobEffects.SLOWNESS); return true; } @@ -271,6 +277,7 @@ public class PlacementHandler carry.clear(); CarryOnDataManager.setCarryData(player, carry); level.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.HORSE_SADDLE, SoundSource.PLAYERS, 0.5F, 1.5F); + player.removeEffect(MobEffects.SLOWNESS); } else { level.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.LAVA_POP, SoundSource.PLAYERS, 0.5F, 0.5F); } @@ -314,6 +321,7 @@ public class PlacementHandler } carry.clear(); CarryOnDataManager.setCarryData(player, carry); + player.removeEffect(MobEffects.SLOWNESS); } private static BlockPos getDeathPlacementPos(BlockState state, ServerPlayer player) diff --git a/Common/src/main/java/tschipp/carryon/mixin/HumanoidModelMixin.java b/Common/src/main/java/tschipp/carryon/mixin/HumanoidModelMixin.java index 2eceb68..0a9074c 100644 --- a/Common/src/main/java/tschipp/carryon/mixin/HumanoidModelMixin.java +++ b/Common/src/main/java/tschipp/carryon/mixin/HumanoidModelMixin.java @@ -51,7 +51,7 @@ public class HumanoidModelMixin { if(state instanceof ICarryOnRenderState carryOnRenderState && Constants.CLIENT_CONFIG.renderArms) { CarryOnData carry = carryOnRenderState.getCarryOnData(); - if(carry.isCarrying() && !state.isVisuallySwimming && !state.isFallFlying) + if(carry != null && carry.isCarrying() && !state.isVisuallySwimming && !state.isFallFlying) { boolean sneaking = state.isCrouching;