This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
louitzie's profile picture

[Help] please can someone port this Gui to SMP

Started by louitzie, 27 May 2012 - 09:04 PM
louitzie #1
Posted 27 May 2012 - 11:04 PM
i give up

can someone please port this gui to smp

gui and container classer are GuiPrinter and ContainerPrinter

Client
BlockPrinter



package net.minecraft.src;

import java.util.Random;

public class BlockPrinter extends BlockContainer
{
protected BlockPrinter(int par1)
	{
		super(par1, 1, Material.circuits);
	}
	/**
	 * Returns the TileEntity used by this block.
	 */
	public TileEntity getBlockEntity()
	{
		return new TileEntityPrinter();
	}

	private void setDefaultDirection(World par1World, int par2, int par3, int par4)
	{
		if (!par1World.isRemote)
		{
			int var5 = par1World.getBlockId(par2, par3, par4 - 1);
			int var6 = par1World.getBlockId(par2, par3, par4 + 1);
			int var7 = par1World.getBlockId(par2 - 1, par3, par4);
			int var8 = par1World.getBlockId(par2 + 1, par3, par4);
			byte var9 = 0;

			if (Block.opaqueCubeLookup[var5] && !Block.opaqueCubeLookup[var6])
			{
				var9 = 0;
			}

			if (Block.opaqueCubeLookup[var6] && !Block.opaqueCubeLookup[var5])
			{
				var9 = 1;
			}

			if (Block.opaqueCubeLookup[var7] && !Block.opaqueCubeLookup[var8])
			{
				var9 = 3;
			}

			if (Block.opaqueCubeLookup[var8] && !Block.opaqueCubeLookup[var7])
			{
				var9 = 2;
			}

			par1World.setBlockMetadataWithNotify(par2, par3, par4, var9);
		}
	}

	public void onBlockAdded(World par1World, int par2, int par3, int par4)
	{
		super.onBlockAdded(par1World, par2, par3, par4);
		this.setDefaultDirection(par1World, par2, par3, par4);
	}

