Scroll of teleportation Code

Started by Norite113 on

Topic category: User side tutorials

Joined Jan 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Scroll of teleportation Code

 

I have created the code of the teleportation roll, I put it here so that it will not die
 

Code:

​
package mod.mcreator;

import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;

import net.minecraft.world.World;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumActionResult;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.init.Items;
import net.minecraft.init.Blocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.Minecraft;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.Block;

import java.util.Random;
import java.util.List;

//Create By Norite113

@SuppressWarnings("unchecked")
public class mcreator_redScrollOfTeleportation {

	public mcreator_redScrollOfTeleportation() {
	}

	public static Item block;
	public static Object instance;

	public void load(FMLInitializationEvent event) {
		if (event.getSide() == Side.CLIENT)
			Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
					.register(block, 0, new ModelResourceLocation("TestEnvironmentMod:RedScrollOfTeleportation", "inventory"));

		GameRegistry.addRecipe(new ItemStack(block, 1), new Object[]{"XXX", "XXX", "678", Character.valueOf('6'), Items.PAPER,
				Character.valueOf('7'), Items.ENDER_PEARL, Character.valueOf('8'), Items.PAPER,});
	}

	public void generateNether(World world, Random random, int chunkX, int chunkZ) {
	}

	public void generateSurface(World world, Random random, int chunkX, int chunkZ) {
	}

	public int addFuel(ItemStack fuel) {
		return 0;
	}

	public void serverLoad(FMLServerStartingEvent event) {
	}

	public void preInit(FMLPreInitializationEvent event) {
	}

	public void registerRenderers() {
	}

	static {
		block = (new ItemredScrollOfTeleportation());

	}

	static class ItemredScrollOfTeleportation extends Item {

		public ItemredScrollOfTeleportation() {
			setMaxDamage(1);
			maxStackSize = 1;
			setUnlocalizedName("RedScrollOfTeleportation");
			GameRegistry.registerItem(this, "RedScrollOfTeleportation");
			setCreativeTab(mcreator_magicCraft.tab);
		}

		@Override
		public int getItemEnchantability() {
			return 0;
		}

		@Override
		public int getMaxItemUseDuration(ItemStack par1ItemStack) {
			return 0;
		}

		@Override
		public float getStrVsBlock(ItemStack par1ItemStack, IBlockState par2Block) {
			return 1.0F;
		}

		public EnumActionResult onItemUseFirst(ItemStack itemStack, EntityPlayer entity, World world, BlockPos pos, EnumFacing side, float hitX,
				float hitY, float hitZ, EnumHand hand) {
			float var4 = 1.0F;

			NBTTagCompound nbt;

			if (entity.inventory.getCurrentItem() != null && entity.inventory.getCurrentItem().getItem() == mcreator_redScrollOfTeleportation.block) {
				if (itemStack.hasTagCompound()) {
					nbt = itemStack.getTagCompound();
				} else {
					nbt = new NBTTagCompound();
				}

				if (entity instanceof EntityPlayer) {
					if (entity.isSneaking() && entity.isCreative()) {
						if (!nbt.hasKey("x")) {
							nbt.setInteger("x", pos.getX());
						}
						if (!nbt.hasKey("y")) {
							nbt.setInteger("y", pos.getY() + 1);
						}
						if (!nbt.hasKey("z")) {
							nbt.setInteger("z", pos.getZ());
						}
						itemStack.setTagCompound(nbt);

					} else {
						if (nbt.hasKey("x")) {
							if (nbt.hasKey("y")) {
								if (nbt.hasKey("z")) {

									int X = itemStack.getTagCompound().getInteger("x");
									int Y = itemStack.getTagCompound().getInteger("y");
									int Z = itemStack.getTagCompound().getInteger("z");

									entity.setPositionAndUpdate((double) X + 0.5f, (double) Y, (double) Z + 0.5f);
									itemStack.damageItem(2, entity);

								}
							}
						}
					}
				}

			}
			return EnumActionResult.PASS;
		}

		@Override
		public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List list, boolean par4) {
			list.add("teleports the player to");
			if (par1ItemStack.hasTagCompound() && par1ItemStack.getTagCompound().hasKey("x") && par1ItemStack.getTagCompound().hasKey("y")
					&& par1ItemStack.getTagCompound().hasKey("z")) {
				list.add("X " + Integer.toString(par1ItemStack.getTagCompound().getInteger("x")) + "Y "
						+ Integer.toString(par1ItemStack.getTagCompound().getInteger("y")) + "Z "
						+ Integer.toString(par1ItemStack.getTagCompound().getInteger("z")));
			}
		}
	}
}

​

 

Joined Nov 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Interesting, thanks...
Sun, 01/13/2019 - 13:00

Interesting, thanks...

Joined Jun 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
What does it do?
Sun, 01/13/2019 - 14:18

What does it do?

Joined Sep 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
from my understanding it…
Sun, 01/13/2019 - 16:19

from my understanding it works like a ender pearl

Joined Nov 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Oops, why is my whole…
Wed, 01/16/2019 - 18:21

Oops, why is my whole comment a link