Skip to content

Commit

Permalink
wip: 1.21.3 support
Browse files Browse the repository at this point in the history
waiting for BRRP update
  • Loading branch information
RubixDev committed Jan 8, 2025
1 parent ee39734 commit 2749cdc
Show file tree
Hide file tree
Showing 17 changed files with 241 additions and 107 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ preprocess {
def mc1204 = createNode('1.20.4' , 1_20_04, 'yarn')
def mc1206 = createNode('1.20.6' , 1_20_06, 'yarn')
def mc1211 = createNode('1.21.1' , 1_21_01, 'yarn')
def mc1213 = createNode('1.21.3' , 1_21_03, 'yarn')

mc1213.link(mc1211, null)
mc1211.link(mc1206, null)
mc1206.link(mc1204, file('versions/mapping-1.20.6-1.20.4.txt'))
mc1204.link(mc1202, file('versions/mapping-1.20.4-1.20.2.txt'))
Expand Down
3 changes: 2 additions & 1 deletion settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"1.20.2",
"1.20.4",
"1.20.6",
"1.21.1"
"1.21.1",
"1.21.3"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,28 @@

//#if MC >= 12006
import net.minecraft.item.ItemStack;
import net.minecraft.util.ItemActionResult;
//#endif

//#if MC >= 12006 && < 12103
//$$ import net.minecraft.util.ItemActionResult;
//#else
//$$ import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResult;
//#endif

@Mixin(AbstractCauldronBlock.class)
public class AbstractCauldronBlockMixin {
//#if MC >= 12006
@Inject(
//#if MC >= 12006
method = "onUseWithItem",
//#else
//$$ method = "onUse",
//#endif
at =
@At(
value = "INVOKE",
target = "Lnet/minecraft/item/ItemStack;getItem()Lnet/minecraft/item/Item;",
shift = At.Shift.AFTER),
cancellable = true)
//#else
//$$ @Inject(
//$$ method = "onUse",
//$$ at =
//$$ @At(
//$$ value = "INVOKE",
//$$ target = "Lnet/minecraft/item/ItemStack;getItem()Lnet/minecraft/item/Item;",
//$$ shift = At.Shift.AFTER),
//$$ cancellable = true)
//#endif
private void onOnUse(
//#if MC >= 12006
ItemStack stack,
Expand All @@ -54,10 +50,10 @@ private void onOnUse(
PlayerEntity player,
Hand hand,
BlockHitResult hit,
//#if MC >= 12006
CallbackInfoReturnable<ItemActionResult> cir
//#if MC >= 12006 && MC < 12103
//$$ CallbackInfoReturnable<ItemActionResult> cir
//#else
//$$ CallbackInfoReturnable<ActionResult> cir
CallbackInfoReturnable<ActionResult> cir
//#endif
) {
Item item = player.getStackInHand(hand).getItem();
Expand All @@ -71,10 +67,10 @@ private void onOnUse(
player.getStackInHand(hand).decrement(1);
}

//#if MC >= 12006
cir.setReturnValue(ItemActionResult.SUCCESS);
//#if MC >= 12006 && MC < 12103
//$$ cir.setReturnValue(ItemActionResult.SUCCESS);
//#else
//$$ cir.setReturnValue(ActionResult.SUCCESS);
cir.setReturnValue(ActionResult.SUCCESS);
//#endif
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,39 @@
import net.minecraft.item.Items;
import net.minecraft.recipe.AbstractCookingRecipe;
import net.minecraft.recipe.Ingredient;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
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(AbstractCookingRecipe.class)
public class AbstractCookingRecipeMixin {
@Shadow @Final protected ItemStack result;
//#if MC >= 12103
import net.minecraft.recipe.SingleStackRecipe;
//#else
//$$ import org.spongepowered.asm.mixin.Final;
//$$ import org.spongepowered.asm.mixin.Shadow;
//#endif

@Shadow @Final protected Ingredient ingredient;
//#if MC >= 12103
@Mixin(AbstractCookingRecipe.class)
public abstract class AbstractCookingRecipeMixin extends SingleStackRecipe {
public AbstractCookingRecipeMixin(String group, Ingredient ingredient, ItemStack result) {
super(group, ingredient, result);
}
//#else
//$$ @Mixin(AbstractCookingRecipe.class)
//$$ public class AbstractCookingRecipeMixin {
//$$ @Shadow @Final protected ItemStack result;
//$$
//$$ @Shadow @Final protected Ingredient ingredient;
//#endif

@Inject(method = "getExperience", at = @At("HEAD"), cancellable = true)
private void setCactusXp(CallbackInfoReturnable<Float> cir) {
if (this.result.isOf(Items.GREEN_DYE) && this.ingredient.test(Items.CACTUS.getDefaultStack())) {
//#if MC >= 12103
if (this.result().isOf(Items.GREEN_DYE) && this.ingredient().test(Items.CACTUS.getDefaultStack())) {
//#else
//$$ if (this.result.isOf(Items.GREEN_DYE) && this.ingredient.test(Items.CACTUS.getDefaultStack())) {
//#endif
cir.setReturnValue((float) RugSettings.cactusFurnaceXp);
}
}
Expand Down
29 changes: 16 additions & 13 deletions src/main/java/de/rubixdev/rug/mixins/BlockItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,20 @@ private void onPlace(
}
}

@Redirect(
method = "place(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/util/ActionResult;",
at =
@At(
value = "INVOKE",
target = "Lnet/minecraft/util/ActionResult;success(Z)Lnet/minecraft/util/ActionResult;"))
private ActionResult onPlace(boolean swingHand) {
if (isValidLilyPad) {
return ActionResult.success(true);
} else {
return ActionResult.success(swingHand);
}
}
// TODO: rewrite this entire mixin
//#if MC < 12103
//$$ @Redirect(
//$$ method = "place(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/util/ActionResult;",
//$$ at =
//$$ @At(
//$$ value = "INVOKE",
//$$ target = "Lnet/minecraft/util/ActionResult;success(Z)Lnet/minecraft/util/ActionResult;"))
//$$ private ActionResult onPlace(boolean swingHand) {
//$$ if (isValidLilyPad) {
//$$ return ActionResult.success(true);
//$$ } else {
//$$ return ActionResult.success(swingHand);
//$$ }
//$$ }
//#endif
}
2 changes: 1 addition & 1 deletion src/main/java/de/rubixdev/rug/mixins/BlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static void onDropStacks(
ItemStack stack,
CallbackInfo ci) {
//#if MC >= 12101
boolean usesSilkTouch = EnchantmentHelper.getLevel(world.getRegistryManager().getWrapperOrThrow(RegistryKeys.ENCHANTMENT).getOrThrow(Enchantments.SILK_TOUCH), stack) > 0;
boolean usesSilkTouch = EnchantmentHelper.getLevel(world.getRegistryManager().getOrThrow(RegistryKeys.ENCHANTMENT).getOrThrow(Enchantments.SILK_TOUCH), stack) > 0;
//#else
//$$ boolean usesSilkTouch = EnchantmentHelper.getLevel(Enchantments.SILK_TOUCH, stack) > 0;
//#endif
Expand Down
30 changes: 5 additions & 25 deletions src/main/java/de/rubixdev/rug/mixins/CreeperEntityMixin.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,17 @@
package de.rubixdev.rug.mixins;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import de.rubixdev.rug.RugSettings;
import net.minecraft.entity.Entity;
import net.minecraft.entity.mob.CreeperEntity;
import net.minecraft.world.World;
import net.minecraft.world.explosion.Explosion;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(CreeperEntity.class)
public class CreeperEntityMixin {
@Redirect(
method = "explode",
at =
@At(
value = "INVOKE",
target =
"Lnet/minecraft/world/World;createExplosion(Lnet/minecraft/entity/Entity;DDDFLnet/minecraft/world/World$ExplosionSourceType;)Lnet/minecraft/world/explosion/Explosion;"))
private Explosion noCreeperGriefing(
World instance,
Entity entity,
double x,
double y,
double z,
float power,
World.ExplosionSourceType explosionSourceType) {
return instance.createExplosion(
entity,
x,
y,
z,
power,
RugSettings.noCreeperGriefing ? World.ExplosionSourceType.NONE : explosionSourceType);
@ModifyExpressionValue(method = "explode", at = @At(value = "FIELD", target = "Lnet/minecraft/world/World$ExplosionSourceType;MOB:Lnet/minecraft/world/World$ExplosionSourceType;"))
private World.ExplosionSourceType noCreeperGriefing(World.ExplosionSourceType original) {
// TODO: test this
return RugSettings.noCreeperGriefing ? World.ExplosionSourceType.NONE : original;
}
}
34 changes: 27 additions & 7 deletions src/main/java/de/rubixdev/rug/mixins/EnderDragonEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

//#if MC >= 12103
import net.minecraft.server.world.ServerWorld;
//#endif

@Mixin(EnderDragonEntity.class)
public abstract class EnderDragonEntityMixin extends Entity {
public EnderDragonEntityMixin(EntityType<?> type, World world) {
Expand All @@ -31,19 +35,35 @@ public EnderDragonEntityMixin(EntityType<?> type, World world) {
ordinal = 1))
private void onUpdatePostDeath(CallbackInfo ci) {
String rugSetting = RugSettings.dragonDrops;
if (!rugSetting.equals("none") && this.getWorld().getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) {
//#if MC >= 12103
if (!rugSetting.equals("none") && this.getWorld() instanceof ServerWorld world && world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) {
boolean dropAll = rugSetting.equals("all");

if (rugSetting.contains("elytra") || dropAll) {
this.dropStack(new ItemStack(Items.ELYTRA));
if (dropAll || rugSetting.contains("elytra")) {
this.dropStack(world, new ItemStack(Items.ELYTRA));
}
if (rugSetting.contains("dragon_egg") || dropAll) {
this.dropStack(new ItemStack(Items.DRAGON_EGG));
if (dropAll || rugSetting.contains("dragon_egg")) {
this.dropStack(world, new ItemStack(Items.DRAGON_EGG));
}
if (rugSetting.contains("dragon_head") || dropAll) {
this.dropStack(new ItemStack(Items.DRAGON_HEAD));
if (dropAll || rugSetting.contains("dragon_head")) {
this.dropStack(world, new ItemStack(Items.DRAGON_HEAD));
}
}
//#else
//$$ if (!rugSetting.equals("none") && this.getWorld().getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) {
//$$ boolean dropAll = rugSetting.equals("all");
//$$
//$$ if (dropAll || rugSetting.contains("elytra")) {
//$$ this.dropStack(new ItemStack(Items.ELYTRA));
//$$ }
//$$ if (dropAll || rugSetting.contains("dragon_egg")) {
//$$ this.dropStack(new ItemStack(Items.DRAGON_EGG));
//$$ }
//$$ if (dropAll || rugSetting.contains("dragon_head")) {
//$$ this.dropStack(new ItemStack(Items.DRAGON_HEAD));
//$$ }
//$$ }
//#endif
}

@ModifyConstant(method = "updatePostDeath", constant = @Constant(intValue = 500))
Expand Down
39 changes: 35 additions & 4 deletions src/main/java/de/rubixdev/rug/mixins/LivingEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -19,12 +20,42 @@ public LivingEntityMixin(EntityType<?> type, World world) {
super(type, world);
}

@WrapOperation(method = "drop", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;dropLoot(Lnet/minecraft/entity/damage/DamageSource;Z)V"))
private void onDrop(LivingEntity instance, DamageSource damageSource, boolean causedByPlayer, Operation<Void> original) {
@WrapOperation(
method = "drop",
at = @At(
value = "INVOKE",
//#if MC >= 12103
target = "Lnet/minecraft/entity/LivingEntity;dropLoot(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/entity/damage/DamageSource;Z)V"
//#else
//$$ target = "Lnet/minecraft/entity/LivingEntity;dropLoot(Lnet/minecraft/entity/damage/DamageSource;Z)V"
//#endif
)
)
private void onDrop(
LivingEntity instance,
//#if MC >= 12103
ServerWorld world,
//#endif
DamageSource damageSource,
boolean causedByPlayer,
Operation<Void> original
) {
if (this.getType().equals(EntityType.SHULKER) && RugSettings.strictShulkerShells > 0) {
this.dropStack(new ItemStack(Items.SHULKER_SHELL, RugSettings.strictShulkerShells));
this.dropStack(
//#if MC >= 12103
world,
//#endif
new ItemStack(Items.SHULKER_SHELL, RugSettings.strictShulkerShells)
);
} else {
original.call(instance, damageSource, causedByPlayer);
original.call(
instance,
//#if MC >= 12103
world,
//#endif
damageSource,
causedByPlayer
);
}
}
}
Loading

0 comments on commit 2749cdc

Please sign in to comment.