Updates version

This commit is contained in:
paulevsGitch 2021-01-14 06:21:05 +03:00
parent 87c0c153bb
commit 9c31454a46
5 changed files with 73 additions and 18 deletions

View file

@ -2,8 +2,6 @@ package ru.betterend.blocks;
import java.util.Objects;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@ -22,7 +20,6 @@ import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Direction.Axis;
import net.minecraft.util.math.Direction.AxisDirection;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.GameMode;
import net.minecraft.world.Heightmap;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
@ -76,9 +73,6 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
if (exitPos == null) return;
if (entity instanceof ServerPlayerEntity) {
ServerPlayerEntity player = (ServerPlayerEntity) entity;
//player.teleport(destination, exitPos.getX() + 0.5D, exitPos.getY(), exitPos.getZ() + 0.5D, player.yaw, player.pitch);
//player.onTeleportationDone();
//player.resetNetherPortalCooldown();
teleportPlayer(player, destination, exitPos);
} else {
@ -93,16 +87,22 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
}
private void teleportPlayer(ServerPlayerEntity player, ServerWorld destination, BlockPos pos) {
((TeleportingEntity) player).beSetExitPos(pos);
if (player.isCreative()) {
player.teleport(destination, pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, player.yaw, player.pitch);
}
else {
if (destination.getRegistryKey() == World.OVERWORLD) {
//player.teleport(destination, pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, player.yaw, player.pitch);
//player.updatePositionAndAngles(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, player.yaw, player.pitch);
player.moveToWorld(destination);
player.teleport(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
if (destination.getRegistryKey() == World.OVERWORLD) {
destination.tickEntity(player);
//player.updatePositionAndAngles(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, player.yaw, player.pitch);
//player.teleport(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
}
else {
player.moveToWorld(destination);
player.teleport(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
//player.teleport(destination, pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, player.yaw, player.pitch);
}
}
player.resetNetherPortalCooldown();

View file

@ -4,4 +4,6 @@ import net.minecraft.util.math.BlockPos;
public interface TeleportingEntity {
void beSetExitPos(BlockPos pos);
boolean beCanTeleport();
}

View file

@ -1,5 +1,7 @@
package ru.betterend.mixin.common;
import java.util.Map;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -7,6 +9,8 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.google.common.collect.Maps;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.server.world.ServerWorld;
@ -18,8 +22,7 @@ import ru.betterend.interfaces.TeleportingEntity;
@Mixin(Entity.class)
public abstract class EntityMixin implements TeleportingEntity {
private BlockPos beExitPos;
private static final Map<Entity, BlockPos> EXIT_POS = Maps.newHashMap();
@Shadow
public float yaw;
@ -45,14 +48,15 @@ public abstract class EntityMixin implements TeleportingEntity {
@Inject(method = "moveToWorld", at = @At("HEAD"), cancellable = true)
public void be_moveToWorld(ServerWorld destination, CallbackInfoReturnable<Entity> info) {
if (!removed && beExitPos != null && world instanceof ServerWorld) {
Entity entity = (Entity) (Object) this;
if (!removed && beCanTeleport() && world instanceof ServerWorld) {
this.detach();
this.world.getProfiler().push("changeDimension");
this.world.getProfiler().push("reposition");
TeleportTarget teleportTarget = this.getTeleportTarget(destination);
if (teleportTarget != null) {
this.world.getProfiler().swap("reloading");
Entity entity = this.getType().create(destination);
entity = this.getType().create(destination);
if (entity != null) {
entity.copyFrom(Entity.class.cast(this));
entity.refreshPositionAndAngles(teleportTarget.position.x, teleportTarget.position.y, teleportTarget.position.z, teleportTarget.yaw, entity.pitch);
@ -64,21 +68,41 @@ public abstract class EntityMixin implements TeleportingEntity {
((ServerWorld) world).resetIdleTimeout();
destination.resetIdleTimeout();
this.world.getProfiler().pop();
this.beExitPos = null;
be_resetTeleport();
info.setReturnValue(entity);
info.cancel();
}
}
}
@Inject(method = "getTeleportTarget", at = @At("HEAD"), cancellable = true)
protected void be_getTeleportTarget(ServerWorld destination, CallbackInfoReturnable<TeleportTarget> info) {
if (beExitPos != null) {
info.setReturnValue(new TeleportTarget(new Vec3d(beExitPos.getX() + 0.5D, beExitPos.getY(), beExitPos.getZ() + 0.5D), getVelocity(), yaw, pitch));
if (beCanTeleport()) {
BlockPos pos = EXIT_POS.get(be_getSelf());
info.setReturnValue(new TeleportTarget(new Vec3d(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5), getVelocity(), yaw, pitch));
be_resetTeleport();
info.cancel();
}
}
@Shadow
protected void setRotation(float yaw, float pitch) {}
@Override
public void beSetExitPos(BlockPos pos) {
this.beExitPos = pos;
EXIT_POS.put(be_getSelf(), pos.toImmutable());
}
private void be_resetTeleport() {
EXIT_POS.remove(be_getSelf());
}
@Override
public boolean beCanTeleport() {
return EXIT_POS.containsKey(be_getSelf());
}
private Entity be_getSelf() {
return (Entity) (Object) this;
}
}

View file

@ -0,0 +1,28 @@
package ru.betterend.mixin.common;
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.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.TeleportTarget;
@Mixin(ServerPlayerEntity.class)
public class ServerPlayerEntityMixin {
@Inject(method = "createEndSpawnPlatform", at = @At("HEAD"), cancellable = true)
private void be_createEndSpawnPlatform(ServerWorld world, BlockPos centerPos, CallbackInfo info) {
if (!centerPos.equals(world.getSpawnPos())) {
info.cancel();
}
}
@Inject(method = "getTeleportTarget", at = @At("HEAD"), cancellable = true)
protected void be_getTeleportTarget(ServerWorld destination, CallbackInfoReturnable<TeleportTarget> info) {
info.setReturnValue(new TeleportTarget(new Vec3d(0, 100, 0), Vec3d.ZERO, 0, 0));
}
}

View file

@ -12,6 +12,7 @@
"NoiseChunkGeneratorMixin",
"AnvilScreenHandlerMixin",
"ChorusPlantFeatureMixin",
"ServerPlayerEntityMixin",
"ComposterBlockAccessor",
"ChorusFlowerBlockMixin",
"LandPathNodeMakerMixin",