Jump to content

Flenix

Members
  • Posts

    440
  • Joined

  • Last visited

Posts posted by Flenix

  1. Hey guys.

     

    I'm giving ISBRH another try in my FlenixRoads rewrite. So far it's going pretty well, but I need to add ambient occlusion to my renders.

     

    Can anyone guide me with it? My blocks are relatively simple six-sided shapes, just they change their heights (including non-square shapes) depending on their surroundings hence the need for ISBRH. Currently they seem to pass light through, which means they don't cast any form of shadow and it's hard to differentiate between the top and sides:

    53c1b9a428d6a.jpg

    (Stone is there for reference)

     

    Ordinastie sent me this on IRC, but it looks to be extremely overcomplicated for what I'm trying to achieve. Can anyone push me in the right direction of doing this in a slightly simpler manor?

     

  2. Kill your region files which is what will be the main size of your world and let it run the update.

    Then replace the region files.

    it SHOULD be fine compressing a 15GB world, unless your computer is to slow.

    But ya, for now there is no config option for this.

     

    Kill my region files...? Wouldn't that effectively just delete the world?

     

    It's on a server not a local PC. 32GB RAM and an Intel Xeon, I was kinda surprised when it hung too if I'm honest. Just copying the files doesn't take long at all.

     

    Could some sort of bypass be considered for future updates? I'm sure I'm not the only person who will have this issue and I see no harm in adding one :P

  3. Hey guys.

     

    Got a simple but annoying bug here.

     

    I updated a few mods on my server, and that caused one ID to change (from aobd: a mod which dynamically adds/removes ore parts for compatability between mods as they are required).

     

    Forge informed me I had the option to continue loading the world, or abort it. If I continue, Forge will kindly make a backup of my world.

     

    If I select continue, Forge attempts to backup my 15gb world. But, due to the size, the server just hangs and doesn't do anything. I left it for around 45 minutes with no sign of progress - and no sign of any files appearing either.

     

    I'd like to request an option in forge.cfg to decline or disable that auto world backup. The warning itself is still very useful, but this way I can handle the backup myself and it'll be a much faster process for large worlds. Currently, I can't launch my server at all, so I consider this a game-breaking bug.

     

    Using Forge 1147 on 1.7.2 - can't update to 1.7.10 yet due to Buildcraft.

     

    Thanks :)

  4. Hello all.

     

    I've got an ore generation mod which is designed just for use in my modpack. The idea is I disable all ores from the other mods, and just generate my ores with a multiplier, to get "cleaner" worlds. Later I'll add fancy features like anti-xray and stuff, but for now I just want to get ores in the world.

     

    However, world generation with my mod is EXTREMELY laggy. I'm just using the method Wuppy gives on his tutorial, but maybe that's not suitable for generating around 50 different ores.

     

    Can anyone recommend a way to optimise things a bit?

     

    Here's my WorldGen class. Note that values are configurable as my modpack is public, so I want other server admins to be able to tweak it how they like.

    http://silvania.co.uk/mods/downloads/files/WorldGen.txt

     

    (I know it's messy. like I said, it was just designed as a modpack tool, not a proper release, so I wasn't focusing too much initially)

     

    Anyone got any tips to make things run a bit smoother?

  5. Under the suggestion of an IRC user, I tried setting the code to the following:

     

    						IFlenixFoods food = ((IFlenixFoods) grill1.getItem());
    						NBTTagCompound tag = new NBTTagCompound();
    						tag.setFloat("cookedValue", cookedValue + 0.01F);
    						grill1.stackTagCompound = tag;
    						setInventorySlotContents(5, grill1);
    						//Slot 5 is temporary for now, because I already check to make sure it's in slot 5. It'll be an if later.
    

     

    This seems to solve the problem of increasing the cookedValue, but at the same time deletes all other saved NBT data; therefore no good.

    Anyone got any other ideas?

  6. Could you post your full updateEntity method?

     

    Not sure how it makes any difference but sure:

    @Override
    public void updateEntity() {
    	ItemStack fuel = getStackInSlot(0);
    	ItemStack hob1 = getStackInSlot(1);
    	ItemStack hob2 = getStackInSlot(2);
    	ItemStack hob3 = getStackInSlot(3);
    	ItemStack hob4 = getStackInSlot(4);
    	ItemStack grill1 = getStackInSlot(5);
    	ItemStack oven1 = getStackInSlot(6);
    	ItemStack oven2 = getStackInSlot(7);
    	int fuelVal = 10000;
    	if (fuelVal > 0) {
    		//Temperature Setting for each section affects cook speed.
    		//Grill 1
    		if (grill1 != null) {
    			if (temperature >= grill1Setting) {
    				if (grill1.getItem() instanceof IFlenixFoods) {
    					NBTTagCompound grill1Tag = grill1.getTagCompound();
    					if (grill1Tag == null) {
    						grill1 = initNBT(grill1);
    					}
    					float localCV = 0.0F;
    					float cookedValue = grill1.stackTagCompound.getFloat("cookedValue");
    					float maxCV = grill1.stackTagCompound.getFloat("burnedLevel");
    					int foodTemp = grill1.stackTagCompound.getInteger("temperature");
    					if (foodTemp >= temperature) {
    						System.out.println("Add to cooked value: " + cookedValue);
    			           		grill1.stackTagCompound.setFloat("cookedValue", cookedValue + 1);
    					} else {
    						grill1.stackTagCompound.setInteger("temperature", foodTemp + 1);
    						System.out.println("Food temp: " + foodTemp);
    					}
    					if (cookedValue <= maxCV) {
    						float cookMultiplier = temperature / 100000;
    						fuelValue = fuelValue - (cookMultiplier * 100);
    						grill1.stackTagCompound.setFloat("cookedValue", cookedValue + cookMultiplier);
    					}
    				}
    			} else {
    				temperature++;
    				System.out.println("Temp: " + temperature);
    			}
    		}
    	}
    }

     

     

    I will point out that other parts of that aren't fully functional, but "Food temp: X" is printed to my log continuously (with X always being the same number regardless of what it's set at)

  7. Hey guys.

     

    So, I've got an item. In the item's class, I have this which is called when the player right-clicks with the item in hand.

     

    	if (!world.isRemote) {
            if (player.isSneaking()) {
                System.out.println("Add to cooked value");
                item.stackTagCompound.setFloat("cookedValue", (item.stackTagCompound.getFloat("cookedValue") + 1));
            }
    	}
    

     

    and it works great, exactly as intended.

     

    However, when I put the same code into my Tile Entities updateEntity() method (item.stackTagCompound.setFloat("cookedValue", (item.stackTagCompound.getFloat("cookedValue") + 1));) it does nothing. I have a println by it, which is called, but the actual value isn't changed.

     

    Anyone got any suggestions as to what I'm doing wrong? :)

     

     

  8. A lot of redstone logic is handled via notification of neighbors rather than update ticks, as well as using the isProvidingStrongPower and isProvidingWeakPower methods. Those both have x/y/z coordinates, so you can check your tile entity's data to return whatever power level you want, all without using update ticks. This way you provide real-time signal strength but only when requested.

     

    I don't suppose you could inform me of any examples (either vanilla or open-source mod?) Not quite sure I follow, I've always been a bit confused by redstone for some reason =/

  9. In the block constructor, setTickRandomly to false. Then add an onUpdate method. Then set the tickRate to 1. Hope this helped.

     

    Couldn't find an "onUpdate" method in block, but found a "updateTick" one - is that what you mean?

     

    Right now, here's my code (Very simple for testing). When I place my block in the world, however, I don't get any of the "Tick!" println =/

     

    package co.uk.silvania.cities.research.blocks.advanced;
    
    import java.util.Random;
    
    import co.uk.silvania.cities.research.FlenixCities_Research;
    import net.minecraft.block.Block;
    import net.minecraft.block.material.Material;
    import net.minecraft.world.World;
    
    public class PlayerDetectorBlock extends Block {
    
    public PlayerDetectorBlock(int id) {
    	super(id, Material.iron);
    	this.setCreativeTab(FlenixCities_Research.tabCitiesResearch);
    	this.setHardness(2.0F);
    	this.setTickRandomly(false);
    }
    
    @Override
    public void updateTick(World world, int x, int y, int z, Random random) {
    	System.out.println("Tick!");
    }
    
    @Override
    public int tickRate(World world) {
    	return 2;
    }
    
    }
    

  10. Hey guys.

     

    I'm working on a block, which works with a Tile Entity. However, the block will emit redstone and I need to control that on a tick-by-tick basis.

     

    What's the best way for me to update my blocks' redstone emission state every tick? I can do it fine in the tile entity side, but it's actually passing that info to the block that I'm a bit confused by.

     

    Thanks :)

  11. You can do this by creating a method in your tile entity to check for the item in the slot like so

     

    public boolean hasBook(int slot)
    {
    // on phone so can't remember method but there is a method in IInventory to check for items in slot
    if(items.unknownMethod[slot] instanceof ItemBook)
          return items.unknownMethod[slot];
    

     

    That would only work for something like Bibliocraft's bookshelf, where the physical item in the slot has no relevance to what is rendered. I need to know what itemstack is in the slot, because I'll be rendering that exact stack

     

    Then do a check in your renderer and if so render that part of the model.

  12. ^^To add on to this, there are two ways around it:

     

    1. When you compile your mod, there is a deobfuscated version in the "bin" folder. You can use the files in there to make an API-version of your mod which other mods can use in development, by telling Eclipse to use them as an external jar.

     

    2. If you place CodeChickenCore in the mods folder of your development environment, any mod in there will be deobfuscated at runtime, meaning you can use absolutely any mod in there, even if it's closed source.

  13. Hey guys,

     

    I want to render some things from a tile entities container physically into the model. However, I'm having a bit of trouble with it.

     

    I believe all I need to do is "sync" the container from the server to the client; but I'm not exactly sure how. My code is failing when doing a null check for the itemstack though, so I think that's a good guess.

     

    Here is my renderer, tile entity, and container. Anyone able to point me in the right direction?

     

    package co.uk.silvania.cities.core.client.models;
    
    import net.minecraft.block.Block;
    import net.minecraft.client.Minecraft;
    import net.minecraft.client.renderer.OpenGlHelper;
    import net.minecraft.client.renderer.Tessellator;
    import net.minecraft.client.renderer.entity.RenderItem;
    import net.minecraft.client.renderer.entity.RenderManager;
    import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.item.EntityItem;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.ResourceLocation;
    import net.minecraft.world.World;
    
    import org.lwjgl.opengl.GL11;
    
    import co.uk.silvania.cities.econ.store.entity.TileEntityAdminShop;
    
    
    public class TileEntityFloatingShelvesRenderer extends TileEntitySpecialRenderer {
    
    private final FloatingShelvesModel model;
    private final RenderItem renderer;
    
    private TileEntityAdminShop shelvesEntity;
    
    public TileEntityFloatingShelvesRenderer() {
    	this.model = new FloatingShelvesModel();
    	this.renderer = new RenderItem();
    
    	renderer.setRenderManager(RenderManager.instance);
    }
    
    @Override
    public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) {
    	this.shelvesEntity = (TileEntityAdminShop) te;
    	int i = te.getBlockMetadata();
    	int meta = 180;
    
    	if (i == 0) {
    		meta = 0;
    	}
    
    	if (i == 3) {
    		meta = 90;
    	}
    
    	if (i == 2) {
    		meta = 180;
    	}
    
    	if (i == 1) {
    		meta = 270;
    	}
    
    	Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation("flenixcities", "textures/entities/floatingshelves.png"));
    	GL11.glPushMatrix();
    	GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
    	GL11.glRotatef(meta, 0.0F, 1.0F, 0.0F);
    	//GL11.glRotatef(((TileEntityBarrierEntity)tile).getRotationPivot()), 0.0F, 1.0F, 0.0F);
    	GL11.glScalef(1.0F, -1F, -1F);
    	this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
    	GL11.glPopMatrix();
    
    	GL11.glPushMatrix();
    	System.out.println("Begin item renderer");
    	if (shelvesEntity.getStackInSlot(0) != null) {
    		System.out.println("Slot 0 contains an item!");
    		EntityItem entity = new EntityItem(te.worldObj);
    		entity.hoverStart = 0.0F;
    		GL11.glTranslated((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
    		GL11.glRotatef(0, 0.0F, 1.0F, 0.0F);
    		entity.setEntityItemStack(shelvesEntity.getStackInSlot(0));
    		System.out.println("Render it now");
    		renderer.doRenderItem(entity, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
    	}
    	System.out.println("End item renderer");
    	GL11.glPopMatrix();
    }
    
    private void adjustLightFixture(World world, int i, int j, int k, Block block) {
    	Tessellator tess = Tessellator.instance;
    	float brightness = block.getBlockBrightness(world, i, j, k);
    	int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0);
    	int modulousModifier = skyLight % 65536;
    	int divModifier = skyLight / 65536;
    	tess.setColorOpaque_F(brightness, brightness, brightness);
    	OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit,  (float) modulousModifier,  divModifier);
    }
    }
    

     

     

    package co.uk.silvania.cities.econ.store.entity;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.inventory.IInventory;
    import net.minecraft.item.ItemStack;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.nbt.NBTTagList;
    import net.minecraft.network.packet.Packet;
    import net.minecraft.tileentity.TileEntity;
    import co.uk.silvania.cities.econ.EconUtils;
    import co.uk.silvania.cities.econ.money.ItemCoin;
    import co.uk.silvania.cities.econ.money.ItemNote;
    
    public class TileEntityAdminShop extends TileEntity implements IInventory {
    
    public String ownerName;
    public String userName;
    private ItemStack[] items;
    public double buyPrice1;
    public double sellPrice1;
    public double buyPrice2;
    public double sellPrice2;
    public double buyPrice3;
    public double sellPrice3;
    public double buyPrice4;
    public double sellPrice4;
    public int tabButton;
    
    @Override
    public void writeToNBT(NBTTagCompound nbt) {
    	super.writeToNBT(nbt);
    	NBTTagList nbtTagList = new NBTTagList();
    	//Credit to Lumien
    	for (int i = 0; i < this.items.length; ++i) {
    		if (this.items[i] != null) {
    			System.out.println("Writing Item in Slot " + i);
    			NBTTagCompound compound = new NBTTagCompound();
    			nbt.setByte("Slot", (byte)i);
    			this.items[i].writeToNBT(compound);
    			nbtTagList.appendTag(compound);
    		}
    	}
    	nbt.setTag("Items",  nbtTagList);
    	nbt.setString("ownerName", ownerName);
    	nbt.setDouble("buyPrice1", buyPrice1);
    	nbt.setDouble("sellPrice1", sellPrice1);
    	nbt.setDouble("buyPrice2", buyPrice2);
    	nbt.setDouble("sellPrice2", sellPrice2);
    	nbt.setDouble("buyPrice3", buyPrice3);
    	nbt.setDouble("sellPrice3", sellPrice3);
    	nbt.setDouble("buyPrice4", buyPrice4);
    	nbt.setDouble("sellPrice4", sellPrice4);
    
    }
    
    @Override
    public void readFromNBT(NBTTagCompound nbt) {
    	super.readFromNBT(nbt);
    	NBTTagList nbtTagList = nbt.getTagList("Items");
    	for (int i = 0; i < nbtTagList.tagCount(); i++) {
    		NBTTagCompound nbt1 = (NBTTagCompound)nbtTagList.tagAt(i);
    		int j = nbt1.getByte("Slot") & 255;
    		System.out.println("Reading Item in Slot " + i + "/" + j);
    		this.items[i] = ItemStack.loadItemStackFromNBT(nbt1);
    	}
    	this.ownerName = nbt.getString("ownerName");
    	this.buyPrice1 = nbt.getDouble("buyPrice1");
    	this.sellPrice1 = nbt.getDouble("sellPrice1");
    	this.buyPrice2 = nbt.getDouble("buyPrice2");
    	this.sellPrice2 = nbt.getDouble("sellPrice2");
    	this.buyPrice3 = nbt.getDouble("buyPrice3");
    	this.sellPrice3 = nbt.getDouble("sellPrice3");
    	this.buyPrice4 = nbt.getDouble("buyPrice4");
    	this.sellPrice4 = nbt.getDouble("sellPrice4");
    
    }
    
    public int getQuantity(int i) {
    	int qty;
    	int startSlot;
    	int endSlot;
    	if (i == 0) {
    
    	} else if (i == 1) {
    
    	} else if (i == 2) {
    
    	} else if (i == 3) {
    
    	}
    	//For loop.
    	return 0;
    }
    
    public boolean isShopOpen() {
    	return true;
    }
    
    public void sellItem(int i, int qty, EntityPlayer entityPlayer) {
    	System.out.println("Beginning Sale Process");
    	double itemCost = 0;
    	if (i == 1) {
    		itemCost = buyPrice1;
    	}
    	if (i == 2) {
    		itemCost = buyPrice2;
    	}
    	if (i == 3) {
    		itemCost = buyPrice3;
    	}
    	if (i == 4) {
    		itemCost = buyPrice4;
    	}
    	double totalItemCost = itemCost * qty;
    	double invCash = EconUtils.getInventoryCash(entityPlayer);
    	System.out.println("Item Cost: " + totalItemCost + ", Inventory Cash: " + EconUtils.getInventoryCash(entityPlayer));
    
    	if (invCash >= totalItemCost) {
    		//Two birds, one stone. Charges the player for us, then tells us how much they paid so we can calculate change.
    		double paidAmount = EconUtils.findCashInInventoryWithChange(entityPlayer, totalItemCost); //Complex code to charge the player's inventory
    		if (paidAmount == 0) {
    			//They didn't pay enough. Don't take the money, and tell 'em to piss off.
    			return;
    		} else {
    			ItemStack item = getStackInSlot(i - 1);
    			System.out.println("Item: " + item);
    			System.out.println("Qty: " + qty);
    			while (qty >= 1) {
    				System.out.println("Giving " + item.stackSize + " items, " + qty + " more stacks of this to go.");
    				entityPlayer.inventory.addItemStackToInventory(new ItemStack(item.getItem(), item.stackSize, item.getItemDamage()));
    				qty--;
    			}
    		}
    	}
    }
    
    
    public TileEntityAdminShop() {
    	items = new ItemStack[4]; //Amount of stacks
    }
    
    @Override
    public int getSizeInventory() {
    	return items.length;
    }
    
    @Override
    public ItemStack getStackInSlot(int i) {
    	return items[i];
    }
    
    @Override
    public ItemStack decrStackSize(int i, int amount) {
    	ItemStack itemStack = getStackInSlot(i);
    
    	if (itemStack != null) {
    		if (itemStack.stackSize <= amount) {
    			setInventorySlotContents(i, null);
    		} else {
    			itemStack = itemStack.splitStack(amount);
    			onInventoryChanged(); //Update the inventory. TODO use this for card removal
    		}
    	}
    	return itemStack;
    }
    
    @Override
    public ItemStack getStackInSlotOnClosing(int i) {
    	ItemStack itemStack = getStackInSlot(i);
    	setInventorySlotContents(i, null);
    	return itemStack;
    }
    
    @Override
    public void setInventorySlotContents(int i, ItemStack itemStack) {
    	if (isItemValidForSlot(i, itemStack)) {
    		items[i] = itemStack;
    
    		if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) {
    			itemStack.stackSize = getInventoryStackLimit();
    		}
    
    		onInventoryChanged();
    	}
    }
    
    public void addMoneyToShopInventory(int i, ItemStack itemStack, double amount) {
    	if (isItemValidForSlot(i, itemStack)) {
    		items[i] = itemStack;
    
    		if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) {
    			itemStack.stackSize = getInventoryStackLimit();
    		}
    
    		onInventoryChanged();
    	}
    }
    
    @Override
    public String getInvName() {
    	return "Floating Shelves";
    }
    
    @Override //Apparently not used...
    public boolean isInvNameLocalized() {
    	return true;
    }
    
    //Max size of stacks placed inside.
    @Override
    public int getInventoryStackLimit() {
    	return 64;
    }
    
    //Checks if the player can use it.
    //Wouldn't work for owner only- if I did that, no one else would be able to interact (Maybe? Need to test that.)
    @Override
    public boolean isUseableByPlayer(EntityPlayer entityPlayer) {
    	return entityPlayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) <= 64;
    }
    
    //Not used
    @Override
    public void openChest() {}
    
    //Not used
    @Override
    public void closeChest() {}
    
    //Checks that the item is valid. For shelves, use instanceof to see if it's item or block.
    @Override
    public boolean isItemValidForSlot(int i, ItemStack item) {
    	ItemStack slot1 = getStackInSlot(0);
    	ItemStack slot2 = getStackInSlot(1);
    	ItemStack slot3 = getStackInSlot(2);
    	ItemStack slot4 = getStackInSlot(3);
    	if (item != null) {
    		if (i > 3 && i <= 39) {
    			return item.itemID == slot1.itemID;
    		}
    		if (i > 39 && i <= 75) {
    			return item.itemID == slot2.itemID;
    		}
    		if (i > 75 && i <= 111) {
    			return item.itemID == slot3.itemID;
    		}
    		if (i > 111 && i <= 147) {
    			return item.itemID == slot4.itemID;
    		}
    		if (i > 147 && i <= 184) {
    			if (item.getItem() instanceof ItemCoin || item.getItem() instanceof ItemNote) {
    				return true;
    			} else {
    				return false;
    			}
    		} if (i > 184) {
    			return false;
    		}
    	}
    	return true;
    }
    }
    

     

     

    package co.uk.silvania.cities.econ.store.container;
    
    import java.util.HashSet;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Set;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.InventoryPlayer;
    import net.minecraft.inventory.Container;
    import net.minecraft.inventory.IInventory;
    import net.minecraft.inventory.Slot;
    import net.minecraft.item.ItemStack;
    import co.uk.silvania.cities.econ.store.entity.TileEntityAdminShop;
    
    public class ContainerAdminShop extends Container {
    
    private TileEntityAdminShop te;
    private IInventory adminShopInventory;
    public static int tabButton;
    
    private int field_94536_g;
    private int field_94535_f = -1;
    private final Set field_94537_h = new HashSet();
    
    public ContainerAdminShop(InventoryPlayer invPlayer, TileEntityAdminShop te) {
    	this.te = te;
    	addSlotToContainer(new Slot(te, 0, 8, 50));
    	addSlotToContainer(new Slot(te, 1, 8, 72));
    	addSlotToContainer(new Slot(te, 2, 8, 94));
    	addSlotToContainer(new Slot(te, 3, 8, 116));
    	bindPlayerInventory(invPlayer);
    }
    
    
    
    protected void bindPlayerInventory(InventoryPlayer invPlayer) {
    	//C = vertical inventory slots, "columns"
    	//R = horizontal inventory slots, "rows"
    	for (int c = 0; c < 3; c++) {
    		for (int r = 0; r < 9; r++) {
    			addSlotToContainer(new Slot(invPlayer, r + c * 9 + 9, 8 + r * 18, 141 + c * 18));
    		}
    	}
    	//H = hotbar slots
    	for (int h = 0; h <9; h++) {
    		addSlotToContainer(new Slot(invPlayer, h, 8 + h * 18, 199));
    	}
    }
    
    @Override
    public boolean canInteractWith(EntityPlayer entityPlayer) {
    	return true;
    }
    
    @Override
        public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
    	ItemStack stack = null;
            Slot slotObject = (Slot) inventorySlots.get(slot);
    
            if (slotObject != null && slotObject.getHasStack()) {
            	ItemStack stackInSlot = slotObject.getStack();
            	stack = stackInSlot.copy();
    
            	if (slot < 9) {
            		if (!this.mergeItemStack(stackInSlot, 9, 45, true)) {
            			return null;
            		}
            	}
    
            	else if (!this.mergeItemStack(stackInSlot, 0, 9, false)) {
            		return null;
            	}
    
            	if (stackInSlot.stackSize == 10) {
            		slotObject.putStack(null);
            	} else {
            		slotObject.onSlotChanged();
            	}
    
            	if (stackInSlot.stackSize == stack.stackSize) {
            		return null;
            	}
            	slotObject.onPickupFromSlot(player, stackInSlot);
            }
            return stack;
    }
    
    @Override
        public void putStackInSlot(int slot, ItemStack item) {
            this.getSlot(slot).putStack(item);
        }
    
    public IInventory getFloatingShelvesInveotry() {
    	return this.adminShopInventory;
    }
    
    @Override
    public ItemStack slotClick(int par1, int par2, int par3, EntityPlayer entityPlayer) {
    	System.out.println("Slot clicked!");
    	if (entityPlayer.capabilities.isCreativeMode) {
    		super.slotClick(par1, par2, par3, entityPlayer);
    	}
    	return null;
    }
    }
    

  14. The way I do it is just move the slots to the "left side" of the screen (set x position to -100 or whatever). That way they are a) not rendered and b) you can't interact with them.

    Then when you want then to be visible, just change their x position to the right value and move the other ones out of the way.

     

    Can you give me an example though? I've always done my slot rendering (and therefore positioning) in the Container class; which as I said is only called on the initial opening.

  15. Hey guys,

     

    I need to know how to create a chest-style block. I've got my container etc, but the items won't save to it on game close.

    I'm guessing there's a tutorial somewhere for that though...

     

    More importantly; I need to have various slots only render and be available at certain times.

    As the Container class is only called once, when you load the container up, I can't just change my slot loading dynamically.

     

    Does anyone know of a way I can? What I need to do is have different slots available and usable depending on which tab of my GUI is open. Everything else for the GUI works (Packets sent to the server so it knows which tab the client is using etc); all I need to do is enable and disable the relevant slots.

    Anyone got any ideas?

     

    (Sorry if this post doesn't make sense, been working on this pretty much all day and very tired now. going to bed to sleep on it for a bit!)

  16. Hey guys,

     

    Got one last snag in my GUIWidgets mod. It's at a usable, releasable stage now, but this graphical bug is annoying me!

     

    Basically, whenever I resize the screen, my text gets distorted. But, not always.

     

    I'm in the process of switching to a slightly better way of rendering items which uses glScalef differently. Unfortunately, the old way of doing it (Read from the vanilla icons texture, scale it up 2.0F) made my text scale perfectly; but when I switched to my new way (Read from a custom png file, already scaled so no need to resize), the text distorts on scale up.

     

    Here's an image which shows what I mean. Health and EXP are on the new system, Hunger is on the old system:

    53008fdb8c337.jpg

     

     

    here's the code for Health. I'm currently popping GL before I get to health and then pushing again, so I KNOW nothing previous will be affecting it.  Below that is the code from hunger where it's all inclusive.

     

    		//render health bar
    		if (config.healthText) {
    			GL11.glPushMatrix();
    			GL11.glScalef(0.5F, 0.5F, 0.5F);
    			font.drawStringWithShadow("Health: " + health + "/" + maxHealth, xPos + 22, yPos + 6, config.healthTextColour);
    			GL11.glPopMatrix();
    		}

     

    		GL11.glPushMatrix();
    		GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);;
    		GL11.glDisable(GL11.GL_LIGHTING);
    		GL11.glScalef(0.5F, 0.5F, 0.5F);
    		mc.renderEngine.bindTexture(guiStatsBar);
    
    		this.drawTexturedModalRect(xPos, yPos, 0, 128, sizeX, sizeY);
    		this.drawTexturedModalRect(xPos + 2, yPos + 2, 0, 76, hungerAmount, 16);
    		this.drawTexturedModalRect(xPos, yPos, 0, 20, sizeX, sizeY);
    
    		this.mc.renderEngine.bindTexture(vanillaIcons);
    		GL11.glScalef(2.0F, 2.0F, 2.0F);
    		this.drawTexturedModalRect(Math.round(xPos / 2) + 1, Math.round(yPos / 2), 16, 36, 9, 9);
    
    		if (config.hungerText) {
    			GL11.glScalef(0.5F, 0.5F, 0.5F);
    			font.drawStringWithShadow("Hunger: " + hunger + "/" + maxHunger, xPos + 22, yPos + 6, config.hungerTextColour);
    		}
    		GL11.glPopMatrix();
    

  17. Realized that what I said about widget transparency might sound a bit confusing; here's a screenshot to try and clear it up:

     

    52fd5379987fa.jpg

     

    The solid white squares should have alpha transparency. You can see the health bar through it, but you can't see the game world.

  18. Make sure you enable glBlend

     

    I have AFAIK- One of the snippets I snagged from the vanilla class.

     

    What's interesting and worth noting that I just discovered via a misconfiguration; If my hotbar renders over another widget, the transparancy DOES affect that widget - it seems to only not work on the game itself.

     

    Here's my render method:

        @ForgeSubscribe(priority = EventPriority.NORMAL)
    public void renderHotbarHorizontal(RenderGameOverlayEvent event) {
        	if (config.hotbarEnabled) {
    
    		double widthMultiplier = getResIncreaseMultiplier("x");
    		double heightMultiplier = getResIncreaseMultiplier("y");
    
    		int sizeX = 182;
    		int sizeY = 22;
    
    		if (!config.horizontalHotbar) {
    			sizeX = 22;
    			sizeY = 182;
    		}
    
    		int configX = 0;
    		int configY = 0;
    
    		if (config.hotbarAnchor == 0 || config.hotbarAnchor >  {
    			configX = (int) Math.round(config.hotbarXPos * widthMultiplier);
    			configY = (int) Math.round(config.hotbarYPos * heightMultiplier);
    		} else {
    			configX = calculateAnchorPointX(config.hotbarAnchor, sizeX);
    			configY = calculateAnchorPointY(config.hotbarAnchor, sizeY);
    		}
    
    		int xPos = configX + config.hotbarXOffset;
    		int yPos = configY + config.hotbarYOffset;
    
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
            mc.renderEngine.bindTexture(guiStatsBar);
            
            if (config.horizontalHotbar) {
            	InventoryPlayer inv = mc.thePlayer.inventory;
                drawTexturedModalRect(xPos, yPos, 0, 168, sizeX, sizeY);
                drawTexturedModalRect(xPos - 1 + (inv.currentItem * 20), yPos - 1, 182, 168, 24, 24);
    
            	GL11.glDisable(GL11.GL_BLEND);
            	GL11.glEnable(GL12.GL_RESCALE_NORMAL);
            	RenderHelper.enableGUIStandardItemLighting();
    
            	for (int i = 0; i < 9; ++i) {
                    int x = xPos +  (i * 20) + 2;
                    int z = yPos - 3;
            		renderInventorySlot(i, x, z, 1.0F);
            	}
            } else {
            	InventoryPlayer inv = mc.thePlayer.inventory;
    	        drawTexturedModalRect(xPos, yPos, 234, 0, sizeX, sizeY);
    	        drawTexturedModalRect(xPos - 1, yPos - 1 + (inv.currentItem * 20), 182, 168, 24, 24);
    
    	        GL11.glDisable(GL11.GL_BLEND);
    	        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    	        RenderHelper.enableGUIStandardItemLighting();
    	        
                for (int i = 0; i < 9; ++i) {
                    int x = xPos + 3;
                    int z = yPos + (i * 20) + 2;
                    renderInventorySlot(i, x, z, 1.0F);
                }
            }
    
            RenderHelper.disableStandardItemLighting();
            GL11.glDisable(GL12.GL_RESCALE_NORMAL);
        	}
    }

  19. Hey guys,

     

    This is (hopefully) my final GUI issue, and it's probably something simple.

     

    Basically, in the vanilla hotbar you can see there is a transparancy alpha layer; you can see through the bar. In my custom hotbar, even when it's just a copy-paste of the vanilla hotbar render code, this alpha transparency doesn't work.

    Anyone got any idea what might cause such a thing?

     

     

    Also, while I'm on the subject; is it possible to animate GUI elements, in a similar way to how we animate normal textures? I know I could do it in a long-winded way, running a tick timer and changing the texture coordinates each tick, but that IS very long-winded; is there a shorter way?

  20. From memory, something similar to that didn't work.

     

    However, I've now got it to work. I caused quite a heated discussion on the whole subject in IRC, but for anyone who wants to do this in the future, here's what I did:

     

    First, I run a bit of code in the preInit which checks the screens current resolution, and saves it as a variable.

    I then later compare this variable with the current resolution, and work out the % difference.

    I turn the % into a double, add 1, and multiply my config value by that.

     

    Basically what that does is moves my GUI widget based on the % increase in screen size.

     

     

    The ONLY issue with this is relevant spacing; if you have multiple widgets, the gap between them increases with screen size. I got around this by making my config more flexible and offering an offset - so if a user sets the coordinates of two widgets the same, they can use offset to move the second widget in relation to the first. That way, when they get scaled by the screen resizing, they will stay in the same relative position to one another and move together.

     

    I also offered a fallback for people who didn't like the X/Y option (as it can be hard to get position exact with it), and allow players to simply choose a corner/side of the screen to use as a base point.

     

    It all works absolutely beautifully; when I finish making the initial release widgets, I'll post up a jar here for anyone who wants to see it in action :)

     

    I've just got one last bug; but I'll post a new thread for that tomorrow if I can't fix it tonight.

  21. Ok, I'm going to guess, due to the fact everyone seems to stop helping after that point, that ScaledResolution will NOT work for what I want to do.

     

    Therefore, the only way I can imagine that I can allow my widgets to be placed anywhere on the screen is like so:

     

    If they want it in the top left, they just set X/Y to a positive int

    X = 0

    Y = 0

     

    If they want it right of the crosshair,

    rightScreen = true

    X = 0 (Or a NEGATIVE offset)

    Y = 0 (or a POSITIVE offset)

     

    If they want it below the crosshair,

    lowerScreen = true

    X = 0 (Or a POSITIVE offset)

    Y = 0 (Or a NEGATIVE offset)

     

    And finally if they want it in the bottom right,

    lowerScreen = true

    rightScreen = true

    X = 0 (Or a NEGATIVE offset)

    Y = 0 (Or a NEGATIVE offset)

     

     

    As you can see, all that configuration gets VERY confusing. I'd much rather just be able to set X and Y, and it move correctly according to the screen's scale...

    Anyone got ANY ideas?

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.