	public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving)
	{
		int var6 = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

		if (var6 == 0)
		{
			par1World.setBlockMetadataWithNotify(par2, par3, par4, 1);
		}

		if (var6 == 1)
		{
			par1World.setBlockMetadataWithNotify(par2, par3, par4, 3);
		}

		if (var6 == 2)
		{
			par1World.setBlockMetadataWithNotify(par2, par3, par4, 0);
		}

		if (var6 == 3)
		{
			par1World.setBlockMetadataWithNotify(par2, par3, par4, 2);
		}
	}

	public int getBlockTextureFromSideAndMetadata(int par1, int par2)
	{
		if (par1==0 || par1==1)
		{
		 return mod_CCPrinter.top;
		}
		else if ((par1==2 && (par2&3)==1) || (par1==3 && (par2&3)==0) || (par1==4 && (par2&3)==2) || (par1==5 && (par2&3)==3))
		{
		 int meta=par2&12;
		 if (meta==12)
		 {
		 return mod_CCPrinter.paperandprinted;
		 }
		 else if (meta==8)
		 {
		 return mod_CCPrinter.papernotprinted;
		 }
		 else if (meta==4)
		 {
		 return mod_CCPrinter.nopaperbutprinted;
		 }
		 else
		 {
		 return mod_CCPrinter.nopapernotprinted;
		 }
		}
		return mod_CCPrinter.side;
	}

	public boolean blockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
	{
		if (par1World.isRemote)
		{
			return true;
		}
		else
		{
		 TileEntityPrinter var6 = (TileEntityPrinter)par1World.getBlockTileEntity(par2, par3, par4);
		 if ((par5EntityPlayer.inventory.getCurrentItem()!=null && par5EntityPlayer.inventory.getCurrentItem().getItem()==Item.paper) || (par5EntityPlayer.inventory.getCurrentItem()!=null && par5EntityPlayer.inventory.getCurrentItem().getItem()==mod_CCPrinter.printedpaper))
		 {
		 ItemStack item = var6.getStackInSlot(4);
		 var6.setInventorySlotContents(4, par5EntityPlayer.inventory.getCurrentItem());
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, item);
		 }
		 else if (par5EntityPlayer.inventory.getCurrentItem()!=null && par5EntityPlayer.inventory.getCurrentItem().getItem()==Item.dyePowder && par5EntityPlayer.inventory.getCurrentItem().getItemDamage()==4)
		 {
		 ItemStack item = var6.getStackInSlot(3);
		 var6.setInventorySlotContents(3, par5EntityPlayer.inventory.getCurrentItem());
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, item);
		 }
		 else if (par5EntityPlayer.inventory.getCurrentItem()!=null && par5EntityPlayer.inventory.getCurrentItem().getItem()==Item.dyePowder && par5EntityPlayer.inventory.getCurrentItem().getItemDamage()==2)
		 {
		 ItemStack item = var6.getStackInSlot(2);
		 var6.setInventorySlotContents(2, par5EntityPlayer.inventory.getCurrentItem());
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, item);
		 }
		 else if (par5EntityPlayer.inventory.getCurrentItem()!=null && par5EntityPlayer.inventory.getCurrentItem().getItem()==Item.dyePowder && par5EntityPlayer.inventory.getCurrentItem().getItemDamage()==1)
		 {
		 ItemStack item = var6.getStackInSlot(1);
		 var6.setInventorySlotContents(1, par5EntityPlayer.inventory.getCurrentItem());
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, item);
		 }
		 else if (par5EntityPlayer.inventory.getCurrentItem()!=null && par5EntityPlayer.inventory.getCurrentItem().getItem()==Item.dyePowder && par5EntityPlayer.inventory.getCurrentItem().getItemDamage()==0)
		 {
		 ItemStack item = var6.getStackInSlot(0);
		 var6.setInventorySlotContents(0, par5EntityPlayer.inventory.getCurrentItem());
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, item);
		 }
		 else if (par5EntityPlayer.inventory.getCurrentItem()==null)
		 {
		 if (var6.getStackInSlot(5)!=null)
		 {
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, var6.getStackInSlot(5));
		 var6.setInventorySlotContents(5, null);
		 }
		 else if (var6.getStackInSlot(4)!=null)
		 {
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, var6.getStackInSlot(4));
		 var6.setInventorySlotContents(4, null);
		 }
		 else if (var6.getStackInSlot(3)!=null)
		 {
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, var6.getStackInSlot(3));
		 var6.setInventorySlotContents(3, null);
		 }
		 else if (var6.getStackInSlot(2)!=null)
		 {
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, var6.getStackInSlot(2));
		 var6.setInventorySlotContents(2, null);
		 }
		 else if (var6.getStackInSlot(1)!=null)
		 {
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, var6.getStackInSlot(1));
		 var6.setInventorySlotContents(1, null);
		 }
		 else if (var6.getStackInSlot(0)!=null)
		 {
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, var6.getStackInSlot(0));
		 var6.setInventorySlotContents(0, null);
		 }
		 }
		 else
		 {
			 if (var6 != null)
			 {
			 ModLoader.openGUI(par5EntityPlayer, new GuiPrinter(par5EntityPlayer.inventory, var6));
			 }
		 }
			return true;
		}
	}
}

mod_CCPrinter


package net.minecraft.src;

import net.minecraft.src.forge.IGuiHandler;
import net.minecraft.src.forge.MinecraftForge;

public class mod_CCPrinter extends BaseMod
{
@MLProp public static int BlockID = 211;
@MLProp public static int ItemID = 4001;
@MLProp public static int capacity = 1280;
@MLProp public static int GuiID = 120;
public static Block printer;
public static ItemPrintedPaper printedpaper;
public static int paper = ModLoader.addOverride("/gui/items.png", "/img/icon.png");
public static int top = ModLoader.addOverride("/terrain.png", "/img/top.png");
public static int side = ModLoader.addOverride("/terrain.png", "/img/side.png");
public static int papernotprinted = ModLoader.addOverride("/terrain.png", "/img/papernotprinted.png");
public static int paperandprinted = ModLoader.addOverride("/terrain.png", "/img/paperandprinted.png");
public static int nopaperbutprinted = ModLoader.addOverride("/terrain.png", "/img/nopaperbutprinted.png");
public static int nopapernotprinted = ModLoader.addOverride("/terrain.png", "/img/nopapernotprinted.png");
@Override
public String getVersion() {
// TODO Auto-generated method stub
return "CC Printer 1.2.5";
}
@Override
public void load() {
// TODO Auto-generated method stub
printer = new BlockPrinter(BlockID).setHardness(1.0F).setBlockName("printer").setRequiresSelfNotify();
printedpaper = (ItemPrintedPaper)(new ItemPrintedPaper(ItemID)).setIconIndex(paper).setItemName("printedpaper");
ModLoader.addName(printedpaper, "Sheet");
ModLoader.registerBlock(printer);
ModLoader.addName(printer, "Printer");
ModLoader.addRecipe(new ItemStack(printer, 1, 1), new Object[] {"C",'C' , Block.dirt});
ModLoader.registerTileEntity(TileEntityPrinter.class, "printer");
}
}

