Jump to content

Recommended Posts

Posted

i made an item that if you right click it, it will transfer you to a dimension, but everytime i right click it, it brings me to the dimension, but instantly teleports me to hell. Help pls. This is my code. Reply if you need more parts of it.

package com.mrfloatingcow.items;

import com.mrfloatingcow.dimensions.dimensionRegistry;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.world.World;

public class rbSword extends ItemSword{

public rbSword(ToolMaterial p_i45356_1_) {
	super(p_i45356_1_);
}

public ItemStack onItemRightClick (ItemStack par1ItemStack, World par2World, EntityPlayer Player){

	EntityPlayer player = (EntityPlayer) Player;
	player.travelToDimension(dimensionRegistry.dimensionIdRainbow);
	return par1ItemStack;


}

}

Posted

I don't see anything blatant that would cause that, you could try the way I did it, with packets, which also affords you more control over how the player is placed in the destination dimension:

 

 

Main class:

public static SimpleNetworkWrapper snw;


@EventHandler
public void preinit(FMLPreInitializationEvent event)
{
	snw = NetworkRegistry.INSTANCE.newSimpleChannel(modid);
	snw.registerMessage(MessageTeleportToDimension.TeleportHandler.class, MessageTeleportToDimension.class, idnumber, Side.SERVER);
}

 

 

Packet:

public class MessageTeleportToDimension implements IMessage
{
int dim;
int id;


public MessageTeleportToDimension(){}


public MessageTeleportToDimension(int dim, int id)
{
	this.dim = dim;
	this.id = id;
}


@Override
public void fromBytes(ByteBuf buf)
{
	this.dim = buf.readInt();
	this.id = buf.readInt();
}


@Override
public void toBytes(ByteBuf buf)
{
	buf.writeInt(this.dim);
	buf.writeInt(this.id);
}


public static class TeleportHandler implements IMessageHandler<MessageTeleportToDimension, IMessage>
{
	@Override
	public IMessage onMessage(MessageTeleportToDimension message, MessageContext ctx)
	{
		Entity ent = ctx.getServerHandler().playerEntity.worldObj.getEntityByID(message.id);
		if(ent instanceof EntityPlayerMP)
		{
			EntityPlayerMP player = (EntityPlayerMP)ent;
			player.mcServer.getConfigurationManager().transferPlayerToDimension(player, message.dim, new CustomTeleporter(player.mcServer.worldServerForDimension(message.dim)));
			player.fallDistance = 0.0f;
		}
		return message;
	}
}
}

 

 

Custom Teleporter (I used this to teleport the player to the overworld without forming a Nether portal, this is where your placement logic would go)

public class CustomTeleporter extends Teleporter
{
final WorldServer worldServer;


public CustomTeleporter(WorldServer worldServer)
{
	super(worldServer);
	this.worldServer = worldServer;
}


@Override
public boolean makePortal(Entity entity){~}


@Override
public void placeInPortal(Entity entity, double x, double y, double z, float yaw){~}
}

 

 

OnRightClick:

MainClass.snw.sendToServer(new MessageTeleportToDimension(dimensionid, player.getEntityId()));

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.