Added GUI for multimeter

This commit is contained in:
Calclavia 2013-08-03 19:43:10 -04:00
parent 32cbb970f4
commit 30349128f3
9 changed files with 162 additions and 7 deletions

View file

@ -4,6 +4,7 @@ itemGroup.resonantinduction=Resonant Induction
## Blocks ## Blocks
tile.resonantinduction\:tesla.name=Tesla Coil tile.resonantinduction\:tesla.name=Tesla Coil
tile.resonantinduction\:multimeter.name=Multimeter
tile.resonantinduction\:contractor.name=Electromagnetic Contractor tile.resonantinduction\:contractor.name=Electromagnetic Contractor
## Items ## Items

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View file

@ -4,11 +4,14 @@
package resonantinduction; package resonantinduction;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import resonantinduction.base.Vector3; import resonantinduction.base.Vector3;
import resonantinduction.contractor.TileEntityEMContractor; import resonantinduction.contractor.TileEntityEMContractor;
import resonantinduction.fx.FXElectricBolt; import resonantinduction.fx.FXElectricBolt;
import resonantinduction.multimeter.GuiMultimeter;
import resonantinduction.multimeter.TileEntityMultimeter;
import resonantinduction.render.BlockRenderingHandler; import resonantinduction.render.BlockRenderingHandler;
import resonantinduction.render.RenderEMContractor; import resonantinduction.render.RenderEMContractor;
import resonantinduction.render.RenderTesla; import resonantinduction.render.RenderTesla;
@ -40,6 +43,12 @@ public class ClientProxy extends CommonProxy
@Override @Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{ {
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileEntityMultimeter)
{
return new GuiMultimeter(player.inventory, ((TileEntityMultimeter) tileEntity));
}
return null; return null;
} }

View file

@ -4,8 +4,11 @@
package resonantinduction; package resonantinduction;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import resonantinduction.base.Vector3; import resonantinduction.base.Vector3;
import resonantinduction.multimeter.ContainerMultimeter;
import resonantinduction.multimeter.TileEntityMultimeter;
import cpw.mods.fml.common.network.IGuiHandler; import cpw.mods.fml.common.network.IGuiHandler;
/** /**
@ -22,6 +25,12 @@ public class CommonProxy implements IGuiHandler
@Override @Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{ {
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileEntityMultimeter)
{
return new ContainerMultimeter(player.inventory, ((TileEntityMultimeter) tileEntity));
}
return null; return null;
} }

View file

@ -14,6 +14,7 @@ import resonantinduction.contractor.ItemBlockContractor;
import resonantinduction.contractor.TileEntityEMContractor; import resonantinduction.contractor.TileEntityEMContractor;
import resonantinduction.entangler.ItemQuantumEntangler; import resonantinduction.entangler.ItemQuantumEntangler;
import resonantinduction.multimeter.BlockMultimeter; import resonantinduction.multimeter.BlockMultimeter;
import resonantinduction.multimeter.TileEntityMultimeter;
import resonantinduction.tesla.BlockTesla; import resonantinduction.tesla.BlockTesla;
import resonantinduction.tesla.TileEntityTesla; import resonantinduction.tesla.TileEntityTesla;
import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.FMLLog;
@ -27,6 +28,7 @@ import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry; import cpw.mods.fml.common.registry.LanguageRegistry;
@ -69,7 +71,7 @@ public class ResonantInduction
public static final String PREFIX = DOMAIN + ":"; public static final String PREFIX = DOMAIN + ":";
public static final String DIRECTORY = "/assets/" + DOMAIN + "/"; public static final String DIRECTORY = "/assets/" + DOMAIN + "/";
public static final String TEXTURE_DIRECTORY = "textures/"; public static final String TEXTURE_DIRECTORY = "textures/";
public static final String GUI_DIRECTORY = TEXTURE_DIRECTORY + "/gui"; public static final String GUI_DIRECTORY = TEXTURE_DIRECTORY + "gui/";
public static final String BLOCK_TEXTURE_DIRECTORY = TEXTURE_DIRECTORY + "blocks/"; public static final String BLOCK_TEXTURE_DIRECTORY = TEXTURE_DIRECTORY + "blocks/";
public static final String ITEM_TEXTURE_DIRECTORY = TEXTURE_DIRECTORY + "items/"; public static final String ITEM_TEXTURE_DIRECTORY = TEXTURE_DIRECTORY + "items/";
public static final String MODEL_TEXTURE_DIRECTORY = TEXTURE_DIRECTORY + "models/"; public static final String MODEL_TEXTURE_DIRECTORY = TEXTURE_DIRECTORY + "models/";
@ -114,6 +116,7 @@ public class ResonantInduction
public void preInit(FMLPreInitializationEvent evt) public void preInit(FMLPreInitializationEvent evt)
{ {
LOGGER.setParent(FMLLog.getLogger()); LOGGER.setParent(FMLLog.getLogger());
NetworkRegistry.instance().registerGuiHandler(this, this.proxy);
CONFIGURATION.load(); CONFIGURATION.load();
@ -128,17 +131,17 @@ public class ResonantInduction
// Blocks // Blocks
blockTesla = new BlockTesla(getNextBlockID()); blockTesla = new BlockTesla(getNextBlockID());
blockMultimeter = new BlockMultimeter(getNextBlockID()); blockMultimeter = new BlockMultimeter(getNextBlockID());
GameRegistry.registerBlock(blockTesla, blockTesla.getUnlocalizedName());
GameRegistry.registerBlock(blockMultimeter, blockMultimeter.getUnlocalizedName());
blockEMContractor = new BlockEMContractor(getNextBlockID()); blockEMContractor = new BlockEMContractor(getNextBlockID());
GameRegistry.registerBlock(blockEMContractor, ItemBlockContractor.class, blockEMContractor.getUnlocalizedName());
CONFIGURATION.save(); CONFIGURATION.save();
GameRegistry.registerBlock(blockTesla, blockTesla.getUnlocalizedName());
GameRegistry.registerBlock(blockMultimeter, blockMultimeter.getUnlocalizedName());
GameRegistry.registerBlock(blockEMContractor, ItemBlockContractor.class, blockEMContractor.getUnlocalizedName());
// Tiles // Tiles
GameRegistry.registerTileEntity(TileEntityTesla.class, blockTesla.getUnlocalizedName()); GameRegistry.registerTileEntity(TileEntityTesla.class, blockTesla.getUnlocalizedName());
GameRegistry.registerTileEntity(TileEntityMultimeter.class, blockMultimeter.getUnlocalizedName());
GameRegistry.registerTileEntity(TileEntityEMContractor.class, blockEMContractor.getUnlocalizedName()); GameRegistry.registerTileEntity(TileEntityEMContractor.class, blockEMContractor.getUnlocalizedName());
ResonantInduction.proxy.registerRenderers(); ResonantInduction.proxy.registerRenderers();

View file

@ -3,7 +3,12 @@
*/ */
package resonantinduction.multimeter; package resonantinduction.multimeter;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import resonantinduction.ResonantInduction;
import resonantinduction.base.BlockBase; import resonantinduction.base.BlockBase;
/** /**
@ -12,11 +17,23 @@ import resonantinduction.base.BlockBase;
* @author Calclavia * @author Calclavia
* *
*/ */
public class BlockMultimeter extends BlockBase public class BlockMultimeter extends BlockBase implements ITileEntityProvider
{ {
public BlockMultimeter(int id) public BlockMultimeter(int id)
{ {
super("multimeter", id, Material.iron); super("multimeter", id, Material.iron);
} }
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9)
{
entityPlayer.openGui(ResonantInduction.INSTNACE, 0, world, x, y, z);
return true;
}
@Override
public TileEntity createNewTileEntity(World world)
{
return new TileEntityMultimeter();
}
} }

View file

@ -0,0 +1,43 @@
/**
*
*/
package resonantinduction.multimeter;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
/**
* @author Calclavia
*
*/
public class ContainerMultimeter extends Container
{
private final int yDisplacement = 0;
public ContainerMultimeter(InventoryPlayer inventoryPlayer, TileEntityMultimeter tileEntity)
{
int i;
for (i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18 + yDisplacement));
}
}
for (i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142 + yDisplacement));
}
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer)
{
return true;
}
}

View file

@ -0,0 +1,55 @@
/**
*
*/
package resonantinduction.multimeter;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import resonantinduction.ResonantInduction;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Multimeter GUI
*
* @author Calclavia
*
*/
@SideOnly(Side.CLIENT)
public class GuiMultimeter extends GuiContainer
{
private static final ResourceLocation TEXTURE = new ResourceLocation(ResonantInduction.DOMAIN, ResonantInduction.GUI_DIRECTORY + "gui_base.png");
TileEntityMultimeter tileEntity;
private int containerWidth;
private int containerHeight;
public GuiMultimeter(InventoryPlayer inventoryPlayer, TileEntityMultimeter tileEntity)
{
super(new ContainerMultimeter(inventoryPlayer, tileEntity));
this.tileEntity = tileEntity;
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
String s = this.tileEntity.getBlockType().getLocalizedName();
this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 6, 4210752);
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y)
{
this.containerWidth = (this.width - this.xSize) / 2;
this.containerHeight = (this.height - this.ySize) / 2;
this.mc.renderEngine.func_110577_a(TEXTURE);
GL11.glColor4f(1, 1, 1, 1);
this.drawTexturedModalRect(this.containerWidth, this.containerHeight, 0, 0, this.xSize, this.ySize);
}
}

View file

@ -0,0 +1,18 @@
/**
*
*/
package resonantinduction.multimeter;
import resonantinduction.base.TileEntityBase;
/**
* @author Calclavia
*
*/
public class TileEntityMultimeter extends TileEntityBase
{
public boolean canUpdate()
{
return false;
}
}