Created
July 6, 2016 05:19
-
-
Save robotgryphon/6cd82100cd518ce1d61529f07ad4c99c to your computer and use it in GitHub Desktop.
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 net.minecraftforge.test; | |
import net.minecraft.client.gui.GuiScreen; | |
import net.minecraft.entity.Entity; | |
import net.minecraft.entity.EntityLiving; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.nbt.NBTTagCompound; | |
import net.minecraft.util.EnumFacing; | |
import net.minecraft.util.EnumHand; | |
import net.minecraft.world.BossInfo; | |
import net.minecraft.world.World; | |
import net.minecraftforge.common.capabilities.Capability; | |
import net.minecraftforge.common.gui.CapabilityEntityGui; | |
import net.minecraftforge.common.gui.IEntityGuiProvider; | |
import net.minecraftforge.common.gui.IGuiHandler; | |
import net.minecraftforge.fml.common.Mod; | |
import net.minecraftforge.fml.common.event.FMLInitializationEvent; | |
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; | |
import net.minecraftforge.fml.common.registry.EntityRegistry; | |
import net.minecraftforge.fml.common.registry.GameRegistry; | |
import javax.annotation.Nullable; | |
import javax.vecmath.Vector3f; | |
import java.awt.*; | |
@Mod(modid = "entitygui", name = "Entity Gui Capability Test") | |
public class TestEntityGui | |
{ | |
@Mod.Instance("entitygui") public static TestEntityGui INSTANCE; | |
final boolean ENABLE = true; | |
@Mod.EventHandler | |
public void preInit(FMLPreInitializationEvent event) | |
{ | |
if(!ENABLE) return; | |
} | |
public void init(FMLInitializationEvent ev){ | |
if(!ENABLE) return; | |
EntityRegistry.registerModEntity(EntityBlob.class, "blob", 1, INSTANCE, 1, 10, true, Color.BLACK.getRGB(), Color.BLUE.getRGB()); | |
} | |
private class EntityBlobGuiHandler implements IEntityGuiProvider { | |
@Override public Object getClientGuiElement(EntityPlayer player, World world, Entity entity) | |
{ | |
if(entity instanceof EntityBlob) return new GuiBlob((EntityBlob) entity); | |
return null; | |
} | |
@Override public Object getServerGuiElement(EntityPlayer player, World world, Entity entity) | |
{ | |
return null; | |
} | |
} | |
private class EntityBlob extends EntityLiving | |
{ | |
public EntityBlob(World world, Vector3f pos){ | |
super(world); | |
setPosition(pos.getX(), pos.getY(), pos.getZ()); | |
} | |
@Override protected boolean processInteract(EntityPlayer player, EnumHand hand, @Nullable ItemStack stack) | |
{ | |
if(!this.worldObj.isRemote) { | |
player.openEntityGui(this); | |
return true; | |
} | |
return super.processInteract(player, hand, stack); | |
} | |
@Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) | |
{ | |
if(capability.equals(CapabilityEntityGui.class)) return true; | |
return super.hasCapability(capability, facing); | |
} | |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) | |
{ | |
if(capability.equals(CapabilityEntityGui.ENTITY_GUI_CAPABILITY)) return (T) new EntityBlobGuiHandler(); | |
return super.getCapability(capability, facing); | |
} | |
} | |
private class GuiBlob extends GuiScreen | |
{ | |
public GuiBlob(EntityBlob blob) | |
{ | |
} | |
@Override public void drawScreen(int mouseX, int mouseY, float partialTicks) | |
{ | |
super.drawScreen(mouseX, mouseY, partialTicks); | |
drawDefaultBackground(); | |
drawString(fontRendererObj, "HAI!", 10, 10, Color.WHITE.getRGB()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment