Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.coderandom.etheriacraft.procedures;
- import net.minecraft.world.level.Level;
- import net.minecraft.world.item.ItemStack;
- import net.minecraft.world.entity.LivingEntity;
- import net.minecraft.world.entity.Entity;
- import net.minecraft.world.effect.MobEffectInstance;
- import net.minecraft.util.RandomSource;
- import net.minecraft.server.level.ServerPlayer;
- import net.minecraft.server.level.ServerLevel;
- import net.minecraft.resources.ResourceKey;
- import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket;
- import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket;
- import net.minecraft.network.protocol.game.ClientboundLevelEventPacket;
- import net.minecraft.network.protocol.game.ClientboundGameEventPacket;
- import net.minecraft.core.BlockPos;
- import net.coderandom.etheriacraft.EtheriaCraftMod;
- public class FocusedEyeOfEnderRightclickedProcedure {
- public static double execute(Entity entity, ItemStack itemstack) {
- if (entity == null)
- return 0;
- if (entity.isShiftKeyDown()) {
- itemstack.getOrCreateTag().putString("dimension", ("" + entity.level().dimension()));
- EtheriaCraftMod.LOGGER.debug(("" + entity.level().dimension()));
- itemstack.getOrCreateTag().putDouble("teleportX", (entity.getX()));
- itemstack.getOrCreateTag().putDouble("teleportY", (entity.getY()));
- itemstack.getOrCreateTag().putDouble("teleportZ", (entity.getZ()));
- itemstack.getOrCreateTag().putDouble("yaw", (entity.getYRot()));
- itemstack.getOrCreateTag().putDouble("pitch", (entity.getXRot()));
- itemstack.getOrCreateTag().putBoolean("canTeleport", true);
- return 1;
- }
- if (itemstack.getOrCreateTag().getBoolean("canTeleport")) {
- if (!(itemstack.getOrCreateTag().getString("dimension")).equals("" + entity.level().dimension())) {
- EtheriaCraftMod.LOGGER.debug(("" + entity.level().dimension()));
- if ((itemstack.getOrCreateTag().getString("dimension")).contains("minecraft:overworld")) {
- if (entity instanceof ServerPlayer _player && !_player.level().isClientSide()) {
- ResourceKey<Level> destinationType = Level.OVERWORLD;
- if (_player.level().dimension() == destinationType)
- return;
- ServerLevel nextLevel = _player.server.getLevel(destinationType);
- if (nextLevel != null) {
- _player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.WIN_GAME, 0));
- _player.teleportTo(nextLevel, _player.getX(), _player.getY(), _player.getZ(), _player.getYRot(), _player.getXRot());
- _player.connection.send(new ClientboundPlayerAbilitiesPacket(_player.getAbilities()));
- for (MobEffectInstance _effectinstance : _player.getActiveEffects())
- _player.connection.send(new ClientboundUpdateMobEffectPacket(_player.getId(), _effectinstance));
- _player.connection.send(new ClientboundLevelEventPacket(1032, BlockPos.ZERO, 0, false));
- }
- }
- } else if ((itemstack.getOrCreateTag().getString("dimension")).contains("minecraft:the_nether")) {
- if (entity instanceof ServerPlayer _player && !_player.level().isClientSide()) {
- ResourceKey<Level> destinationType = Level.NETHER;
- if (_player.level().dimension() == destinationType)
- return;
- ServerLevel nextLevel = _player.server.getLevel(destinationType);
- if (nextLevel != null) {
- _player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.WIN_GAME, 0));
- _player.teleportTo(nextLevel, _player.getX(), _player.getY(), _player.getZ(), _player.getYRot(), _player.getXRot());
- _player.connection.send(new ClientboundPlayerAbilitiesPacket(_player.getAbilities()));
- for (MobEffectInstance _effectinstance : _player.getActiveEffects())
- _player.connection.send(new ClientboundUpdateMobEffectPacket(_player.getId(), _effectinstance));
- _player.connection.send(new ClientboundLevelEventPacket(1032, BlockPos.ZERO, 0, false));
- }
- }
- } else if ((itemstack.getOrCreateTag().getString("dimension")).contains("minecraft:the_end")) {
- if (entity instanceof ServerPlayer _player && !_player.level().isClientSide()) {
- ResourceKey<Level> destinationType = Level.END;
- if (_player.level().dimension() == destinationType)
- return;
- ServerLevel nextLevel = _player.server.getLevel(destinationType);
- if (nextLevel != null) {
- _player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.WIN_GAME, 0));
- _player.teleportTo(nextLevel, _player.getX(), _player.getY(), _player.getZ(), _player.getYRot(), _player.getXRot());
- _player.connection.send(new ClientboundPlayerAbilitiesPacket(_player.getAbilities()));
- for (MobEffectInstance _effectinstance : _player.getActiveEffects())
- _player.connection.send(new ClientboundUpdateMobEffectPacket(_player.getId(), _effectinstance));
- _player.connection.send(new ClientboundLevelEventPacket(1032, BlockPos.ZERO, 0, false));
- }
- }
- }
- }
- {
- Entity _ent = entity;
- _ent.setYRot((float) itemstack.getOrCreateTag().getDouble("yaw"));
- _ent.setXRot((float) itemstack.getOrCreateTag().getDouble("pitch"));
- _ent.setYBodyRot(_ent.getYRot());
- _ent.setYHeadRot(_ent.getYRot());
- _ent.yRotO = _ent.getYRot();
- _ent.xRotO = _ent.getXRot();
- if (_ent instanceof LivingEntity _entity) {
- _entity.yBodyRotO = _entity.getYRot();
- _entity.yHeadRotO = _entity.getYRot();
- }
- }
- {
- Entity _ent = entity;
- _ent.teleportTo((itemstack.getOrCreateTag().getDouble("teleportX")), (itemstack.getOrCreateTag().getDouble("teleportY")), (itemstack.getOrCreateTag().getDouble("teleportZ")));
- if (_ent instanceof ServerPlayer _serverPlayer)
- _serverPlayer.connection.teleport((itemstack.getOrCreateTag().getDouble("teleportX")), (itemstack.getOrCreateTag().getDouble("teleportY")), (itemstack.getOrCreateTag().getDouble("teleportZ")), _ent.getYRot(), _ent.getXRot());
- }
- {
- ItemStack _ist = itemstack;
- if (_ist.hurt(1, RandomSource.create(), null)) {
- _ist.shrink(1);
- _ist.setDamageValue(0);
- }
- }
- }
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement