mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-11 22:45:38 -04:00
Preventing END special events with dimensional api (#1938)
* Preventing END special events with dimensional api * Style errors fix
This commit is contained in:
parent
befed49ea3
commit
d8e20785fa
3 changed files with 75 additions and 2 deletions
fabric-dimensions-v1/src/main
java/net/fabricmc/fabric/mixin/dimension
resources
|
@ -22,6 +22,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.world.TeleportTarget;
|
||||
|
||||
|
@ -29,9 +30,10 @@ import net.fabricmc.fabric.impl.dimension.FabricDimensionInternals;
|
|||
|
||||
/**
|
||||
* This mixin implements {@link Entity#getTeleportTarget(ServerWorld)} for modded dimensions, as Vanilla will
|
||||
* not return a teleport target for anything but Vanilla dimensions.
|
||||
* not return a teleport target for anything but Vanilla dimensions and prevents changing teleport target in
|
||||
* {@link ServerPlayerEntity#getTeleportTarget(ServerWorld)} when teleporting to END using api.
|
||||
*/
|
||||
@Mixin(Entity.class)
|
||||
@Mixin(value = {ServerPlayerEntity.class, Entity.class})
|
||||
public class EntityMixin {
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Inject(method = "getTeleportTarget", at = @At("HEAD"), cancellable = true, allow = 1)
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.mixin.dimension;
|
||||
|
||||
import org.objectweb.asm.Opcodes;
|
||||
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.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.Slice;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.fabricmc.fabric.impl.dimension.FabricDimensionInternals;
|
||||
|
||||
/**
|
||||
* This mixin prevents END dimension specific events when using api. Specifically:
|
||||
* <ol>
|
||||
* <li>{@link ServerPlayerEntity#createEndSpawnPlatform(ServerWorld, BlockPos)} execution when teleporting to END</li>
|
||||
* <li>"Game won" screen and {@link ServerPlayerEntity#seenCredits} flag setting by
|
||||
* {@link ServerPlayerEntity#moveToWorld(ServerWorld)} when teleporting from END</li>
|
||||
* </ol>
|
||||
*/
|
||||
@Mixin(ServerPlayerEntity.class)
|
||||
public class ServerPlayerEntityMixin {
|
||||
@Inject(method = "createEndSpawnPlatform", at = @At("HEAD"), cancellable = true, allow = 1)
|
||||
public void getTeleportTarget(ServerWorld world, BlockPos centerPos, CallbackInfo ci) {
|
||||
// Check if a destination has been set for the entity currently being teleported
|
||||
if (FabricDimensionInternals.getCustomTarget() != null) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(
|
||||
method = "moveToWorld",
|
||||
slice = @Slice(
|
||||
from = @At(value = "FIELD", target = "net/minecraft/world/World.END:Lnet/minecraft/util/registry/RegistryKey;", opcode = Opcodes.GETSTATIC, ordinal = 0),
|
||||
to = @At(value = "FIELD", target = "net/minecraft/server/network/ServerPlayerEntity.notInAnyWorld:Z", opcode = Opcodes.GETFIELD, ordinal = 0)
|
||||
),
|
||||
at = @At(value = "FIELD", target = "net/minecraft/world/World.OVERWORLD:Lnet/minecraft/util/registry/RegistryKey;", opcode = Opcodes.GETSTATIC),
|
||||
allow = 1
|
||||
)
|
||||
public RegistryKey<World> moveToWorld() {
|
||||
// Check if a destination has been set for the entity currently being teleported
|
||||
if (FabricDimensionInternals.getCustomTarget() != null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return World.END;
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
"compatibilityLevel": "JAVA_16",
|
||||
"mixins": [
|
||||
"EntityMixin",
|
||||
"ServerPlayerEntityMixin",
|
||||
"ServerBugfixMixin"
|
||||
],
|
||||
"injectors": {
|
||||
|
|
Loading…
Add table
Reference in a new issue