Skip to content

Commit

Permalink
Update to Minecraft 1.21.1 (#1450)
Browse files Browse the repository at this point in the history
  • Loading branch information
qyl27 authored Aug 11, 2024
1 parent ee68f94 commit 1a22cd0
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.item.ArrowItem;
import net.minecraft.world.item.BowItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -19,7 +16,7 @@ public interface ItemBridge {
return charge;
}

default AbstractArrow bridge$forge$customArrow(BowItem bowItem, ItemStack itemStack, AbstractArrow arrow) {
default AbstractArrow bridge$forge$customArrow(BowItem bowItem, ItemStack weapon, ItemStack projectile, AbstractArrow arrow) {
return arrow;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class EntityArgumentMixin implements EntityArgumentBridge {

public EntitySelector parse(StringReader reader, boolean overridePermissions) throws CommandSyntaxException {
int i = 0;
EntitySelectorParser entityselectorparser = new EntitySelectorParser(reader);
EntitySelectorParser entityselectorparser = new EntitySelectorParser(reader, true);
EntitySelector entityselector = ((EntitySelectorParserBridge) entityselectorparser).bridge$parse(overridePermissions);
if (entityselector.getMaxResults() > 1 && this.single) {
if (this.playersOnly) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.bukkit.craftbukkit.v.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v.inventory.CraftItemStack;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.inventory.view.AnvilView;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -44,7 +45,7 @@ public abstract class AnvilMenuMixin extends ItemCombinerMixin implements AnvilM

@Decorate(method = "createResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/ResultContainer;setItem(ILnet/minecraft/world/item/ItemStack;)V"))
private void arclight$prepareAnvilEvent(ResultContainer instance, int i, ItemStack itemStack) throws Throwable {
var event = new PrepareAnvilEvent(getBukkitView(), CraftItemStack.asCraftMirror(itemStack).clone());
var event = new PrepareAnvilEvent((AnvilView) getBukkitView(), CraftItemStack.asCraftMirror(itemStack).clone());
Bukkit.getServer().getPluginManager().callEvent(event);
DecorationOps.callsite().invoke(instance, i, CraftItemStack.asNMSCopy(event.getResult()));
}
Expand All @@ -71,7 +72,7 @@ public CraftInventoryView getBukkitView() {
}

CraftInventory inventory = new CraftInventoryAnvil(
((IWorldPosCallableBridge) this.access).bridge$getLocation(), this.inputSlots, this.resultSlots, (AnvilMenu) (Object) this);
((IWorldPosCallableBridge) this.access).bridge$getLocation(), this.inputSlots, this.resultSlots);
bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this);
return bukkitEntity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
import org.bukkit.inventory.view.EnchantmentView;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -96,7 +97,7 @@ public abstract class EnchantmentContainerMixin extends AbstractContainerMenuMix
offers[j] = (enchantment != null) ? new EnchantmentOffer(enchantment, this.levelClue[j], this.costs[j]) : null;
}

PrepareItemEnchantEvent event = new PrepareItemEnchantEvent(((ServerPlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), this.getBukkitView(), ((IWorldPosCallableBridge) this.access).bridge$getLocation().getBlock(), item, offers, arclight$power);
PrepareItemEnchantEvent event = new PrepareItemEnchantEvent(((ServerPlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), (EnchantmentView) this.getBukkitView(), ((IWorldPosCallableBridge) this.access).bridge$getLocation().getBlock(), item, offers, arclight$power);
event.setCancelled(!arclight$enchantable);
Bukkit.getPluginManager().callEvent(event);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public class CustomRecipeMixin implements RecipeBridge {

@Override
public Recipe bridge$toBukkitRecipe(NamespacedKey id) {
return new org.bukkit.craftbukkit.v.inventory.CraftComplexRecipe(id, (CustomRecipe) (Object) this);
return new org.bukkit.craftbukkit.v.inventory.CraftComplexRecipe(id, null, (CustomRecipe) (Object) this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.izzel.arclight.common.mod.server.ArclightServer;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.RecipeInput;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.v.inventory.CraftComplexRecipe;
import org.bukkit.craftbukkit.v.inventory.CraftItemStack;
Expand All @@ -16,7 +17,7 @@ public class ArclightSpecialRecipe extends CraftComplexRecipe {
private final Recipe<?> recipe;

public ArclightSpecialRecipe(NamespacedKey id, Recipe<?> recipe) {
super(id, null);
super(id, null, null);
this.recipe = recipe;
}

Expand Down
26 changes: 26 additions & 0 deletions arclight-common/src/main/resources/arclight.accesswidener
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
accessWidener v2 named
# Arclight 1.21.1
mutable field net/minecraft/world/level/block/entity/trialspawner/TrialSpawner targetCooldownLength I
mutable field net/minecraft/world/level/block/entity/trialspawner/TrialSpawner normalConfig Lnet/minecraft/world/level/block/entity/trialspawner/TrialSpawnerConfig;
mutable field net/minecraft/world/level/block/entity/trialspawner/TrialSpawner requiredPlayerRange I
mutable field net/minecraft/world/level/block/entity/trialspawner/TrialSpawner ominousConfig Lnet/minecraft/world/level/block/entity/trialspawner/TrialSpawnerConfig;
accessible class net/minecraft/world/level/biome/Biome$ClimateSettings
accessible class net/minecraft/world/item/crafting/Ingredient$ItemValue
accessible field net/minecraft/world/level/biome/Biome climateSettings Lnet/minecraft/world/level/biome/Biome$ClimateSettings;
accessible class net/minecraft/world/entity/monster/Guardian$GuardianAttackGoal
accessible class net/minecraft/world/entity/Interaction$PlayerAction
accessible class net/minecraft/world/item/ItemCooldowns$CooldownInstance
accessible field net/minecraft/network/protocol/handshake/ClientIntentionPacket hostName Ljava/lang/String;
mutable field net/minecraft/network/protocol/handshake/ClientIntentionPacket hostName Ljava/lang/String;
accessible field net/minecraft/network/protocol/handshake/ClientIntentionPacket port I
accessible class net/minecraft/server/level/ServerPlayer$RespawnPosAngle
accessible class net/minecraft/world/level/block/ComposterBlock$InputContainer
accessible class net/minecraft/world/entity/projectile/FishingHook$FishHookState
accessible class net/minecraft/world/item/crafting/Ingredient$Value
accessible class net/minecraft/world/level/block/ComposterBlock$OutputContainer
accessible method net/minecraft/world/damagesource/DamageSource <init> (Lnet/minecraft/core/Holder;Lnet/minecraft/world/entity/Entity;)V
accessible class net/minecraft/server/level/ChunkMap$TrackedEntity
accessible class net/minecraft/server/MinecraftServer$ReloadableResources
accessible class net/minecraft/world/level/block/ComposterBlock$EmptyContainer
accessible class net/minecraft/world/entity/monster/SpellcasterIllager$IllagerSpell
mutable field net/minecraft/world/level/block/entity/BeehiveBlockEntity stored Ljava/util/List;
accessible class net/minecraft/server/dedicated/DedicatedServerProperties$WorldDimensionData
# Arclight 1.21
accessible field net/minecraft/core/component/DataComponentPatch map Lit/unimi/dsi/fastutil/objects/Reference2ObjectMap;
accessible field net/minecraft/core/component/DataComponentPatch$Builder map Lit/unimi/dsi/fastutil/objects/Reference2ObjectMap;
Expand Down
1 change: 1 addition & 0 deletions arclight-forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ loom {
accessWidenerPath = project(":arclight-common").loom.accessWidenerPath

forge {
useCustomMixin = false
convertAccessWideners = true
extraAccessWideners.add loom.accessWidenerPath.get().asFile.name
mixinConfig "mixins.arclight.forge.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class ItemMixin_Forge implements ItemBridge {

@Override
public AbstractArrow bridge$forge$customArrow(BowItem bowItem, ItemStack itemStack, AbstractArrow arrow) {
public AbstractArrow bridge$forge$customArrow(BowItem bowItem, ItemStack weapon, ItemStack projectile, AbstractArrow arrow) {
return bowItem.customArrow(arrow);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.neoforged.neoforge.common.CommonHooks;
import net.neoforged.neoforge.common.damagesource.DamageContainer;
import net.neoforged.neoforge.event.EventHooks;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -37,7 +38,7 @@ public abstract class LivingEntityMixin_NeoForge extends EntityMixin_NeoForge im

@Inject(method = "hurt", cancellable = true, at = @At("HEAD"))
private void arclight$livingHurt(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
if (!CommonHooks.onLivingAttack((LivingEntity) (Object) this, source, amount)) {
if (!CommonHooks.onEntityIncomingDamage((LivingEntity) (Object) this, new DamageContainer(source, amount))) {
cir.setReturnValue(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.neoforged.neoforge.common.CommonHooks;
import net.neoforged.neoforge.common.damagesource.DamageContainer;
import net.neoforged.neoforge.common.extensions.IPlayerExtension;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -28,7 +29,7 @@ public abstract class PlayerMixin_NeoForge extends LivingEntityMixin_NeoForge im

@Inject(method = "hurt", cancellable = true, at = @At("HEAD"))
private void arclight$onPlayerAttack(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
if (!CommonHooks.onPlayerAttack((Player) (Object) this, source, amount)) {
if (!CommonHooks.onEntityIncomingDamage((Player) (Object) this, new DamageContainer(source, amount))) {
cir.setReturnValue(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
public abstract class ItemMixin_NeoForge implements ItemBridge {

@Override
public AbstractArrow bridge$forge$customArrow(BowItem bowItem, ItemStack itemStack, AbstractArrow arrow) {
return bowItem.customArrow(arrow, itemStack);
public AbstractArrow bridge$forge$customArrow(BowItem bowItem, ItemStack weapon, ItemStack projectile, AbstractArrow arrow) {
return bowItem.customArrow(arrow, projectile, weapon);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public abstract class ItemEntityMixin_ActivationRange_NeoForge extends EntityMix
@Override
public void bridge$forge$optimization$discardItemEntity() {
if (!this.level().isClientSide && this.age >= this.lifespan) {
int hook = EventHooks.onItemExpire((ItemEntity) (Object) this, this.getItem());
int hook = EventHooks.onItemExpire((ItemEntity) (Object) this);
if (hook < 0) this.discard();
else this.lifespan += hook;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class ItemEntityEventDispatcher {

@SubscribeEvent(receiveCanceled = true)
public void onExpire(ItemExpireEvent event) {
event.setCanceled(CraftEventFactory.callItemDespawnEvent(event.getEntity()).isCancelled());
if (CraftEventFactory.callItemDespawnEvent(event.getEntity()).isCancelled()) {
event.setExtraLife(1);
}
}
}
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ allprojects {
}

ext {
minecraftVersion = '1.21'
minecraftVersion = '1.21.1'
supportedPlatforms = ['forge', 'neoforge', 'fabric']
fabricLoaderVersion = '0.15.11'
fabricApiVersion = '0.100.1+1.21'
forgeVersion = '51.0.5'
neoForgeVersion = '21.0.4-beta'
fabricLoaderVersion = '0.16.0'
fabricApiVersion = '0.102.0+1.21.1'
forgeVersion = '52.0.1'
neoForgeVersion = '21.1.2'
apiVersion = '1.7.3'
toolsVersion = '1.3.0'
mixinVersion = '0.8.5'
Expand Down

0 comments on commit 1a22cd0

Please sign in to comment.