diff --git a/src/main/java/com/yipkei/vanilladdition/mixin/ExampleMixin.java b/src/main/java/com/yipkei/vanilladdition/mixin/ExampleMixin.java deleted file mode 100644 index 818e142..0000000 --- a/src/main/java/com/yipkei/vanilladdition/mixin/ExampleMixin.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.yipkei.vanilladdition.mixin; - -import net.minecraft.server.MinecraftServer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(MinecraftServer.class) -public class ExampleMixin { - @Inject(at = @At("HEAD"), method = "loadWorld") - private void init(CallbackInfo info) { - // This code is injected into the start of MinecraftServer.loadWorld()V - } -} \ No newline at end of file diff --git a/src/main/java/com/yipkei/vanilladdition/mixin/ItemMixin.java b/src/main/java/com/yipkei/vanilladdition/mixin/ItemMixin.java deleted file mode 100644 index e17424c..0000000 --- a/src/main/java/com/yipkei/vanilladdition/mixin/ItemMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.yipkei.vanilladdition.mixin; - -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(Item.class) -public abstract class ItemMixin implements ItemSettingModifier{ - - @Shadow public abstract ItemStack getDefaultStack(); - - @Override - public ItemStack getDestroyedStack(int damage){ - ItemStack stack = this.getDefaultStack(); - //stack.damage(damage); - return stack; - } -} diff --git a/src/main/java/com/yipkei/vanilladdition/mixin/ItemSettingModifier.java b/src/main/java/com/yipkei/vanilladdition/mixin/ItemSettingModifier.java deleted file mode 100644 index 1bdcf7c..0000000 --- a/src/main/java/com/yipkei/vanilladdition/mixin/ItemSettingModifier.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.yipkei.vanilladdition.mixin; - -import net.minecraft.item.ItemStack; - -public interface ItemSettingModifier { - public ItemStack getDestroyedStack(int damage); - -} diff --git a/src/main/java/com/yipkei/vanilladdition/mixin/MooshroomEntityMixin.java b/src/main/java/com/yipkei/vanilladdition/mixin/MooshroomEntityMixin.java index ab7ca9f..4f76d5a 100644 --- a/src/main/java/com/yipkei/vanilladdition/mixin/MooshroomEntityMixin.java +++ b/src/main/java/com/yipkei/vanilladdition/mixin/MooshroomEntityMixin.java @@ -1,30 +1,22 @@ package com.yipkei.vanilladdition.mixin; import com.yipkei.vanilladdition.util.ModTags; -import net.minecraft.component.DataComponentTypes; -import net.minecraft.component.type.SuspiciousStewEffectsComponent; import net.minecraft.entity.EntityType; import net.minecraft.entity.Shearable; import net.minecraft.entity.passive.CowEntity; import net.minecraft.entity.passive.MooshroomEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemUsage; -import net.minecraft.item.Items; -import net.minecraft.particle.ParticleTypes; -import net.minecraft.registry.tag.ItemTags; import net.minecraft.sound.SoundCategory; -import net.minecraft.sound.SoundEvent; -import net.minecraft.sound.SoundEvents; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.world.World; import net.minecraft.world.event.GameEvent; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; - -import java.util.Optional; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Deprecated @Mixin(MooshroomEntity.class) @@ -34,74 +26,87 @@ public MooshroomEntityMixin(EntityType entityType, World wo super(entityType, world); } - @Shadow private SuspiciousStewEffectsComponent stewEffects; + @Shadow + public abstract boolean isShearable(); - @Shadow public abstract MooshroomEntity.Type getVariant(); + @Shadow public abstract void sheared(SoundCategory shearedSoundCategory); - @Shadow protected abstract Optional getStewEffectFrom(ItemStack flower) ; - /** - * @author YipKei - * @reason The original method cannot accept custom Shears. - */ - @Overwrite - public ActionResult interactMob(PlayerEntity player, Hand hand) { + @Inject(method = "interactMob", at = @At("HEAD"), cancellable = true) + private void checkSteelShears(PlayerEntity player, Hand hand, CallbackInfoReturnable ci){ ItemStack itemStack = player.getStackInHand(hand); - if (itemStack.isOf(Items.BOWL) && !this.isBaby()) { - boolean bl = false; - ItemStack itemStack2; - if (this.stewEffects != null) { - bl = true; - itemStack2 = new ItemStack(Items.SUSPICIOUS_STEW); - itemStack2.set(DataComponentTypes.SUSPICIOUS_STEW_EFFECTS, this.stewEffects); - this.stewEffects = null; - } else { - itemStack2 = new ItemStack(Items.MUSHROOM_STEW); - } - - ItemStack itemStack3 = ItemUsage.exchangeStack(itemStack, player, itemStack2, false); - player.setStackInHand(hand, itemStack3); - SoundEvent soundEvent; - if (bl) { - soundEvent = SoundEvents.ENTITY_MOOSHROOM_SUSPICIOUS_MILK; - } else { - soundEvent = SoundEvents.ENTITY_MOOSHROOM_MILK; - } - - this.playSound(soundEvent, 1.0F, 1.0F); - return ActionResult.success(this.getWorld().isClient); - } else if (itemStack.isIn(ModTags.Items.SHEARS) && this.isShearable()) { + if (itemStack.isIn(ModTags.Items.SHEARS) && this.isShearable()){ this.sheared(SoundCategory.PLAYERS); this.emitGameEvent(GameEvent.SHEAR, player); if (!this.getWorld().isClient) { itemStack.damage(1, player, getSlotForHand(hand)); } - - return ActionResult.success(this.getWorld().isClient); - } else if (this.getVariant() == MooshroomEntity.Type.BROWN && itemStack.isIn(ItemTags.SMALL_FLOWERS)) { - if (this.stewEffects != null) { - for(int i = 0; i < 2; ++i) { - this.getWorld().addParticle(ParticleTypes.SMOKE, this.getX() + this.random.nextDouble() / 2.0, this.getBodyY(0.5), this.getZ() + this.random.nextDouble() / 2.0, 0.0, this.random.nextDouble() / 5.0, 0.0); - } - } else { - Optional optional = this.getStewEffectFrom(itemStack); - if (optional.isEmpty()) { - return ActionResult.PASS; - } - - itemStack.decrementUnlessCreative(1, player); - - for(int j = 0; j < 4; ++j) { - this.getWorld().addParticle(ParticleTypes.EFFECT, this.getX() + this.random.nextDouble() / 2.0, this.getBodyY(0.5), this.getZ() + this.random.nextDouble() / 2.0, 0.0, this.random.nextDouble() / 5.0, 0.0); - } - - this.stewEffects = (SuspiciousStewEffectsComponent)optional.get(); - this.playSound(SoundEvents.ENTITY_MOOSHROOM_EAT, 2.0F, 1.0F); - } - - return ActionResult.success(this.getWorld().isClient); - } else { - return super.interactMob(player, hand); + ci.setReturnValue(ActionResult.success(this.getWorld().isClient)); } } + +// /** +// * @author YipKei +// * @reason The original method cannot accept custom Shears. +// */ +// @Overwrite +// public ActionResult interactMob(PlayerEntity player, Hand hand) { +// ItemStack itemStack = player.getStackInHand(hand); +// if (itemStack.isOf(Items.BOWL) && !this.isBaby()) { +// boolean bl = false; +// ItemStack itemStack2; +// if (this.stewEffects != null) { +// bl = true; +// itemStack2 = new ItemStack(Items.SUSPICIOUS_STEW); +// itemStack2.set(DataComponentTypes.SUSPICIOUS_STEW_EFFECTS, this.stewEffects); +// this.stewEffects = null; +// } else { +// itemStack2 = new ItemStack(Items.MUSHROOM_STEW); +// } +// +// ItemStack itemStack3 = ItemUsage.exchangeStack(itemStack, player, itemStack2, false); +// player.setStackInHand(hand, itemStack3); +// SoundEvent soundEvent; +// if (bl) { +// soundEvent = SoundEvents.ENTITY_MOOSHROOM_SUSPICIOUS_MILK; +// } else { +// soundEvent = SoundEvents.ENTITY_MOOSHROOM_MILK; +// } +// +// this.playSound(soundEvent, 1.0F, 1.0F); +// return ActionResult.success(this.getWorld().isClient); +// } else if (itemStack.isIn(ModTags.Items.SHEARS) && this.isShearable()) { +// this.sheared(SoundCategory.PLAYERS); +// this.emitGameEvent(GameEvent.SHEAR, player); +// if (!this.getWorld().isClient) { +// itemStack.damage(1, player, getSlotForHand(hand)); +// } +// +// return ActionResult.success(this.getWorld().isClient); +// } else if (this.getVariant() == MooshroomEntity.Type.BROWN && itemStack.isIn(ItemTags.SMALL_FLOWERS)) { +// if (this.stewEffects != null) { +// for(int i = 0; i < 2; ++i) { +// this.getWorld().addParticle(ParticleTypes.SMOKE, this.getX() + this.random.nextDouble() / 2.0, this.getBodyY(0.5), this.getZ() + this.random.nextDouble() / 2.0, 0.0, this.random.nextDouble() / 5.0, 0.0); +// } +// } else { +// Optional optional = this.getStewEffectFrom(itemStack); +// if (optional.isEmpty()) { +// return ActionResult.PASS; +// } +// +// itemStack.decrementUnlessCreative(1, player); +// +// for(int j = 0; j < 4; ++j) { +// this.getWorld().addParticle(ParticleTypes.EFFECT, this.getX() + this.random.nextDouble() / 2.0, this.getBodyY(0.5), this.getZ() + this.random.nextDouble() / 2.0, 0.0, this.random.nextDouble() / 5.0, 0.0); +// } +// +// this.stewEffects = (SuspiciousStewEffectsComponent)optional.get(); +// this.playSound(SoundEvents.ENTITY_MOOSHROOM_EAT, 2.0F, 1.0F); +// } +// +// return ActionResult.success(this.getWorld().isClient); +// } else { +// return super.interactMob(player, hand); +// } +// } } diff --git a/src/main/java/com/yipkei/vanilladdition/mixin/PumpkinBlockMixin.java b/src/main/java/com/yipkei/vanilladdition/mixin/PumpkinBlockMixin.java index 1c6f948..5ff7c67 100644 --- a/src/main/java/com/yipkei/vanilladdition/mixin/PumpkinBlockMixin.java +++ b/src/main/java/com/yipkei/vanilladdition/mixin/PumpkinBlockMixin.java @@ -18,7 +18,9 @@ import net.minecraft.world.World; import net.minecraft.world.event.GameEvent; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(PumpkinBlock.class) public abstract class PumpkinBlockMixin extends Block { @@ -26,28 +28,48 @@ public PumpkinBlockMixin(Settings settings) { super(settings); } - /** - * @author YipKei - * @reason The original method cannot accept custom Shears. - */ - @Overwrite - public ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - if (!stack.isIn(ModTags.Items.SHEARS)) { - return super.onUseWithItem(stack, state, world, pos, player, hand, hit); + @Inject(method = "onUseWithItem",at = @At("HEAD"), cancellable = true) + private void checkSteelShears(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable ci){ + if (stack.isIn(ModTags.Items.SHEARS)){ + if (world.isClient){ + ci.setReturnValue(ItemActionResult.success(world.isClient)); + } + Direction direction = hit.getSide(); + Direction direction2 = direction.getAxis() == Direction.Axis.Y ? player.getHorizontalFacing().getOpposite() : direction; + world.playSound(null, pos, SoundEvents.BLOCK_PUMPKIN_CARVE, SoundCategory.BLOCKS, 1.0f, 1.0f); + world.setBlockState(pos, Blocks.CARVED_PUMPKIN.getDefaultState().with(CarvedPumpkinBlock.FACING, direction2), Block.NOTIFY_ALL_AND_REDRAW); + ItemEntity itemEntity = new ItemEntity(world, (double)pos.getX() + 0.5 + (double)direction2.getOffsetX() * 0.65, (double)pos.getY() + 0.1, (double)pos.getZ() + 0.5 + (double)direction2.getOffsetZ() * 0.65, new ItemStack(Items.PUMPKIN_SEEDS, 4)); + itemEntity.setVelocity(0.05 * (double)direction2.getOffsetX() + world.random.nextDouble() * 0.02, 0.05, 0.05 * (double)direction2.getOffsetZ() + world.random.nextDouble() * 0.02); + world.spawnEntity(itemEntity); + stack.damage(1, player, LivingEntity.getSlotForHand(hand)); + world.emitGameEvent(player, GameEvent.SHEAR, pos); + player.incrementStat(Stats.USED.getOrCreateStat(Items.SHEARS)); + ci.setReturnValue(ItemActionResult.success(world.isClient)); } - if (world.isClient) { - return ItemActionResult.success(world.isClient); - } - Direction direction = hit.getSide(); - Direction direction2 = direction.getAxis() == Direction.Axis.Y ? player.getHorizontalFacing().getOpposite() : direction; - world.playSound(null, pos, SoundEvents.BLOCK_PUMPKIN_CARVE, SoundCategory.BLOCKS, 1.0f, 1.0f); - world.setBlockState(pos, Blocks.CARVED_PUMPKIN.getDefaultState().with(CarvedPumpkinBlock.FACING, direction2), Block.NOTIFY_ALL_AND_REDRAW); - ItemEntity itemEntity = new ItemEntity(world, (double)pos.getX() + 0.5 + (double)direction2.getOffsetX() * 0.65, (double)pos.getY() + 0.1, (double)pos.getZ() + 0.5 + (double)direction2.getOffsetZ() * 0.65, new ItemStack(Items.PUMPKIN_SEEDS, 4)); - itemEntity.setVelocity(0.05 * (double)direction2.getOffsetX() + world.random.nextDouble() * 0.02, 0.05, 0.05 * (double)direction2.getOffsetZ() + world.random.nextDouble() * 0.02); - world.spawnEntity(itemEntity); - stack.damage(1, player, LivingEntity.getSlotForHand(hand)); - world.emitGameEvent(player, GameEvent.SHEAR, pos); - player.incrementStat(Stats.USED.getOrCreateStat(Items.SHEARS)); - return ItemActionResult.success(world.isClient); } + +// /** +// * @author YipKei +// * @reason The original method cannot accept custom Shears. +// */ +// @Overwrite +// public ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { +// if (!stack.isIn(ModTags.Items.SHEARS)) { +// return super.onUseWithItem(stack, state, world, pos, player, hand, hit); +// } +// if (world.isClient) { +// return ItemActionResult.success(world.isClient); +// } +// Direction direction = hit.getSide(); +// Direction direction2 = direction.getAxis() == Direction.Axis.Y ? player.getHorizontalFacing().getOpposite() : direction; +// world.playSound(null, pos, SoundEvents.BLOCK_PUMPKIN_CARVE, SoundCategory.BLOCKS, 1.0f, 1.0f); +// world.setBlockState(pos, Blocks.CARVED_PUMPKIN.getDefaultState().with(CarvedPumpkinBlock.FACING, direction2), Block.NOTIFY_ALL_AND_REDRAW); +// ItemEntity itemEntity = new ItemEntity(world, (double)pos.getX() + 0.5 + (double)direction2.getOffsetX() * 0.65, (double)pos.getY() + 0.1, (double)pos.getZ() + 0.5 + (double)direction2.getOffsetZ() * 0.65, new ItemStack(Items.PUMPKIN_SEEDS, 4)); +// itemEntity.setVelocity(0.05 * (double)direction2.getOffsetX() + world.random.nextDouble() * 0.02, 0.05, 0.05 * (double)direction2.getOffsetZ() + world.random.nextDouble() * 0.02); +// world.spawnEntity(itemEntity); +// stack.damage(1, player, LivingEntity.getSlotForHand(hand)); +// world.emitGameEvent(player, GameEvent.SHEAR, pos); +// player.incrementStat(Stats.USED.getOrCreateStat(Items.SHEARS)); +// return ItemActionResult.success(world.isClient); +// } } diff --git a/src/main/java/com/yipkei/vanilladdition/mixin/SheepEntityMixin.java b/src/main/java/com/yipkei/vanilladdition/mixin/SheepEntityMixin.java index c4be550..944fffc 100644 --- a/src/main/java/com/yipkei/vanilladdition/mixin/SheepEntityMixin.java +++ b/src/main/java/com/yipkei/vanilladdition/mixin/SheepEntityMixin.java @@ -13,35 +13,56 @@ import net.minecraft.world.World; import net.minecraft.world.event.GameEvent; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(SheepEntity.class) public abstract class SheepEntityMixin extends AnimalEntity implements Shearable { + @Shadow public abstract boolean isShearable(); + + @Shadow public abstract void sheared(SoundCategory shearedSoundCategory); + protected SheepEntityMixin(EntityType entityType, World world) { super(entityType, world); } - /** - * @author YipKei - * @reason The original method cannot accept custom Shears. - */ - @Overwrite - public ActionResult interactMob(PlayerEntity player, Hand hand){ + + @Inject(method = "interactMob", at = @At( value = "HEAD" ), cancellable = true) + private void checkSteelShears(PlayerEntity player, Hand hand, CallbackInfoReturnable ci){ ItemStack itemStack = player.getStackInHand(hand); - if (itemStack.isIn(ModTags.Items.SHEARS)) { - if (!this.getWorld().isClient && this.isShearable()) { + if (itemStack.isIn(ModTags.Items.SHEARS)){ + if (!this.getWorld().isClient && this.isShearable()){ this.sheared(SoundCategory.PLAYERS); this.emitGameEvent(GameEvent.SHEAR, player); itemStack.damage(1, player, getSlotForHand(hand)); - return ActionResult.SUCCESS; - } else { - return ActionResult.CONSUME; + ci.setReturnValue(ActionResult.SUCCESS); } - } else { - return super.interactMob(player, hand); } } + +// /** +// * @author YipKei +// * @reason The original method cannot accept custom Shears. +// */ +// @Overwrite +// public ActionResult interactMob(PlayerEntity player, Hand hand){ +// ItemStack itemStack = player.getStackInHand(hand); +// if (itemStack.isIn(ModTags.Items.SHEARS)) { +// if (!this.getWorld().isClient && this.isShearable()) { +// this.sheared(SoundCategory.PLAYERS); +// this.emitGameEvent(GameEvent.SHEAR, player); +// itemStack.damage(1, player, getSlotForHand(hand)); +// return ActionResult.SUCCESS; +// } else { +// return ActionResult.CONSUME; +// } +// } else { +// return super.interactMob(player, hand); +// } +// } } diff --git a/src/main/resources/vanilla-addition.mixins.json b/src/main/resources/vanilla-addition.mixins.json index 9914dea..df8dbf4 100644 --- a/src/main/resources/vanilla-addition.mixins.json +++ b/src/main/resources/vanilla-addition.mixins.json @@ -4,7 +4,6 @@ "compatibilityLevel": "JAVA_21", "mixins": [ "EnderDragonFightMixin", - "ExampleMixin", "PumpkinBlockMixin", "SheepEntityMixin", "SpawnHelperMixin"