Created
March 24, 2016 22:44
-
-
Save MattDahEpic/f2d77d259367f530cbc5 to your computer and use it in GitHub Desktop.
unworking item colors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mattdahepic.telepacks.client; | |
import com.mattdahepic.telepacks.CommonProxy; | |
import com.mattdahepic.telepacks.TelePacks; | |
import com.mattdahepic.telepacks.item.ItemTelePack; | |
import net.minecraft.client.Minecraft; | |
import net.minecraft.client.renderer.block.model.ModelBakery; | |
import net.minecraft.client.renderer.block.model.ModelResourceLocation; | |
import net.minecraft.client.renderer.color.IItemColor; | |
import net.minecraft.item.EnumDyeColor; | |
import net.minecraft.item.ItemStack; | |
import net.minecraftforge.client.model.ModelLoader; | |
import net.minecraftforge.fml.relauncher.Side; | |
import net.minecraftforge.fml.relauncher.SideOnly; | |
@SideOnly(Side.CLIENT) | |
public class ClientProxy extends CommonProxy { | |
@Override | |
public void registerRenderers () { | |
ModelBakery.registerItemVariants(TelePacks.telepack, new ModelResourceLocation("telepacks:telepack", "inventory")); | |
ModelLoader.setCustomModelResourceLocation(TelePacks.telepack, 0, new ModelResourceLocation("telepacks:telepack", "inventory")); | |
ModelLoader.setCustomModelResourceLocation(TelePacks.telepack, 1, new ModelResourceLocation("telepacks:telepack", "inventory")); | |
} | |
@Override | |
public void registerColorHandler () { | |
Minecraft.getMinecraft().getItemColors().registerItemColorHandler(TelePacks.telepack, TelePacks.telepack); //color handler for telepack is in ItemTelePack | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mattdahepic.telepacks.item; | |
import com.mattdahepic.mdecore.helpers.PlayerHelper; | |
import com.mattdahepic.mdecore.helpers.TeleportHelper; | |
import net.minecraft.client.renderer.color.IItemColor; | |
import net.minecraft.creativetab.CreativeTabs; | |
import net.minecraft.entity.Entity; | |
import net.minecraft.entity.EntityLivingBase; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.item.EnumAction; | |
import net.minecraft.item.EnumDyeColor; | |
import net.minecraft.item.Item; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.nbt.NBTTagCompound; | |
import net.minecraft.server.management.PlayerList; | |
import net.minecraft.util.*; | |
import net.minecraft.util.text.TextComponentString; | |
import net.minecraft.util.text.TextFormatting; | |
import net.minecraft.world.World; | |
import net.minecraftforge.fml.relauncher.Side; | |
import net.minecraftforge.fml.relauncher.SideOnly; | |
import java.util.List; | |
public class ItemTelePack extends Item implements IItemColor { | |
public static final String NAME = "telepack"; | |
public static final String COLOR_KEY = "packColor"; | |
public ItemTelePack () { | |
super(); | |
this.setUnlocalizedName(NAME); | |
this.setCreativeTab(CreativeTabs.tabAllSearch); | |
this.setMaxStackSize(1); | |
this.setHasSubtypes(true); | |
} | |
@Override | |
public EnumAction getItemUseAction(ItemStack stack) { | |
return EnumAction.BOW; | |
} | |
@Override | |
public int getMaxItemUseDuration(ItemStack stack) { | |
return 7; | |
} | |
@Override | |
@SideOnly(Side.CLIENT) | |
public boolean hasEffect(ItemStack stack) { | |
return canCrossDimensions(stack); | |
} | |
@Override | |
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) { | |
player.setActiveHand(hand); | |
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS,stack); | |
} | |
@Override | |
public void onPlayerStoppedUsing (ItemStack stack, World world, EntityLivingBase entity, int timeLeft) { | |
if (!world.isRemote && entity instanceof EntityPlayer) { | |
if (entity.isSneaking() && timeLeft != 0) { | |
setStoredLocation((EntityPlayer)entity,stack,new TelePackLocation(entity.posX,entity.posY, entity.posZ,entity.dimension)); | |
} else { | |
entity.playSound(new SoundEvent(new ResourceLocation("minecraft","random.fizz")),1f,1f); | |
((EntityPlayer)entity).getCooldownTracker().setCooldown(this,3); | |
} | |
} | |
} | |
@Override | |
public ItemStack onItemUseFinish(ItemStack stack, World world, EntityLivingBase entity) { | |
if (stack.hasTagCompound() && !world.isRemote && entity instanceof EntityPlayer) { | |
if (!entity.isSneaking()) { | |
if (hasValidLocation(stack)) { | |
TelePackLocation loc = getStoredLocation(stack); | |
if (canCrossDimensions(stack) && loc.dimension != ((EntityPlayer)entity).dimension) { | |
PlayerList list = entity.getServer().getPlayerList(); | |
TeleportHelper.transferPlayerToDimension(PlayerHelper.getPlayerFromUsername(((EntityPlayer)entity).getDisplayNameString()), loc.dimension, list); | |
} | |
if (loc.dimension == entity.dimension) { | |
entity.setPositionAndUpdate(loc.x+.5f, loc.y+.25f, loc.z+.5f); | |
((EntityPlayer)entity).getCooldownTracker().setCooldown(this, canCrossDimensions(stack) ? 240 : 90); | |
entity.playSound(new SoundEvent(new ResourceLocation("minecraft:mob.enderman.portal")), 1f, 1f); | |
} else { | |
((EntityPlayer)entity).addChatComponentMessage(new TextComponentString(TextFormatting.YELLOW + "The technology in this pack is too primitive to cross the dimensional gap.")); | |
} | |
} else { | |
((EntityPlayer)entity).addChatComponentMessage(new TextComponentString("No location set!")); | |
} | |
} | |
} | |
return stack; | |
} | |
@Override | |
public String getUnlocalizedName (ItemStack stack) { | |
switch (stack.getMetadata()) { | |
case 0: | |
return super.getUnlocalizedName(stack)+"_basic"; | |
case 1: | |
return super.getUnlocalizedName(stack)+"_advanced"; | |
} | |
return null; | |
} | |
@Override | |
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean isSelected) { | |
if (!stack.hasTagCompound()) { | |
stack.setTagCompound(new NBTTagCompound()); | |
} | |
} | |
@Override | |
@SideOnly(Side.CLIENT) | |
@SuppressWarnings("unchecked") | |
public void addInformation(ItemStack stack, EntityPlayer playerIn, List tooltip, boolean advanced) { | |
if (stack.hasTagCompound()) { | |
if (hasValidLocation(stack)) { | |
TelePackLocation loc = getStoredLocation(stack); | |
tooltip.add("Location set at ("+loc.x+","+loc.y+","+loc.z+")"); | |
tooltip.add("In the dimension "+loc.dimension+"."); | |
return; | |
} | |
} | |
tooltip.add("No location set."); | |
} | |
@Override | |
@SideOnly(Side.CLIENT) | |
@SuppressWarnings("unchecked") | |
public void getSubItems(Item item, CreativeTabs tab, List list) { | |
list.add(new ItemStack(item,1,0)); | |
list.add(new ItemStack(item,1,1)); | |
} | |
@Override | |
@SideOnly(Side.CLIENT) | |
public int getColorFromItemstack(ItemStack stack, int tintIndex) { | |
if (!stack.getTagCompound().hasKey(ItemTelePack.COLOR_KEY)) stack.getTagCompound().setInteger(ItemTelePack.COLOR_KEY, EnumDyeColor.LIME.getMapColor().colorIndex); | |
return stack.getTagCompound().getInteger(ItemTelePack.COLOR_KEY); | |
} | |
//... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mattdahepic.telepacks; | |
import com.mattdahepic.telepacks.item.ItemTelePack; | |
import net.minecraft.item.Item; | |
import net.minecraftforge.common.MinecraftForge; | |
import net.minecraftforge.fml.common.FMLCommonHandler; | |
import net.minecraftforge.fml.common.Mod; | |
import net.minecraftforge.fml.common.SidedProxy; | |
import net.minecraftforge.fml.common.event.FMLInitializationEvent; | |
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; | |
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | |
import net.minecraftforge.fml.common.gameevent.PlayerEvent; | |
import org.apache.logging.log4j.LogManager; | |
import org.apache.logging.log4j.Logger; | |
@Mod(modid = TelePacks.MODID,name = TelePacks.NAME,version = TelePacks.VERSION,dependencies = TelePacks.DEPENDENCIES,updateJSON = TelePacks.UPDATE_JSON) | |
public class TelePacks { | |
//... | |
@Mod.EventHandler | |
public void load (FMLPreInitializationEvent e) { | |
proxy.registerItems(); | |
proxy.registerRenderers(); | |
} | |
@Mod.EventHandler | |
public void init (FMLInitializationEvent e) { | |
proxy.registerRecipes(); | |
proxy.registerColorHandler(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment