Skip to content

Instantly share code, notes, and snippets.

@ollieread
Last active August 29, 2015 14:02
Show Gist options
  • Save ollieread/05da74aa17eaf301ae79 to your computer and use it in GitHub Desktop.
Save ollieread/05da74aa17eaf301ae79 to your computer and use it in GitHub Desktop.
package com.ollieread.technomagi.block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import com.ollieread.technomagi.TechnoMagi;
import com.ollieread.technomagi.common.CommonProxy;
import com.ollieread.technomagi.common.Reference;
import com.ollieread.technomagi.tileentity.TileEntityNaniteReplicator;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockNaniteReplicator extends BlockOwnable
{
public BlockNaniteReplicator(String name)
{
super(Material.iron, name);
setBlockTextureName("construct");
}
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister register)
{
blockIcon = register.registerIcon(Reference.MODID.toLowerCase() + ":" + getTextureName());
}
@Override
public TileEntity createNewTileEntity(World var1, int var2)
{
return new TileEntityNaniteReplicator();
}
@Override
public int getRenderType()
{
return -1;
}
public boolean renderAsNormalBlock()
{
return false;
}
public boolean isOpaqueCube()
{
return false;
}
public boolean canPlaceBlockAt(World world, int x, int y, int z)
{
if (!world.isAirBlock(x, y + 1, z)) {
return false;
}
return true;
}
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)
{
if (world.isRemote) {
return true;
} else {
TileEntityNaniteReplicator entity = (TileEntityNaniteReplicator) world.getTileEntity(x, y, z);
if (entity != null) {
if (entity.isPlayer(player)) {
player.openGui(TechnoMagi.instance, CommonProxy.GUI_REPLICATOR, world, x, y, z);
} else {
System.out.println(entity.getPlayer());
}
}
return true;
}
}
}
package com.ollieread.technomagi.common;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import com.ollieread.technomagi.client.gui.GuiNaniteReplicator;
import com.ollieread.technomagi.client.gui.GuiSelf;
import com.ollieread.technomagi.client.gui.GuiSpecialisation;
import com.ollieread.technomagi.event.handler.PlayerEventHandler;
import com.ollieread.technomagi.event.handler.TMEventHandler;
import com.ollieread.technomagi.event.handler.TickEventHandler;
import com.ollieread.technomagi.inventory.ContainerNaniteReplicator;
import com.ollieread.technomagi.player.PlayerKnowledge;
import com.ollieread.technomagi.tileentity.TileEntityNaniteReplicator;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.IGuiHandler;
public class CommonProxy implements IGuiHandler
{
public static int GUI_TECHNOMAGI = 1;
public static int GUI_SPECIALISATION = 2;
public static int GUI_REPLICATOR = 3;
public static PlayerEventHandler playerEventHandler = new PlayerEventHandler();
private static final Map<String, NBTTagCompound> extendedEntityData = new HashMap<String, NBTTagCompound>();
public static void storeEntityData(String name, NBTTagCompound compound)
{
extendedEntityData.put(name, compound);
}
public static NBTTagCompound getEntityData(String name)
{
return extendedEntityData.remove(name);
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
if (ID == GUI_REPLICATOR) {
TileEntityNaniteReplicator replicator = (TileEntityNaniteReplicator) world.getTileEntity(x, y, z);
if (replicator != null) {
return new ContainerNaniteReplicator(player.inventory, replicator);
}
}
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
if (ID == GUI_TECHNOMAGI) {
PlayerKnowledge charon = PlayerKnowledge.get(player);
if (charon.canSpecialise()) {
return new GuiSpecialisation();
} else {
return new GuiSelf();
}
} else if (ID == GUI_REPLICATOR) {
TileEntityNaniteReplicator replicator = (TileEntityNaniteReplicator) world.getTileEntity(x, y, z);
if (replicator != null) {
return new GuiNaniteReplicator(player.inventory, replicator);
}
}
return null;
}
public void registerEventHandlers()
{
MinecraftForge.EVENT_BUS.register(playerEventHandler);
MinecraftForge.EVENT_BUS.register(new TMEventHandler());
FMLCommonHandler.instance().bus().register(new TickEventHandler());
}
public EntityPlayer getClientPlayer()
{
return null;
}
public void init()
{
}
public ModelBiped getArmorModel(int id)
{
return null;
}
}
package com.ollieread.technomagi.inventory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import com.ollieread.technomagi.tileentity.TileEntityNaniteReplicator;
public class ContainerNaniteReplicator extends Container
{
private TileEntityNaniteReplicator replicator;
public ContainerNaniteReplicator(InventoryPlayer playerInventory, TileEntityNaniteReplicator tile)
{
replicator = tile;
addSlotToContainer(new Slot(replicator, 0, 5, 26));
addSlotToContainer(new SlotResult(replicator, 1, 164, 26));
addSlotToContainer(new SlotNanites(replicator, 2, 164, 61, true));
int i;
for (i = 0; i < 3; ++i) {
for (int j = 0; j < 9; ++j) {
addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 13 + j * 18, 95 + i * 18));
}
}
for (i = 0; i < 9; ++i) {
addSlotToContainer(new Slot(playerInventory, i, 13 + i * 18, 153));
}
addPlayerSlots(playerInventory);
}
@Override
public boolean canInteractWith(EntityPlayer player)
{
return true;
}
public void addPlayerSlots(InventoryPlayer playerInventory)
{
}
}
package com.ollieread.technomagi.client.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import com.ollieread.technomagi.common.Reference;
import com.ollieread.technomagi.inventory.ContainerNaniteReplicator;
import com.ollieread.technomagi.tileentity.TileEntityNaniteReplicator;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiNaniteReplicator extends GuiContainer
{
protected int xSize = 185;
protected int ySize = 177;
protected int xOffset;
protected int yOffset;
private static final ResourceLocation texture = new ResourceLocation(Reference.MODID.toLowerCase(), "textures/gui/replicator.png");
public GuiNaniteReplicator(InventoryPlayer playerInventory, TileEntityNaniteReplicator tile)
{
super(new ContainerNaniteReplicator(playerInventory, tile));
}
public void initGui()
{
this.guiLeft = (this.width - this.xSize) / 2;
this.guiTop = (this.height - this.ySize) / 2;
}
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
this.fontRendererObj.drawString(I18n.format("technomagi.replicator.gui"), 7, 9, 16777215);
}
@Override
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(texture);
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment