Started by
Norite113
on
Topic category: User side tutorials
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")));
}
}
}
}
Interesting, thanks...
What does it do?
from my understanding it works like a ender pearl
@BadKaiPanda It seems you can code, if you don't mind please can you create a tutorial on how to create a multi shot bow.
Oops, why is my whole comment a link