Skip to content

Commit

Permalink
Fix end gateway teleport crash (#1298)
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Mar 31, 2024
1 parent e47fe80 commit 75700e2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.izzel.arclight.common.bridge.core.tileentity;

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;

public interface EndGatewayBlockEntityBridge {

void bridge$playerTeleportEvent(Level level, BlockPos pos, BlockState state, Entity entityIn, BlockPos dest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.izzel.arclight.api.ArclightPlatform;
import io.izzel.arclight.common.bridge.core.entity.player.ServerPlayerEntityBridge;
import io.izzel.arclight.common.bridge.core.network.play.ServerPlayNetHandlerBridge;
import io.izzel.arclight.common.bridge.core.tileentity.EndGatewayBlockEntityBridge;
import io.izzel.arclight.common.mod.mixins.annotation.OnlyInPlatform;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
Expand All @@ -24,28 +25,19 @@
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(TheEndGatewayBlockEntity.class)
@OnlyInPlatform({ArclightPlatform.FORGE, ArclightPlatform.NEOFORGE})
public abstract class EndGatewayBlockEntityMixin extends BlockEntityMixin {
public abstract class EndGatewayBlockEntityMixin extends BlockEntityMixin implements EndGatewayBlockEntityBridge {

// @formatter:off
@Shadow private static void triggerCooldown(Level p_155850_, BlockPos p_155851_, BlockState p_155852_, TheEndGatewayBlockEntity p_155853_) { }
// @formatter:on

@Inject(method = "teleportEntity", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setPortalCooldown()V"))
private static void arclight$portal(Level level, BlockPos pos, BlockState state, Entity entityIn, TheEndGatewayBlockEntity entity, CallbackInfo ci,
ServerLevel serverLevel, BlockPos dest) {
if (entityIn instanceof ServerPlayer) {
arclight$playerTeleport(level, pos, state, entityIn, entity, dest);
ci.cancel();
}
}

@Inject(method = "teleportEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setPortalCooldown()V"))
private static void arclight$teleportCause(Level level, BlockPos pos, BlockState state, Entity entityIn, TheEndGatewayBlockEntity entity, CallbackInfo ci) {
entityIn.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.HIT);
}

private static void arclight$playerTeleport(Level level, BlockPos pos, BlockState state, Entity entityIn, TheEndGatewayBlockEntity entity, BlockPos dest) {
@Override
public void bridge$playerTeleportEvent(Level level, BlockPos pos, BlockState state, Entity entityIn, BlockPos dest) {
CraftPlayer player = ((ServerPlayerEntityBridge) entityIn).bridge$getBukkitEntity();
Location location = new Location(level.bridge$getWorld(), dest.getX() + 0.5D, dest.getY() + 0.5D, dest.getZ() + 0.5D);
location.setPitch(player.getLocation().getPitch());
Expand All @@ -59,7 +51,7 @@ public abstract class EndGatewayBlockEntityMixin extends BlockEntityMixin {

entityIn.setPortalCooldown();
((ServerPlayNetHandlerBridge) (((ServerPlayer) entityIn)).connection).bridge$teleport(event.getTo());
triggerCooldown(level, pos, state, entity);
triggerCooldown(level, pos, state, (TheEndGatewayBlockEntity) (Object) this);
}

@Mixin(TheEndGatewayBlockEntity.class)
Expand All @@ -70,14 +62,23 @@ public static class VanillaLike {
private static void arclight$portal(Level level, BlockPos pos, BlockState state, Entity entityIn, TheEndGatewayBlockEntity entity, CallbackInfo ci,
BlockPos dest) {
if (entityIn instanceof ServerPlayer) {
arclight$playerTeleport(level, pos, state, entityIn, entity, dest);
((EndGatewayBlockEntityBridge) entity).bridge$playerTeleportEvent(level, pos, state, entityIn, dest);
ci.cancel();
}
}
}

@Mixin(TheEndGatewayBlockEntity.class)
@OnlyInPlatform({ArclightPlatform.FORGE, ArclightPlatform.NEOFORGE})
public static class ForgeLike {

@Inject(method = "teleportEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setPortalCooldown()V"))
private static void arclight$teleportCause(Level level, BlockPos pos, BlockState state, Entity entityIn, TheEndGatewayBlockEntity entity, CallbackInfo ci) {
entityIn.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.HIT);
@Inject(method = "teleportEntity", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setPortalCooldown()V"))
private static void arclight$portal(Level level, BlockPos pos, BlockState state, Entity entityIn, TheEndGatewayBlockEntity entity, CallbackInfo ci,
ServerLevel serverLevel, BlockPos dest) {
if (entityIn instanceof ServerPlayer) {
((EndGatewayBlockEntityBridge) entity).bridge$playerTeleportEvent(level, pos, state, entityIn, dest);
ci.cancel();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@
"world.level.block.entity.DecoratedPotBlockEntityMixin",
"world.level.block.entity.DispenserBlockEntityMixin",
"world.level.block.entity.EndGatewayBlockEntityMixin",
"world.level.block.entity.EndGatewayBlockEntityMixin$ForgeLike",
"world.level.block.entity.EndGatewayBlockEntityMixin$VanillaLike",
"world.level.block.entity.HopperBlockEntityMixin",
"world.level.block.entity.JukeboxBlockEntityMixin",
Expand Down

0 comments on commit 75700e2

Please sign in to comment.