Предмет-телепортер

Версия Minecraft
1.7.10
1,385
116
246
У меня возник вопрос: как телепортировать игрока с одного измерения в другое? Я тут накидал кое-что, но оно не работает. Код смотрите ниже. Прошу помощи, больно интересно как это можно реализовать. Заранее спасибо!
Java:
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;

public class NetherItem extends Item {
    protected NetherItem(){
        super();
        setUnlocalizedName("netherItem");
        setCreativeTab(CreativeTabs.tabMisc);
    }
    public ItemStack onRightClick(ItemStack is, World world, EntityPlayer player) {
        if(!world.isRemote) {
            player.travelToDimension(-1);
            EntityPlayerMP playerMP = (EntityPlayerMP) player;
            MinecraftServer.getServer().getConfigurationManager().transferPlayerToDimension(playerMP, -1);
        }
        return is;
        
    }
}
 
7,099
324
1,510
1,385
116
246
Честно говоря, я практически вообще не разбираюсь в чужом коде. Мне нужно чтоб на каждую строчку был коммент, а так проблему я решил, осталось только коорды игрока каким-то образом сохранить...
 
344
1
47
*facepalm* вам готовый код дали) Это очень сложно, посмотреть внимательно...

Java:
        public void writeToNBT(NBTTagCompound compound) {
            compound.setDouble("X", xCoord);
            compound.setDouble("Y", yCoord);
            compound.setDouble("Z", zCoord);
            compound.setInteger("Dimension", dimension);
            compound.setFloat("Pitch", pitch);
            compound.setFloat("Yaw", yaw);
            compound.setString("Name", name);
            compound.setString("DimentionName", dimensionName);
            compound.setBoolean("WP", writeProtected);
        }

        public void readFromNBT(NBTTagCompound compound) {
            xCoord = compound.getDouble("X");
            yCoord = compound.getDouble("Y");
            zCoord = compound.getDouble("Z");
            dimension = compound.getInteger("Dimension");
            pitch = compound.getFloat("Pitch");
            yaw = compound.getFloat("Yaw");
            name = compound.getString("Name");
            dimensionName = compound.getString("DimentionName");
            writeProtected = compound.getBoolean("WP");
        }
 
917
22
332
У меня гит заблочили
Есть vpn.
Java:
package com.brandon3055.brandonscore.utils;

import com.brandon3055.brandonscore.lib.TeleportUtils;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;

public class Teleporter
{
    public static class TeleportLocation {
        protected double xCoord;
        protected double yCoord;
        protected double zCoord;
        protected int dimension;
        protected float pitch;
        protected float yaw;
        protected String name;
        protected String dimensionName = "";
        protected boolean writeProtected = false;

        public TeleportLocation() {

        }

        public TeleportLocation(double x, double y, double z, int dimension) {
            this.xCoord = x;
            this.yCoord = y;
            this.zCoord = z;
            this.dimension = dimension;
            this.pitch = 0;
            this.yaw = 0;
        }

        public TeleportLocation(double x, double y, double z, int dimension, float pitch, float yaw) {
            this.xCoord = x;
            this.yCoord = y;
            this.zCoord = z;
            this.dimension = dimension;
            this.pitch = pitch;
            this.yaw = yaw;
        }

        public TeleportLocation(double x, double y, double z, int dimension, float pitch, float yaw, String name) {
            this.xCoord = x;
            this.yCoord = y;
            this.zCoord = z;
            this.dimension = dimension;
            this.pitch = pitch;
            this.yaw = yaw;
            this.name = name;
        }

        public double getXCoord() {
            return xCoord;
        }

        public double getYCoord() {
            return yCoord;
        }

        public double getZCoord() {
            return zCoord;
        }

        public int getDimension() {
            return dimension;
        }

        public String getDimensionName() {
            return dimensionName;
        }

        public float getPitch() {
            return pitch;
        }

        public float getYaw() {
            return yaw;
        }

        public String getName() {
            return name;
        }

        public boolean getWriteProtected() {
            return writeProtected;
        }

        public void setXCoord(double x) {
            xCoord = x;
        }

        public void setYCoord(double y) {
            yCoord = y;
        }

        public void setZCoord(double z) {
            zCoord = z;
        }

        public void setDimension(int d) {
            dimension = d;
        }

        public void setPitch(float p) {
            pitch = p;
        }

        public void setYaw(float y) {
            yaw = y;
        }

        public void setName(String s) {
            name = s;
        }

        public void setWriteProtected(boolean b) {
            writeProtected = b;
        }

        public void writeToNBT(NBTTagCompound compound) {
            compound.setDouble("X", xCoord);
            compound.setDouble("Y", yCoord);
            compound.setDouble("Z", zCoord);
            compound.setInteger("Dimension", dimension);
            compound.setFloat("Pitch", pitch);
            compound.setFloat("Yaw", yaw);
            compound.setString("Name", name);
            compound.setString("DimentionName", dimensionName);
            compound.setBoolean("WP", writeProtected);
        }

        public void readFromNBT(NBTTagCompound compound) {
            xCoord = compound.getDouble("X");
            yCoord = compound.getDouble("Y");
            zCoord = compound.getDouble("Z");
            dimension = compound.getInteger("Dimension");
            pitch = compound.getFloat("Pitch");
            yaw = compound.getFloat("Yaw");
            name = compound.getString("Name");
            dimensionName = compound.getString("DimentionName");
            writeProtected = compound.getBoolean("WP");
        }

        public void teleport(Entity entity) {
            TeleportUtils.teleportEntity(entity, dimension, xCoord, yCoord, zCoord, yaw, pitch);
        }

        public void setDimensionName(String dimensionName) {
            this.dimensionName = dimensionName;
        }

        @Override
        public int hashCode() {
            return (xCoord + "-" + yCoord + "-" + zCoord + "-" + name + "-" + dimensionName + "-" + dimension + "-" + yaw + "-" + pitch).hashCode();
        }
    }
}
 

CMTV

Основатель
Администратор
1,304
4
601
Сверху