Jump to content

dark2222

Forge Modder
  • Posts

    111
  • Joined

  • Last visited

Posts posted by dark2222

  1. try to reduce the number at

    (new WorldGenMinable(MainClass.SapphireOre, 50)).generate(world, random, chunkX, chunkY, chunkZ);

    i think its too big

     

    maybe you run you of memory creating the ores because it generates in chunks

     

    you rarity is basically how many times it runs per chunk and and then you say 50 ores should spawn (thats a lot of ores)

    so in short you in 1 chunk you run the code 24-25 times and every time you create 50 ores

     

    i try'ed this myself when i try'ed to make trees (hole chunks where just trees)

     

    if i'm wrong on how this works please tell me i just learned this from my tree gen

  2. try to create you items before the config

    Package = new BlockPackage(PackageBlockID, Material.wood).setUnlocalizedName("Package");
    Configuration config = new Configuration(event.getSuggestedConfigurationFile());
            config.load();
            //Block
            int PackageBlockID = config.getBlock("Package", 4095).getInt();
            config.save();
    

     

  3. Removing a recipe is easy CraftingManager.getInstance().getRecipeList().removeAt();

    only removing a recipe per player is hard.

    yea that's why i wanna just cancel when they craft the item because the Boolean that can be true for some players can also turn false.

    just so you now what i'm working on (may help)

    i'm working on a new Vampire Mod and i'm currently adding a Holy Ingot that i don't wan't the vampires to craft and there is also some items that i'm thinking too add that i wan't only the vampires to be able too craft.

     

  4. hello everyone.

    i can't find a way to "stop" a player from crafting a specific item when they not shall be able to make it

     

    to say it more deeply i have a boolean that normal say false but for some player it says true and i try to stop the player with the boolean = true from crafting some items

     

    i already tryed ItemCraftedEvent where i cancel the event but i crash when i do that

  5. i'm having a problem with the new netty system where i can send a packet in singleplayer without any problems but when i try on a local server (using ip: localhost) it seams that the client sends and encode the packet but it never run the decode or handleServerSide code's

    the packet i'm trying to send

    package com.dark2222.vampiremod.core.PacketHandler.packets;
    import io.netty.buffer.ByteBuf;
    import io.netty.channel.ChannelHandlerContext;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.EntityPlayerMP;
    import net.minecraft.util.ChatComponentText;
    import net.minecraft.util.IChatComponent;
    
    import com.dark2222.vampiremod.core.VampireMain;
    import com.dark2222.vampiremod.core.BloodCore.BloodCore;
    import com.dark2222.vampiremod.core.BloodCore.TickHandler;
    import com.dark2222.vampiremod.core.PacketHandler.AbstractPacket;
    
    import cpw.mods.fml.common.gameevent.TickEvent;
    import cpw.mods.fml.common.network.ByteBufUtils;
    public class FoodPack extends AbstractPacket{
    int i;
    
    public FoodPack() {}
    
    public FoodPack(int i){
    	this.i = i;
    }
    
    @Override
    public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
    	buffer.writeInt(i);
    }
    
    @Override
    public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
    	i = buffer.readInt();
    }
    
    @Override
    public void handleClientSide(EntityPlayer player) {
    		System.out.print("Running Client ");
    		BloodCore props = BloodCore.get(player);
    
    }
    
    @Override
    public void handleServerSide(EntityPlayer player) 
    {	
    		System.out.print("Running server ");
    		BloodCore props = BloodCore.get(player);
    }
    
    }

    my packetpipeline class is just "copy-paste" from the tutorial as is the abstractPacket class

     

    i register the packages in the packetpipeline

  6. Sorry for not replying and apparently leaving you all in suspense, but it was just that I needed to register the handler. After that I just had to screw around and delete some things and it works like a charm now. Thanks guys.

    how did you make the server get the packet?

    i'm having a problem with the server doesn't seem to receive the packets i send it (it does not print anything out in console from the server)

     

    i use this code when i'm trying to send a packets

     

    MainClass.packetPipeline.sendToAll(new TestPacket());

     

    i also tryed to change the code to

     

    MainClass.packetPipeline.sendToServer(new TestPacket());

     

    no reaction from the server at all when i send the packet

  7. ok i understand a bit more of NBT but can i use this without a block/item?

     

    Yes and No.  Entirely depends on what you mean to do with it.

    ok.

    i'm working on a wampire mod and i'm working on the blood system and i found out working on the system that it will kind of reset itself if i don't "save" the blood level a player is on.

    ex: if the player has a blood level on 5 i don't wan't it to be on 0 when he restart minecraft or re-join a server

  8. If you mean HUD, then check this: http://www.minecraftforge.net/wiki/Gui_Overlay

     

    It's a little outdated, but will work fine if you know just a little bit about what you are doing.

     

    Here also are two tutorials on using NBT, one in an Item, and one in a Block, but you can do the same pretty much anywhere you have access to something that will allow you to save NBT:

     

    http://www.minecraftforge.net/wiki/Item_nbt

     

    http://www.minecraftforge.net/wiki/How_to_use_NBT_Tag_Compound

    thanks gonna check them out.

    and i meant HUD :)

    ok i understand a bit more of NBT but can i use this without a block/item?

  9. If you mean HUD, then check this: http://www.minecraftforge.net/wiki/Gui_Overlay

     

    It's a little outdated, but will work fine if you know just a little bit about what you are doing.

     

    Here also are two tutorials on using NBT, one in an Item, and one in a Block, but you can do the same pretty much anywhere you have access to something that will allow you to save NBT:

     

    http://www.minecraftforge.net/wiki/Item_nbt

     

    http://www.minecraftforge.net/wiki/How_to_use_NBT_Tag_Compound

    thanks gonna check them out.

    and i meant HUD :)

  10. Dude... ItemStack is not ant int, it's an OBJECT (java type).

    If yo uwant to eg. get specific block you do not write:

    ItemStack[1000]

    but:

    ItemStack[MyMod.Sword]

    well as i sad i learn as do it right now and i just learned that it is a object

    and btw if i try to do that it want to change the items to a int so i don't think i am doing it right

    here is my container is i try to code in

    package com.durabilitytransfer;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.InventoryPlayer;
    import net.minecraft.inventory.Container;
    import net.minecraft.inventory.Slot;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraftforge.event.ForgeSubscribe;
    
    import com.durabilitytransfer.slots.basictransferslot1;
    import com.durabilitytransfer.slots.basictransferslot2;
    import com.durabilitytransfer.slots.basictransferslot3;
    import com.durabilitytransfer.titleentitys.TileEntityBasic;
    
    public class ContainerBatic extends Container{
    private TileEntityBasic basic;
    
    public ContainerBatic(InventoryPlayer invPlayer, TileEntityBasic basic) {
    	this.basic = basic;
    	boolean a = true;
    		test(basic);
    
    	for (int x = 0; x < 9; x++){
    		addSlotToContainer(new Slot(invPlayer, x, 8 + 18 * x, 198));
    	}
    	for (int y = 0; y < 3; y++){
    		for(int x = 0; x < 9; x++) {
    			addSlotToContainer(new Slot(invPlayer, x + y * 9 + 9, 8 + 18 * x, 140 + y * 18));
    		}
    	}
    
    	for (int y = 0; y < 1; y++){
    		for (int x = 0; x < 1; x++){
    			this.addSlotToContainer(new basictransferslot1(basic,  0, 82 + x * 18, 12 + y * 18));
    			this.addSlotToContainer(new basictransferslot2(basic,  1, 82 + x * 18, 59 + y * 18));
    			this.addSlotToContainer(new basictransferslot3(basic, 2, 8 + x * 18, 120 + y * 18));
    		}
    	}
    }
                                                                           
    public static void test(TileEntityBasic basic){ <---- this is the code i am working on
    	System.out.println("starting1");
    	if(basic.getStackInSlot(0) == ItemStack[item.swordWood]){
    		System.out.println("test");
    
    	}else{
    		System.out.println("broke");
    
    	}
    }
    
    
    @Override
    public boolean canInteractWith(EntityPlayer entityplayer) {
    	return basic.isUseableByPlayer(entityplayer);
    }
    @Override
    public ItemStack transferStackInSlot(EntityPlayer player, int index){
    	ItemStack stack = null;
    	Slot slot = (Slot) this.inventorySlots.get(index);
    	if(slot!=null&&slot.getHasStack()){
    		ItemStack slotstack = slot.getStack();
    		stack = slotstack.copy();
    		if(index<{
    			if(!this.mergeItemStack(slotstack,8,this.inventorySlots.size(),false)) return null;
    		}else if(!this.getSlot(0).isItemValid(slotstack)||!this.mergeItemStack(slotstack,0,4,false)) return null;
    		if(slotstack.stackSize==0){
    			slot.putStack((ItemStack) null);
    		}else{
    			slot.onSlotChanged();
    		}
    		if(slotstack.stackSize==stack.stackSize) return null;
    		slot.onPickupFromSlot(player,slotstack);
    	}
    	return stack;
    }
    /**
     * Does the same as mergeItemStack with the same args, except does not
     * actually merge— just returns the number of items that can be merged
     * (usually either stack.stackSize or 0, but can be in between)
     * @param stack
     * @param start
     * @param end
     * @param reverse
     * @return
     */
    int dryMerge(ItemStack stack, int start, int end, boolean reverse){
    	boolean flag1 = false;
    	int i = start;
    	if(reverse){
    		i = end-1;
    	}
    	int quantity = stack.stackSize;
    	Slot slot;
    	ItemStack slotstack;
    	if(stack.isStackable()){
    		while(stack.stackSize>0&&(!reverse&&i<end||reverse&&i>=start)){
    			slot = this.getSlot(i);
    			slotstack = slot.getStack();
    			if(slotstack!=null&&slotstack.itemID==stack.itemID&&(!stack.getHasSubtypes()||stack.getItemDamage()==slotstack.getItemDamage())&&ItemStack.areItemStackTagsEqual(stack,slotstack)){
    				int l = slotstack.stackSize+stack.stackSize;
    				if(l<=stack.getMaxStackSize()){
    					quantity -= slotstack.stackSize;
    				}else if(slotstack.stackSize<stack.getMaxStackSize()){
    					quantity -= (stack.getMaxStackSize() - slotstack.stackSize);
    				}
    			}
    			if(reverse) --i;
    			else ++i;
    		}
    	}
    	if(stack.stackSize>0){
    		if(reverse){
    			i = end-1;
    		}else{
    			i = start;
    		}
    		while(!reverse&&i<end||reverse&&i>=start){
    			slot = (Slot) this.inventorySlots.get(i);
    			slotstack = slot.getStack();
    			if(slotstack==null){
    				quantity = 0;
    				break;
    			}
    			if(reverse){
    				--i;
    			}else{
    				++i;
    			}
    		}
    	}
    	return stack.stackSize-quantity;
    }
    }
    

  11. You ask (author) some strange questions lately - it's almost like you are lazy (lol) :)

    If you don't understand how TileEntity works in container and when and what is called I suggest opening:

    BlockFurncae.class

    ContainerFurnace.class

    FurnaceRecipes.class

    TileEntityFurnace.class

    Then go through code and in every method add System.out.println() on beggining and end, also before and after any method that is called by that method (see for what it asks, when, and what is the return).

    eg.: in onUpdate() in TileEntity write something like:

    public void updateEntity()
        {
            boolean flag = this.furnaceBurnTime > 0;
            boolean flag1 = false;
    System.out.println("Starting Updating Entity")
            if (this.furnaceBurnTime > 0)
            {
    System.out.println("Furnace is burning...")
                --this.furnaceBurnTime;
            }
    else System.out.println("Not burning")
    
            if (!this.worldObj.isRemote)
            {
    System.out.println("Checking if furnace is not burning and if not, and also there is fuel continue")
                if (this.furnaceBurnTime == 0 && this.canSmelt())
                {
                    this.currentItemBurnTime = this.furnaceBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);
    

     

    Same goes to this.furnaceItemStacks[1] - if you add nice System.out.println() to it and put something in it you will figure out how it works.

    I am not helping here much (sorry) but belive me, if you want to have ability to code advanced stuff in future this will help very much (takes about few hours to figure out, but then you KNOW the code).

     

    And hit about this.furnaceItemStacks[] - when you are adding slots in your Container class this will be an array with size equal to how many slots you add. Let's have look:

    //In Container  I have defined my slots like this
    public static final int FUEL[] = {0};
    public static final int INPUT[] = {1,2,3,4,5,6};
    public static final int OUTPUT[] = {7,8,9,10,11,12};
    //Now in my TileEntity it's
    ArrayOfItemStacks = new ItemStack[13];
    //Now ArrayOfItemStacks is a array {0,1,2,3,4,5,6,7,8,9,10,11,12}; where every ID is refering to those in Container.class
    

    Can't describe it more clearly :C

    will not say that i am lazy bekos i am trying to make it work as i am waiting for response

    i just ask so much bekos i can't find any tuts on it + i don't now that much java (learning that as i go more advanced)

    and i use that system println trick and right now i am trying to get wooden sword to work but i all times get a error

    (about ItemStack[] don't work with int)

     

  12. I don't know how to explain it more clearly. There is ONE index for each slot. It's the index of the ItemStack in your ItemStack array.

    i understand that and i tryed to make a code my problem is that my code is not running/executing

    EDIT-

    wait... am i suppose to do this in the container or tile entity? (right now i tryed in tile entity)

  13. In your Inventory (in this case: the TileEntity) you have the

    getStackInSlot

    and

    setInventorySlotContents

    methods. These take a slot index. Usually that maps directly to an array of ItemStacks, so

    getStackInSlot(0)

    will return the first element in the array:

    itemStacks[0]

    .

    Now in your container you have something like

    new Slot(id, x, y)

    . Now that slot will display the stack which is available via

    getStackInSlot(id)

    resp.

    itemStacks[id]

    .

    i have tryed a cuble things but i can't get it to run

    EDIT-

    i can't find any onUpdate

  14. Each index in the array is a different Slot. You are defining which slot is which index when you construct your Slots. You pass it an index variable, that is the index in the array.

    So i can tell it what slot by the slot id i gave the specefic slot?

     

    Sorry i ask so much just trying to understand as much as i can before getting home for school xD

  15. the itemstack array in the tileentity symboles your Slots.

    Use onUpdate() in the tileentity and check your inventory and change the item how much you want.

    Thanks for the tip, can i still check what slot the item are in? Have 3 diffrent slots and i need to do diffrent stuff on all slots

     

    Sorry if some words are spell wrong i am on ipad in school

  16. i am working on an new mod right now and i don't now have to detect the items i put the GUI slots or change them (damaging/enchanting ex)

    here are the files i think you will need

    container

    package com.durabilitytransfer;
    
    import com.durabilitytransfer.slots.basictransferslot1;
    import com.durabilitytransfer.slots.basictransferslot2;
    import com.durabilitytransfer.slots.basictransferslot3;
    import com.durabilitytransfer.titleentitys.TileEntityBasic;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.InventoryPlayer;
    import net.minecraft.inventory.Container;
    import net.minecraft.inventory.Slot;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraftforge.client.MinecraftForgeClient;
    import net.minecraftforge.common.MinecraftForge;
    
    public class ContainerBatic extends Container{
    private TileEntityBasic basic;
    
    public ContainerBatic(InventoryPlayer invPlayer, TileEntityBasic basic) {
    	this.basic = basic;
    	if(basic.canUpdate() != false){
    		basic.updateContainingBlockInfo();
    	}
    
    	for (int x = 0; x < 9; x++){
    		addSlotToContainer(new Slot(invPlayer, x, 8 + 18 * x, 198));
    	}
    	for (int y = 0; y < 3; y++){
    		for(int x = 0; x < 9; x++) {
    			addSlotToContainer(new Slot(invPlayer, x + y * 9 + 9, 8 + 18 * x, 140 + y * 18));
    		}
    	}
    
    	for (int y = 0; y < 1; y++){
    		for (int x = 0; x < 1; x++){
    			this.addSlotToContainer(new basictransferslot1(basic,  0, 82 + x * 18, 12 + y * 18));
    			this.addSlotToContainer(new basictransferslot2(basic,  1, 82 + x * 18, 59 + y * 18));
    			this.addSlotToContainer(new basictransferslot3(basic, 2, 8 + x * 18, 120 + y * 18));
    		}
    	}
    }
    
    
    @Override
    public boolean canInteractWith(EntityPlayer entityplayer) {
    	return basic.isUseableByPlayer(entityplayer);
    }
    @Override
    public ItemStack transferStackInSlot(EntityPlayer player, int index){
    	ItemStack stack = null;
    	Slot slot = (Slot) this.inventorySlots.get(index);
    	if(slot!=null&&slot.getHasStack()){
    		ItemStack slotstack = slot.getStack();
    		stack = slotstack.copy();
    		if(index<{
    			if(!this.mergeItemStack(slotstack,8,this.inventorySlots.size(),false)) return null;
    		}else if(!this.getSlot(0).isItemValid(slotstack)||!this.mergeItemStack(slotstack,0,4,false)) return null;
    		if(slotstack.stackSize==0){
    			slot.putStack((ItemStack) null);
    		}else{
    			slot.onSlotChanged();
    		}
    		if(slotstack.stackSize==stack.stackSize) return null;
    		slot.onPickupFromSlot(player,slotstack);
    	}
    	return stack;
    }
    /**
     * Does the same as mergeItemStack with the same args, except does not
     * actually merge— just returns the number of items that can be merged
     * (usually either stack.stackSize or 0, but can be in between)
     * @param stack
     * @param start
     * @param end
     * @param reverse
     * @return
     */
    int dryMerge(ItemStack stack, int start, int end, boolean reverse){
    	boolean flag1 = false;
    	int i = start;
    	if(reverse){
    		i = end-1;
    	}
    	int quantity = stack.stackSize;
    	Slot slot;
    	ItemStack slotstack;
    	if(stack.isStackable()){
    		while(stack.stackSize>0&&(!reverse&&i<end||reverse&&i>=start)){
    			slot = this.getSlot(i);
    			slotstack = slot.getStack();
    			if(slotstack!=null&&slotstack.itemID==stack.itemID&&(!stack.getHasSubtypes()||stack.getItemDamage()==slotstack.getItemDamage())&&ItemStack.areItemStackTagsEqual(stack,slotstack)){
    				int l = slotstack.stackSize+stack.stackSize;
    				if(l<=stack.getMaxStackSize()){
    					quantity -= slotstack.stackSize;
    				}else if(slotstack.stackSize<stack.getMaxStackSize()){
    					quantity -= (stack.getMaxStackSize() - slotstack.stackSize);
    				}
    			}
    			if(reverse) --i;
    			else ++i;
    		}
    	}
    	if(stack.stackSize>0){
    		if(reverse){
    			i = end-1;
    		}else{
    			i = start;
    		}
    		while(!reverse&&i<end||reverse&&i>=start){
    			slot = (Slot) this.inventorySlots.get(i);
    			slotstack = slot.getStack();
    			if(slotstack==null){
    				quantity = 0;
    				break;
    			}
    			if(reverse){
    				--i;
    			}else{
    				++i;
    			}
    		}
    	}
    	return stack.stackSize-quantity;
    }
    
    }

     

    Tile entity

    package com.durabilitytransfer.titleentitys;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.inventory.IInventory;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.nbt.NBTTagList;
    import net.minecraft.tileentity.TileEntity;
    
    public class TileEntityBasic extends TileEntity implements IInventory{
    
    private ItemStack[] items;
    
    public TileEntityBasic() {
    	items = new ItemStack[9];
    }
    
    @Override
    public int getSizeInventory() {
    	return items.length;
    }
    
    @Override
    public ItemStack getStackInSlot(int i) {
    	return items[i];
    }
    
    @Override
    public ItemStack decrStackSize(int i, int count) {
    	ItemStack itemstack = getStackInSlot(i);
    
    	if(itemstack != null){
    		if(itemstack.stackSize <= count){
    			setInventorySlotContents(i, null);
    		} else {
    			itemstack = itemstack.splitStack(count);
    			onInventoryChanged();
    		}
    	}
    
    	return itemstack;
    }
    
    @Override
    public ItemStack getStackInSlotOnClosing(int i) {
    	ItemStack item = getStackInSlot(i);
    	setInventorySlotContents(i, null);
    	return item;
    }
    
    @Override
    public void setInventorySlotContents(int i, ItemStack itemstack) {
    	items[i] = itemstack;
    
    	if(itemstack != null && itemstack.stackSize > getInventoryStackLimit()) {
    		itemstack.stackSize = getInventoryStackLimit();
    	}
    
    	onInventoryChanged();
    
    }
    
    @Override
    public String getInvName() {
    	return "BasicTransfer";
    }
    
    @Override
    public boolean isInvNameLocalized() {
    
    	return false;
    }
    
    @Override
    public int getInventoryStackLimit() {
    	return 1;
    }
    
    @Override
    public boolean isUseableByPlayer(EntityPlayer entityplayer) {
    	return entityplayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) <= 64;
    }
    
    @Override
    public void openChest() {
    
    }
    
    @Override
    public void closeChest() {
    
    }
    
    @Override
    public boolean isItemValidForSlot(int i, ItemStack itemstack) {
    	return itemstack.itemID == Item.swordWood.itemID;
    }
    @Override
    public void writeToNBT(NBTTagCompound compound) {
      super.writeToNBT(compound);
    
      NBTTagList list = new NBTTagList();
    
      for(int i = 0; i < getSizeInventory(); i++) {
            ItemStack itemstack = getStackInSlot(i);
    
            if(itemstack != null) {
              NBTTagCompound item = new NBTTagCompound();
    
              item.setByte("dtitem", (byte) i);
              itemstack.writeToNBT(item);
              list.appendTag(item);
            }
      }
    
      compound.setTag("dtitem", list);
    }
    @Override
    public void readFromNBT(NBTTagCompound compound) {
      super.readFromNBT(compound);
    
      NBTTagList list = compound.getTagList("dtitem");
    
      for(int i = 0; i < list.tagCount(); i++) {
            NBTTagCompound item = (NBTTagCompound) list.tagAt(i);
            int slot = item.getByte("dtitem");
    
            if(slot >= 0 && slot < getSizeInventory()) {
              setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item));
            }
      }
    }
    }

    i also have 3 custom slot classes for my Block slots that look like this

    package com.durabilitytransfer.slots;
    
    import net.minecraft.inventory.IInventory;
    import net.minecraft.inventory.Slot;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    
    public class basictransferslot1 extends Slot{
    
    
    public basictransferslot1(IInventory par1iInventory, int par2, int par3, int par4) {
    	super(par1iInventory, par2, par3, par4);
    }
    
    @Override
        public boolean isItemValid(ItemStack par1ItemStack)
        {
            return par1ItemStack.itemID == Item.swordWood.itemID;
        }
        
    }
    

×
×
  • Create New...

Important Information

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