Server
BlockPrinter


package net.minecraft.src;

import java.util.Random;

import net.minecraft.src.forge.MinecraftForge;

public class BlockPrinter extends BlockContainer
{
protected BlockPrinter(int par1)
	{
		super(par1, 1, Material.circuits);
	}
	/**
	 * Returns the TileEntity used by this block.
	 */
	public TileEntity getBlockEntity()
	{
		return new TileEntityPrinter();
	}

	private void setDefaultDirection(World par1World, int par2, int par3, int par4)
	{
		if (!par1World.isRemote)
		{
			int var5 = par1World.getBlockId(par2, par3, par4 - 1);
			int var6 = par1World.getBlockId(par2, par3, par4 + 1);
			int var7 = par1World.getBlockId(par2 - 1, par3, par4);
			int var8 = par1World.getBlockId(par2 + 1, par3, par4);
			byte var9 = 0;

			if (Block.opaqueCubeLookup[var5] && !Block.opaqueCubeLookup[var6])
			{
				var9 = 0;
			}

			if (Block.opaqueCubeLookup[var6] && !Block.opaqueCubeLookup[var5])
			{
				var9 = 1;
			}

			if (Block.opaqueCubeLookup[var7] && !Block.opaqueCubeLookup[var8])
			{
				var9 = 3;
			}

			if (Block.opaqueCubeLookup[var8] && !Block.opaqueCubeLookup[var7])
			{
				var9 = 2;
			}

			par1World.setBlockMetadataWithNotify(par2, par3, par4, var9);
		}
	}

	public void onBlockAdded(World par1World, int par2, int par3, int par4)
	{
		super.onBlockAdded(par1World, par2, par3, par4);
		this.setDefaultDirection(par1World, par2, par3, par4);
	}

	public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving)
	{
		int var6 = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

		if (var6 == 0)
		{
			par1World.setBlockMetadataWithNotify(par2, par3, par4, 1);
		}

		if (var6 == 1)
		{
			par1World.setBlockMetadataWithNotify(par2, par3, par4, 3);
		}

		if (var6 == 2)
		{
			par1World.setBlockMetadataWithNotify(par2, par3, par4, 0);
		}

		if (var6 == 3)
		{
			par1World.setBlockMetadataWithNotify(par2, par3, par4, 2);
		}
	}

	public boolean blockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
	{
		if (par1World.isRemote)
		{
			return true;
		}
		else
		{
		 TileEntityPrinter var6 = (TileEntityPrinter)par1World.getBlockTileEntity(par2, par3, par4);
		 if ((par5EntityPlayer.inventory.getCurrentItem()!=null && par5EntityPlayer.inventory.getCurrentItem().getItem()==Item.paper) || (par5EntityPlayer.inventory.getCurrentItem()!=null && par5EntityPlayer.inventory.getCurrentItem().getItem()==mod_CCPrinter.printedpaper))
		 {
		 ItemStack item = var6.getStackInSlot(4);
		 var6.setInventorySlotContents(4, par5EntityPlayer.inventory.getCurrentItem());
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, item);
		 }
		 else if (par5EntityPlayer.inventory.getCurrentItem()!=null && par5EntityPlayer.inventory.getCurrentItem().getItem()==Item.dyePowder && par5EntityPlayer.inventory.getCurrentItem().getItemDamage()==4)
		 {
		 ItemStack item = var6.getStackInSlot(3);
		 var6.setInventorySlotContents(3, par5EntityPlayer.inventory.getCurrentItem());
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, item);
		 }
		 else if (par5EntityPlayer.inventory.getCurrentItem()!=null && par5EntityPlayer.inventory.getCurrentItem().getItem()==Item.dyePowder && par5EntityPlayer.inventory.getCurrentItem().getItemDamage()==2)
		 {
		 ItemStack item = var6.getStackInSlot(2);
		 var6.setInventorySlotContents(2, par5EntityPlayer.inventory.getCurrentItem());
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, item);
		 }
		 else if (par5EntityPlayer.inventory.getCurrentItem()!=null && par5EntityPlayer.inventory.getCurrentItem().getItem()==Item.dyePowder && par5EntityPlayer.inventory.getCurrentItem().getItemDamage()==1)
		 {
		 ItemStack item = var6.getStackInSlot(1);
		 var6.setInventorySlotContents(1, par5EntityPlayer.inventory.getCurrentItem());
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, item);
		 }
		 else if (par5EntityPlayer.inventory.getCurrentItem()!=null && par5EntityPlayer.inventory.getCurrentItem().getItem()==Item.dyePowder && par5EntityPlayer.inventory.getCurrentItem().getItemDamage()==0)
		 {
		 ItemStack item = var6.getStackInSlot(0);
		 var6.setInventorySlotContents(0, par5EntityPlayer.inventory.getCurrentItem());
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, item);
		 }
		 else if (par5EntityPlayer.inventory.getCurrentItem()==null)
		 {
		 if (var6.getStackInSlot(5)!=null)
		 {
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, var6.getStackInSlot(5));
		 var6.setInventorySlotContents(5, null);
		 }
		 else if (var6.getStackInSlot(4)!=null)
		 {
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, var6.getStackInSlot(4));
		 var6.setInventorySlotContents(4, null);
		 }
		 else if (var6.getStackInSlot(3)!=null)
		 {
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, var6.getStackInSlot(3));
		 var6.setInventorySlotContents(3, null);
		 }
		 else if (var6.getStackInSlot(2)!=null)
		 {
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, var6.getStackInSlot(2));
		 var6.setInventorySlotContents(2, null);
		 }
		 else if (var6.getStackInSlot(1)!=null)
		 {
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, var6.getStackInSlot(1));
		 var6.setInventorySlotContents(1, null);
		 }
		 else if (var6.getStackInSlot(0)!=null)
		 {
		 par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, var6.getStackInSlot(0));
		 var6.setInventorySlotContents(0, null);
		 }
		 }
		 else
		 {
			 if (var6 != null)
			 {
			
			 }
		 }
			return true;
		}
	}
}

