Preventing END special events with dimensional api ()

* Preventing END special events with dimensional api

* Style errors fix
This commit is contained in:
kohanis 2022-01-02 22:36:31 +03:00 committed by GitHub
parent befed49ea3
commit d8e20785fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 2 deletions
fabric-dimensions-v1/src/main

View file

@ -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)

View file

@ -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;
}
}

View file

@ -4,6 +4,7 @@
"compatibilityLevel": "JAVA_16",
"mixins": [
"EntityMixin",
"ServerPlayerEntityMixin",
"ServerBugfixMixin"
],
"injectors": {