Skip to content

Commit

Permalink
chore: update to 1.21.4-pre1
Browse files Browse the repository at this point in the history
- fixes CreakingData
- fixes unleashing injection point for the event
  • Loading branch information
gabizou committed Nov 22, 2024
1 parent 87d0ae6 commit 837b428
Show file tree
Hide file tree
Showing 9 changed files with 428 additions and 76 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mixinConfigs=mixins.sponge.accessors.json,mixins.sponge.api.json,mixins.sponge.c
mixins.sponge.tracker.json,mixins.sponge.ipforward.json,mixins.sponge.optimization.json
superClassChanges=common.superclasschange

minecraftVersion=24w46a
minecraftVersion=1.21.4-pre1
recommendedVersion=0-SNAPSHOT

org.gradle.dependency.verification.console=verbose
Expand Down
389 changes: 389 additions & 0 deletions gradle/verification-metadata.xml

Large diffs are not rendered by default.

This file was deleted.

1 change: 0 additions & 1 deletion src/accessors/resources/mixins.sponge.accessors.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
"world.entity.monster.VexAccessor",
"world.entity.monster.VindicatorAccessor",
"world.entity.monster.ZombifiedPiglinAccessor",
"world.entity.monster.creaking.CreakingAccessor",
"world.entity.npc.AbstractVillagerAccessor",
"world.entity.player.AbilitiesAccessor",
"world.entity.player.PlayerAccessor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import net.minecraft.world.entity.monster.creaking.Creaking;
import org.spongepowered.api.data.Keys;
import org.spongepowered.common.accessor.world.entity.monster.creaking.CreakingAccessor;
import org.spongepowered.common.data.provider.DataProviderRegistrator;
import org.spongepowered.common.util.VecHelper;

Expand All @@ -37,11 +36,11 @@ public static void register(final DataProviderRegistrator registrator) {
registrator
.asImmutable(Creaking.class)
.create(Keys.CREAKING_IS_LINKED)
.get(Creaking::isTransient);
.get(Creaking::isHeartBound);
registrator
.asMutable(Creaking.class)
.create(Keys.CREAKING_HOME_POSITION)
.get(h -> VecHelper.toVector3i(((CreakingAccessor) h).accessor$homePos()))
.get(h -> VecHelper.toVector3i(h.getHomePos()))
.set((h, v) -> h.setTransient(VecHelper.toBlockPos(v)));
;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ public static void register(final DataProviderRegistrator registrator) {
final var ld = h.getLeashData();
return ld == null ? null : (Entity) ld.leashHolder;
})
.delete(h -> {
h.dropLeash(true, false);
})
.delete(Leashable::dropLeash)
.set((h, v) -> {
if (v == null) {
// TODO remove
h.dropLeash(true, false);
h.dropLeash();
} else {
h.setLeashedTo((net.minecraft.world.entity.Entity) v, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.minecraft.world.item.component.CustomData;
import org.spongepowered.api.data.Keys;
import org.spongepowered.api.entity.EntityArchetype;
import org.spongepowered.common.SpongeCommon;
import org.spongepowered.common.data.provider.DataProviderRegistrator;
import org.spongepowered.common.entity.SpongeEntityArchetypeBuilder;

Expand All @@ -46,7 +47,7 @@ public static void register(final DataProviderRegistrator registrator) {
.get(stack -> {
final Item item = stack.getItem();
final SpawnEggItem eggItem = (SpawnEggItem) item;
final EntityType<?> type = eggItem.getType(stack);
final EntityType<?> type = eggItem.getType(SpongeCommon.vanillaRegistryAccess(), stack);
final var tag = stack.getOrDefault(DataComponents.ENTITY_DATA, CustomData.EMPTY).getUnsafe();

final EntityArchetype.Builder builder = EntityArchetype.builder().type((org.spongepowered.api.entity.EntityType<?>) type);
Expand All @@ -60,7 +61,7 @@ public static void register(final DataProviderRegistrator registrator) {
.get(stack -> {
final Item item = stack.getItem();
final SpawnEggItem eggItem = (SpawnEggItem) item;
return (org.spongepowered.api.entity.EntityType) eggItem.getType(stack);
return (org.spongepowered.api.entity.EntityType) eggItem.getType(SpongeCommon.vanillaRegistryAccess(), stack);
})
;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@
package org.spongepowered.common.mixin.core.world.entity;

import net.minecraft.world.entity.Leashable;
import org.checkerframework.checker.units.qual.A;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.living.Living;
import org.spongepowered.api.event.Cause;
import org.spongepowered.api.event.CauseStackManager;
import org.spongepowered.api.event.SpongeEventFactory;
import org.spongepowered.api.event.entity.UnleashEntityEvent;
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;
import org.spongepowered.common.SpongeCommon;
import org.spongepowered.common.event.tracking.PhaseTracker;

import java.util.Objects;

@Mixin(Leashable.class)
public interface LeashableMixin {
Expand All @@ -47,4 +55,27 @@ public interface LeashableMixin {
}
}

@Inject(method = "dropLeash(Lnet/minecraft/world/entity/Entity;ZZ)V", at = @At("HEAD"), cancellable = true)
private static void impl$onDropLeash(final net.minecraft.world.entity.Entity entity, final boolean $$1, final boolean $$2, final CallbackInfo ci) {
if (entity == null || entity.level().isClientSide) {
return;
}

Leashable.LeashData leashData = ((Leashable) (Object) entity).getLeashData();
if (leashData == null) {
return;
}

final net.minecraft.world.entity.Entity holder = leashData.leashHolder;

final CauseStackManager csm = PhaseTracker.getCauseStackManager();
csm.pushCause(Objects.requireNonNullElse(holder, entity));
final UnleashEntityEvent event = SpongeEventFactory.createUnleashEntityEvent(csm.currentCause(), (Entity) entity);
SpongeCommon.post(event);
csm.popCause();
if (event.isCancelled()) {
ci.cancel();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,34 +86,6 @@ public abstract class MobMixin extends LivingEntityMixin {
}
}

@Inject(method = "dropLeash", cancellable = true,
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Leashable;dropLeash(ZZ)V"))
private void impl$ThrowUnleashEvent(final boolean sendPacket, final boolean dropLead, final CallbackInfo ci) {
if (this.shadow$level().isClientSide) {
return;
}

var leashData = this.shadow$getLeashData();
if (leashData == null) {
return;
}

final net.minecraft.world.entity.Entity entity = leashData.leashHolder;

final CauseStackManager csm = PhaseTracker.getCauseStackManager();
if (entity == null) {
csm.pushCause(this);
} else {
csm.pushCause(entity);
}
final UnleashEntityEvent event = SpongeEventFactory.createUnleashEntityEvent(csm.currentCause(), (Living) this);
SpongeCommon.post(event);
csm.popCause();
if (event.isCancelled()) {
ci.cancel();
}
}

/**
* @author gabizou - January 4th, 2016
*
Expand Down

0 comments on commit 837b428

Please sign in to comment.