mod_CCPrinter


package net.minecraft.src;

import net.minecraft.src.forge.IGuiHandler;
import net.minecraft.src.forge.MinecraftForge;

public class mod_CCPrinter extends BaseMod
{
@MLProp public static int BlockID = 211;
@MLProp public static int ItemID = 4001;
@MLProp public static int capacity = 1280;
@MLProp public static int GuiID = 120;
public static Block printer;
public static ItemPrintedPaper printedpaper;
public static int paper = ModLoader.addOverride("/gui/items.png", "/img/icon.png");
public static int top = ModLoader.addOverride("/terrain.png", "/img/top.png");
public static int side = ModLoader.addOverride("/terrain.png", "/img/side.png");
public static int papernotprinted = ModLoader.addOverride("/terrain.png", "/img/papernotprinted.png");
public static int paperandprinted = ModLoader.addOverride("/terrain.png", "/img/paperandprinted.png");
public static int nopaperbutprinted = ModLoader.addOverride("/terrain.png", "/img/nopaperbutprinted.png");
public static int nopapernotprinted = ModLoader.addOverride("/terrain.png", "/img/nopapernotprinted.png");
@Override
public String getVersion() {
// TODO Auto-generated method stub
return "CC Printer 1.2.5";
}
@Override
public void load() {
// TODO Auto-generated method stub
printer = new BlockPrinter(BlockID).setHardness(1.0F).setBlockName("printer").setRequiresSelfNotify();
printedpaper = (ItemPrintedPaper)(new ItemPrintedPaper(ItemID)).setIconIndex(paper).setItemName("printedpaper");
ModLoader.addName(printedpaper, "Sheet");
ModLoader.registerBlock(printer);
ModLoader.addName(printer, "Printer");
ModLoader.addRecipe(new ItemStack(printer, 1, 1), new Object[] {"C",'C' , Block.dirt});
ModLoader.registerTileEntity(TileEntityPrinter.class, "printer");
}
}

if this is done i can release an awesome peripheral wich can print pixels and characters on sheets like maps
Xfel #2
Posted 28 May 2012 - 06:19 AM
If you would provide the full source code, it would be much easier. I don't know what your gui does, so i can't port it. Aslo please provide it as file download, you can get all mod files with the getchangedsource script from mcp. Just pack these into a zip file, that's much easier to read. But if you could do that, i might be able to help you.
louitzie #3
Posted 28 May 2012 - 09:47 AM
ok i'll do that but first i'll upload the SSP mod

EDIT: i have send the mod to you XFel