Jump to content

Triphion

Members
  • Posts

    122
  • Joined

  • Last visited

Posts posted by Triphion

  1. 37 minutes ago, diesieben07 said:

    So... what's the error?

     

    50 minutes ago, Triphion said:
    Quote

    The method register(String, Supplier<? extends I>) in the type DeferredRegister<EntityType<?>> is not applicable for the arguments (String, () -> {})

    Quote

    The method create(EntityType.IFactory<T>, EntityClassification) in the type EntityType.Builder is not applicable for the arguments (ChupnutEntity::new, EntityClassification)

    Quote

    The type ChupnutEntity does not define ChupnutEntity(EntityType<T>, World) that is applicable here

    These also don't disappear even if I were to extend another vanilla class. 

    These. 

  2. I recently started to use deferred registries instead of the old way of registering stuff such as items and blocks. And i've gotten all other stuff i've tried to work splendidly, all but entities. It just gives me error messages for every single solution I try; and it's driving me nuts. Help please. 

     

    What is it that's so wrong with this code? 

    	public static final DeferredRegister<EntityType<?>> ENTITIES = new DeferredRegister<>(ForgeRegistries.ENTITIES, Reference.MODID);
    	
    	public static final RegistryObject<EntityType<ChupnutEntity>> CHUPNUT = ENTITIES.register("chupnut", () -> EntityType.Builder.create(ChupnutEntity::new, EntityClassification.CREATURE)
    			.size(0.8f, 0.6f)
    			.setShouldReceiveVelocityUpdates(false)
    			.build("chupnut"));

    Also, this error doesn't pop up if i change the entity class to any of the vanilla ones, and so this leads me to believe that there is something that is supposed to go into the entity class that i'm not aware of.

    And so, this is my entity class:

    public class ChupnutEntity extends CreatureEntity
    {
    	protected ChupnutEntity(EntityType<? extends CreatureEntity> type, World worldIn) 
    	{
    		super(type, worldIn);
    		
    		this.experienceValue = 5;
    	}
    	
    	@Override
    	protected void registerGoals() 
    	{
    		this.goalSelector.addGoal(0, new SwimGoal(this));
    		this.goalSelector.addGoal(3, new MeleeAttackGoal(this, 1.0D, true));
    		this.goalSelector.addGoal(5, new WaterAvoidingRandomWalkingGoal(this, 1.0D));
    		this.goalSelector.addGoal(7, new LookAtGoal(this, LivingEntity.class, 16.0f));
    		this.targetSelector.addGoal(0, new HurtByTargetGoal(this, new Class[0]));
    		this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, PlayerEntity.class, true));
    		this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, ChickenEntity.class, true));
    	}
    	
    	@Override
    	protected void registerAttributes() 
    	{
    		super.registerAttributes();
    		this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(16.0D);
    		this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.30000001192092896D);
    		this.getAttributes().registerAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(2.0D);
    	}
    	
    	@Override
    	protected void updateAITasks() 
    	{
    		super.updateAITasks();
    	}
    	
        public boolean attackEntityAsMob(Entity entityIn)
        {
            boolean flag = entityIn.attackEntityFrom(DamageSource.causeMobDamage(this), (float)((int)this.getAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getBaseValue()));
    
            if (flag)
            {
                this.applyEnchantments(this, entityIn);
            }
    
            return flag;
        }
    	
    	@Override
    	protected SoundEvent getAmbientSound() 
    	{
    		return super.getAmbientSound();
    	}
    	
    	@Override
    	protected SoundEvent getHurtSound(DamageSource damageSourceIn) 
    	{
    		return super.getHurtSound(damageSourceIn);
    	}
    	
    	@Override
    	protected SoundEvent getDeathSound() 
    	{
    		return super.getDeathSound();
    	}
    	
    	@Override
    	protected float getStandingEyeHeight(Pose poseIn, EntitySize sizeIn) 
    	{
    		return 0.4f;
    	}
    }

    Oh, and these errors are the ones that keep popping up:

    Quote

    The method register(String, Supplier<? extends I>) in the type DeferredRegister<EntityType<?>> is not applicable for the arguments (String, () -> {})

    Quote

    The method create(EntityType.IFactory<T>, EntityClassification) in the type EntityType.Builder is not applicable for the arguments (ChupnutEntity::new, EntityClassification)

    Quote

    The type ChupnutEntity does not define ChupnutEntity(EntityType<T>, World) that is applicable here

    These also don't disappear even if I were to extend another vanilla class. 

  3. 7 hours ago, loordgek said:

    check if the InventoryCrafting is yours

    Did this and it works! Thank you! Only issue i have now is that the Crafting Book is behaving oddly, the recipes themselves aren't showing up when i click on them and my custom recipe for sword is showing up as a 90 degrees rotated sword recipe. The Crafting Book issue regarding the recipes that aren't showing up inside the crafting window however has something to do with the container, don't know where this gets called since i have checked withing the vanilla Crafting Table and my code looks pretty identical. 

  4. I want my special recipes to work ONLY on my new crafting table. I have everything set-up: Custom Crafting Table, Custom IRecipe implementation and a _factories.json. My Crafting Table is just like a normal Crafting Table so my custom IRecipe is essentially the same as a "shaped" recipe. This is what my custom IRecipe implementation looks like:

     

    Custom IRecipe implementation - https://gist.github.com/triphion/ac318db6a9a38789e219bbc71adea2b8

     

    My guess is that i can somehow change this inside the matches function. 

  5. To be clear, i have added loot_tables before, and i have also added loot_tables in this mod i'm making right now. However, some loot_table jsons aren't working and i can't get my head around why they don't. So here is one of them that i think should work but doesn't. 

    Quote

    {
        "pools": [
            {
                "name": "main",
                "rolls": {
                    "min": 1,
                    "max": 3
                },
                "entries": [
                    {
                        "type": "item",
                        "weight": 15,
                        "name": "minecraft:bone",
                        "functions": [
                            {
                                "function": "set_count",
                                "count": {
                                    "min": 1,
                                    "max": 6
                                }
                            }
                        ]
                    },
                    {
                        "type": "item",
                        "weight": 15,
                        "name": "minecraft:rotten_flash",
                        "functions": [
                            {
                                "function": "set_count",
                                "count": {
                                    "min": 1,
                                    "max": 6
                                }
                            }
                        ]
                    },
                    {
                        "type": "item",
                        "weight": 10,
                        "name": "minecraft:iron_ingot",
                        "functions": [
                            {
                                "function": "set_count",
                                "count": {
                                    "min": 1,
                                    "max": 3
                                }
                            }
                        ]
                    },
                    {
                        "type": "item",
                        "weight": 5,
                        "name": "minecraft:diamond",
                        "functions": [
                            {
                                "function": "set_count",
                                "count": {
                                    "min": 1,
                                    "max": 2
                                }
                            }
                        ]
                    },
                    {
                        "type": "item",
                        "weight": 5,
                        "name": "minecraft:dye",
                        "functions": [
                            {
                                "function": "set_data",
                                "data": 4
                            },
                            {
                                "function": "set_count",
                                "count": {
                                    "min": 1,
                                    "max": 7
                                }
                            }
                        ]
                    },
                    {
                        "type": "item",
                        "weight": 10,
                        "name": "minecraft:string",
                        "functions": [
                            {
                                "function": "set_count",
                                "count": {
                                    "min": 1,
                                    "max": 5
                                }
                            }
                        ]
                    },
                    {
                        "type": "item",
                        "weight": 5,
                        "name": "minecraft:arrow",
                        "functions": [
                            {
                                "function": "set_count",
                                "count": {
                                    "min": 1,
                                    "max": 8
                                }
                            }
                        ]
                    }
                ]
            },
            {
                "rolls": {
                    "min": 1,
                    "max": 3
                },
                "entries": [
                    {
                        "type": "item",
                        "weight": 2,
                        "name": "minecraft:stone_sword"
                    },
                    {
                        "type": "item",
                        "weight": 5,
                        "name": "minecraft:wooden_sword"
                    },
                    {
                        "type": "item",
                        "weight": 1,
                        "name": "minecraft:wheat",
                        "functions": [
                            {
                                "function": "set_count",
                                "count": {
                                    "min": 1,
                                    "max": 5
                                }
                            }
                        ]
                    },
                    {
                        "type": "item",
                        "weight": 2,
                        "name": "minecraft:book",
                        "functions": [
                            {
                                "function": "enchant_randomly"
                            }
                        ]
                    },
                    {
                        "type": "item",
                        "weight": 2,
                        "name": "minecraft:book",
                        "functions": [
                            {
                                "function": "enchant_randomly"
                            }
                        ]
                    },
                    {
                        "type": "item",
                        "weight": 5,
                        "name": "minecraft:leather_helmet"
                    },
                    {
                        "type": "item",
                        "weight": 5,
                        "name": "minecraft:leather_chestplate"
                    },
                    {
                        "type": "item",
                        "weight": 5,
                        "name": "minecraft:leather_leggings"
                    },
                    {
                        "type": "item",
                        "weight": 5,
                        "name": "minecraft:leather_boots"
                    }
                ]
            },
            {
                "rolls": {
                    "min": 1,
                    "max": 3
                },
                "entries": [
                    {
                        "type": "item",
                        "weight": 10,
                        "name": "minecraft:stick",
                        "functions": [
                            {
                                "function": "set_count",
                                "count": {
                                    "min": 1,
                                    "max": 3
                                }
                            }
                        ]
                    },
                    {
                        "type": "item",
                        "weight": 10,
                        "name": "minecraft:leather",
                        "functions": [
                            {
                                "function": "set_count",
                                "count": {
                                    "min": 1,
                                    "max": 3
                                }
                            }
                        ]
                    },
                    {
                        "type": "item",
                        "weight": 15,
                        "name": "minecraft:glass_bottle",
                        "functions": [
                            {
                                "function": "set_count",
                                "count": {
                                    "min": 1,
                                    "max": 5
                                }
                            }
                        ]
                    },
                    {
                        "type": "item",
                        "weight": 1,
                        "name": "minecraft:experience_bottle",
                        "functions": [
                            {
                                "function": "set_count",
                                "count": {
                                    "min": 1,
                                    "max": 5
                                }
                            }
                        ]
                    },
                    {
                        "type": "item",
                        "weight": 1,
                        "name": "minecraft:shield"
                    },
                    {
                        "type": "item",
                        "weight": 5,
                        "name": "etauric:yarch_ingot",
                        "functions": [
                            {
                                "function": "set_count",
                                "count": {
                                    "min": 1,
                                    "max": 3
                                }
                            }
                        ]
                    },
                    {
                        "type": "item",
                        "weight": 10,
                        "name": "minecraft:gunpowder",
                        "functions": [
                            {
                                "function": "set_count",
                                "count": {
                                    "min": 1,
                                    "max": 3
                                }
                            }
                        ]
                    }
                ]
            },
            {
                "rolls": {
                    "min": 1,
                    "max": 3
                },
                "entries": [
                    {
                        "type": "item",
                        "weight": 10,
                        "name": "minecraft:bread",
                        "functions": [
                            {
                                "function": "set_count",
                                "count": {
                                    "min": 1,
                                    "max": 2
                                }
                            }
                        ]
                    },
                    {
                        "type": "item",
                        "weight": 10,
                        "name": "minecraft:feather",
                        "functions": [
                            {
                                "function": "set_count",
                                "count": {
                                    "min": 1,
                                    "max": 3
                                }
                            }
                        ]
                    },
                    {
                        "type": "item",
                        "weight": 5,
                        "name": "minecraft:book",
                        "functions": [
                            {
                                "function": "set_count",
                                "count": {
                                    "min": 1,
                                    "max": 2
                                }
                            }
                        ]
                    },
                    {
                        "type": "item",
                        "weight": 2,
                        "name": "minecraft:iron_horse_armor"
                    },
                    {
                        "type": "item",
                        "weight": 20,
                        "name": "minecraft:cobblestone",
                        "functions": [
                            {
                                "function": "set_count",
                                "count": {
                                    "min": 1,
                                    "max": 9
                                }
                            }
                        ]
                    }
                ]
            }
        ]
    }

    There aren't any problems with the registering of the loot_table either, i have tried with the same name with different loot inside and it works, but this loot does not. 

  6. 10 hours ago, Cadiboo said:

    You probably want a custom recipe type. To do this I think you’ll need a _factories.json file and a custom IRecipe implementation.

    Okay, i looked a bit into it, however, i have a REALLY hard time understanding how everything regarding IRecipe works. I have however created a _factories.json now, so i think that one will work once i get everything else done. 

    Also, to clear up, i have added recipes. But the recipes are normal recipes, and since my custom crafting table is basically a vanilla with a retexture, it adds onto that table aswell. But i want the recipes to only work on my custom table, and not the vanilla one. 

    How do i make use of a custom IRecipe by the way? 

  7. I have my working custom crafting table and everything like that set up. But now i'd like to have some new recipes added on-top of the vanilla ones. I have some insight into it, such as i'd probably need a crafting manager/handler or something like that. But i don't know how to make one or how to use it. So i'd like some guidance here if possible. Such as: What is important inside a crafting manager/handler? How do i make use of it? How do i register it? 

     

    Worth noting is that crafting recipes in json format is new to me aswell since this is my first mod in 1.12.2, so some insight onto that aswell would be great! ?

  8. I have everything handled and in order for this to work, and everything does work, except for the inventory. When i click on some slots and/or items in the inventory, they move to other places inside the inventory or duplicates or something else. I have no idea why this happens and would very much appreciate some help here. 

    The block:

    Quote

    public class BlockCyclopsSmithy extends BlockBase
    {
        public BlockCyclopsSmithy(String unlocalizedName, Material materialIn) 
        {
            super(unlocalizedName, materialIn);
            this.setSoundType(SoundType.STONE);
            this.setDefaultState(this.blockState.getBaseState());
        }
        
        @Override
        public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) 
        {
            if(worldIn.isRemote)
            {
                playerIn.openGui(MainClass.instance, MainClass.GUI_ENUM.CYCLOPS_SMITHY.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ());
            }
            
            return true;
        }

    The Container:

    Quote

    public class ContainerCyclopsSmithy extends Container
    {
        /** The crafting matrix inventory (3x3). */
        public InventoryCrafting craftMatrix = new InventoryCyclopsSmithy(this, 3, 3);
        public InventoryCraftResult craftResult = new InventoryCraftResult();
        private final World world;
        /** Position of the workbench */
        private final BlockPos pos;
        private final EntityPlayer player;
        
        public ContainerCyclopsSmithy(InventoryPlayer playerInventory, World parWorld, BlockPos posIn) 
        {
                   this.world = parWorld;
                this.pos = posIn;
                this.player = playerInventory.player;
                this.addSlotToContainer(new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 124, 35));

                for (int i = 0; i < 3; ++i)
                {
                    for (int j = 0; j < 3; ++j)
                    {
                        this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 3, 30 + j * 18, 17 + i * 18));
                    }
                }

                for (int k = 0; k < 3; ++k)
                {
                    for (int i1 = 0; i1 < 9; ++i1)
                    {
                        this.addSlotToContainer(new Slot(playerInventory, i1 + k * 9 + 9, 8 + i1 * 18, 84 + k * 18));
                    }
                }

                for (int l = 0; l < 9; ++l)
                {
                    this.addSlotToContainer(new Slot(playerInventory, l, 8 + l * 18, 142));
                }
         }

            /**
             * Callback for when the crafting matrix is changed.
             */
            public void onCraftMatrixChanged(IInventory inventoryIn)
            {
                this.slotChangedCraftingGrid(this.world, this.player, this.craftMatrix, this.craftResult);
            }

            /**
             * Called when the container is closed.
             */
            public void onContainerClosed(EntityPlayer playerIn)
            {
                super.onContainerClosed(playerIn);

                if (!this.world.isRemote)
                {
                    this.clearContainer(playerIn, this.world, this.craftMatrix);
                }
            }

            /**
             * Determines whether supplied player can use this container
             */
            public boolean canInteractWith(EntityPlayer playerIn)
            {
                if (this.world.getBlockState(this.pos).getBlock() != EtauricBlocks.CYCLOPS_SMITHY)
                {
                    return false;
                }
                else
                {
                    return playerIn.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
                }
            }

            /**
             * Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
             * inventory and the other inventory(s).
             */
            public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
            {
                ItemStack itemstack = ItemStack.EMPTY;
                Slot slot = this.inventorySlots.get(index);

                if (slot != null && slot.getHasStack())
                {
                    ItemStack itemstack1 = slot.getStack();
                    itemstack = itemstack1.copy();

                    if (index == 0)
                    {
                        itemstack1.getItem().onCreated(itemstack1, this.world, playerIn);

                        if (!this.mergeItemStack(itemstack1, 10, 46, true))
                        {
                            return ItemStack.EMPTY;
                        }

                        slot.onSlotChange(itemstack1, itemstack);
                    }
                    else if (index >= 10 && index < 37)
                    {
                        if (!this.mergeItemStack(itemstack1, 37, 46, false))
                        {
                            return ItemStack.EMPTY;
                        }
                    }
                    else if (index >= 37 && index < 46)
                    {
                        if (!this.mergeItemStack(itemstack1, 10, 37, false))
                        {
                            return ItemStack.EMPTY;
                        }
                    }
                    else if (!this.mergeItemStack(itemstack1, 10, 46, false))
                    {
                        return ItemStack.EMPTY;
                    }

                    if (itemstack1.isEmpty())
                    {
                        slot.putStack(ItemStack.EMPTY);
                    }
                    else
                    {
                        slot.onSlotChanged();
                    }

                    if (itemstack1.getCount() == itemstack.getCount())
                    {
                        return ItemStack.EMPTY;
                    }

                    ItemStack itemstack2 = slot.onTake(playerIn, itemstack1);

                    if (index == 0)
                    {
                        playerIn.dropItem(itemstack2, false);
                    }
                }

                return itemstack;
            }

            /**
             * Called to determine if the current slot is valid for the stack merging (double-click) code. The stack passed in
             * is null for the initial slot that was double-clicked.
             */
            public boolean canMergeSlot(ItemStack stack, Slot slotIn)
            {
                return slotIn.inventory != this.craftResult && super.canMergeSlot(stack, slotIn);
            }

    The Inventory:

    Quote

    public class InventoryCyclopsSmithy extends InventoryCrafting
    {
        public InventoryCyclopsSmithy(Container eventHandlerIn, int width, int height) 
        {
            super(eventHandlerIn, width, height);
        }
    }

    Basically all of it is copy-pasted from the normal workbench, but with my own block instead. 

  9. 14 minutes ago, Draco18s said:

    So, it will do this:

     

    0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0...

     

    Yes?

     

    If so, why do you need an integer? Or an if statement at all?

     

    1 - currentValue will do this just fine. So will (currentValue + 1) % maximum

    I need the integer since i have added more than just 2 modes. This is how it looks now:

        public void setLightningIndex(ItemStack item, int lightningValue) 
        {
    	    NBTTagCompound nbtTagCompound = item.getTagCompound();
    	    
    	    if (nbtTagCompound == null) 
    	    {
    	    	nbtTagCompound = new NBTTagCompound();
    	    	item.setTagCompound(nbtTagCompound);
    	    }
    	    
    	    if (lightningValue == 4) 
    	    {
    	    	lightningValue = 0;
    	    }
    	    
    	    nbtTagCompound.setInteger("lIndex", lightningValue);
    	}

    And this works just fine for this case. 

    But i am very appreciative of the advice however. ^^

     

    EDIT: Actually, i do not need that integer parameter, my bad, thanks for pointing that out.

    Quote

        public void setLightningIndex(ItemStack item) 
        {
            NBTTagCompound nbtTagCompound = item.getTagCompound();
            
            if (nbtTagCompound == null) 
            {
                nbtTagCompound = new NBTTagCompound();
                item.setTagCompound(nbtTagCompound);
            }
            
            nbtTagCompound.setInteger("lIndex", nbtTagCompound.getInteger("lIndex") + 1);
            
            if (nbtTagCompound.getInteger("lIndex") == 4) 
            {
                nbtTagCompound.setInteger("lIndex", 0);
            }
        }

    This works easier than the above mentioned, thanks Draco. ^^

  10. Hi again, i've been posting quite frequently on here now hehe, it's just that i'm trying out so many new things and have no idea which methods do which in some of these cases. So i'd like some information on how this would be done. I have my item set up, a bottle that fills with fire whenever a block of my choosing is right-clicked. However, i can't seem to get any fire-blocks from raytracing, and the case seems to be that fire-blocks has no hitbox, and so, i would like to know how i can go around this issue. I have tried looking into waterliquid to see how it distinguishes fires, however i did not find anything there, i then also tried looking into how the player can extinguish fires by left-clicking on top of the block that is burning to no avail. So i'd like some info on this issue. ^^

  11. 2 hours ago, Draco18s said:

    1) remove this

    2) use the logger the FMLPreInitializationEvent gives you

     

    Did you mean to leave this empty?

    I have removed the printlns, and i usually use the logger, but for this i used the printlns because of a whim i guess? ?

    And that check is actually not needed, so i removed it. I always add +1 as the lightning index, so it always goes up, then i check if it goes up to 2, and if it does, it resets the value. But thanks for pointing those out. ?

  12. 3 minutes ago, diesieben07 said:

    This can be null if the ItemStack does not have an NBT tag yet. Your code does not handle that case.

    I SOLVED IT! Thank you so much diesieben! ❤️

    This is how i did it: 

    Quote

        public void setLightningIndex(ItemStack item, int lightningValue) 
        {
            NBTTagCompound nbtTagCompound = item.getTagCompound();
            System.out.println(nbtTagCompound);
            
            if (nbtTagCompound == null) 
            {
                nbtTagCompound = new NBTTagCompound();
                item.setTagCompound(nbtTagCompound);
            }
            
            if (lightningValue < 2) 
            {
            }
            else if (lightningValue == 2) 
            {
                lightningValue = 0;
            }
            
            nbtTagCompound.setInteger("lIndex", lightningValue);
            System.out.println("Lightning Value: " + lightningValue);
        }

  13. EDIT: I realized that there is actually the setLightningIndex function that gets the server to crash. And this is the error i get everytime:

    Quote

    [19:52:05] [Netty Server IO #1/ERROR] [FML]: There was a critical exception handling a packet on channel etauric
    java.lang.NullPointerException: null
        at com.etauricstaff.etauricmod.items.ItemZeusLightningCharged.setLightningIndex(ItemZeusLightningCharged.java:92) ~[ItemZeusLightningCharged.class:?]
        at com.etauricstaff.etauricmod.network.MessageGetPlayer.handleServerSide(MessageGetPlayer.java:43) ~[MessageGetPlayer.class:?]
        at com.etauricstaff.etauricmod.network.MessageBase.onMessage(MessageBase.java:17) ~[MessageBase.class:?]

    And this is how my setLightningFunction looks right now:

    Quote

        public void setLightningIndex(ItemStack item, int lightningValue) 
        {
            NBTTagCompound nbtTagCompound = item.getTagCompound();
            
            if (lightningValue < 2) 
            {
            }
            else if (lightningValue == 2) 
            {
                lightningValue = 0;
            }
            
            nbtTagCompound.setInteger("lIndex", lightningValue);
            
            Utils.getLogger().info(lightningValue);
        }

     

  14. I do in-fact know how static works, this was actually me being frustrated and just trying everything(which is never a good thing). Static is a declaration that has the same value for the class, including all individual objects that stem from the class has the same value. I have now removed those. I realized now aswell, but i don't know how to get that specific itemstack and then use the method since i cannot cast directly to an itemstack. This is what i have for now, and it is not valid/or working method, just starting the method. 

    		if (player.getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.ZEUS_LIGHTNING_CHARGED) 
    		{
    			System.out.println("Succesfully retrieved Item.");
    			
    			ItemStack weapon = player.getHeldItem(EnumHand.MAIN_HAND);
    			((ItemZeusLightningCharged)weapon).setLightningIndex(weapon, + 1);
    		}

    How do i cast directly to the itemstack and not the item class as a whole? Because i can get the itemstack, but not cast it directly to the itemstack and change that specific itemstack. 

    [16:42:22] [Netty Server IO #1/INFO] [STDOUT]: [com.etauricstaff.etauricmod.network.MessageGetPlayer:handleServerSide:36]: Succesfully retrieved Item.
    [16:42:22] [Netty Server IO #1/INFO] [STDOUT]: [com.etauricstaff.etauricmod.network.MessageGetPlayer:handleServerSide:39]: Itemstack: 1xitem.zeus_lightning_charged@0

     

  15. Thank you for the advice. I have tried to make something like that. However, the problem is that the player doesn't register the active itemstack, and instead has it as simple air. And i don't really know how to fix that. 

    			((ItemZeusLightningCharged)player.getHeldItemMainhand().getItem()).setLightningIndex(player.getActiveItemStack(), +1);

    This is the function that i'm calling when the player presses a button to change the firing mode. After that, the lightning index is going up, and then the item property is supposed to override and give the item a new texture. 

    	public static int getLightningIndex(ItemStack item) 
    	{
    	    NBTTagCompound nbtTagCompound = item.getTagCompound();
    	    
    	    if(nbtTagCompound != null)
    		    return nbtTagCompound.getInteger("lIndex");
    	   
    	   return 0;
        }
       
        public static void setLightningIndex(ItemStack item, int lightningValue) 
        {
    	    NBTTagCompound nbtTagCompound = item.getTagCompound();
    	    
    	    if (lightningValue < 2) 
    	    {
    	    }
    	    else if (lightningValue == 2) 
    	    {
    	    	lightningValue = 0;
    	    }
    	    
    	    nbtTagCompound.setInteger("lIndex", lightningValue);
    	   
    	    ItemZeusLightningCharged.lightningIndex = lightningValue;
    	    
    	    Utils.getLogger().info(lightningValue);
    	}

    This is the methods i'm using to get the index number. 

    	public static int lightningIndex;

    This is the int/float i'm using to check if the item should override. 

  16. So the problem is very simple, i want the item i'm holding to change, and not the other ones of the same item in my inventory. Here is the class with the method. Any ideas?

    	EntityLightningBolt lightning;
    	
    	private int lightning_index;
    	
    	public ItemZeusLightningCharged(String unlocalizedName) 
    	{
    		super(unlocalizedName);
    		this.setCreativeTab(CreativeTabs.COMBAT);
    		this.lightning_index = 0;
    		
    		this.addPropertyOverride(new ResourceLocation(Reference.MODID, "zeus_mode"), new IItemPropertyGetter() 
    		{
    			@Override
    			public float apply(ItemStack stack, World worldIn, EntityLivingBase entityIn) 
    			{
    				Utils.getLogger().info("Itemstack: " + stack);
    				if (entityIn != null && entityIn.getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.ZEUS_LIGHTNING_CHARGED)
    				{
    					Utils.getLogger().info("Player has Item.");
    					return (float)((ItemZeusLightningCharged)entityIn.getHeldItem(EnumHand.MAIN_HAND).getItem()).lightning_index;
    				}
    				else 
    				{
    					return 0.0F;
    				}
    			}
    		});
    	}

    To clarify, the lightning index is an int that resembles the different modes. 

     

    Edit: This doesn't actually work serverside either.

  17. To start off. The item in question is working, the problem lies in my eventhandler that is responsible for switching the firing modes when a button is pressed. 

    	private static boolean first_keypress = true;
    	private static EntityLivingBase player;
    	private static ItemZeusLightningCharged z_lightning;

    These are the variables that i'm using. The first_keypress is used to keep the key triggered once, and then you can trigger it once more after you release it. 

    The player is to check if the entity is a player.

    The lightning is used as the weapon reference.

    	@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
    	public static void onItemCheck(LivingUpdateEvent event) 
    	{
    		if (event.getEntityLiving() instanceof EntityPlayerMP) 
    		{
    			player = (EntityPlayerMP) event.getEntityLiving();
    			
    			if (event.getEntity() == player && player.getHeldItemMainhand().getItem() == ModItems.ZEUS_LIGHTNING_CHARGED) 
    			{
    				z_lightning = (ItemZeusLightningCharged) player.getHeldItemMainhand().getItem();
    			}
    			else 
    			{
    				z_lightning = null;
    			}
    		}
    	}

    This is the method that checks if the entity is an instance of entityplayer, and if it is, it changes the player variable to the entity. 

    And under that we have a check to see if the player is holding the lightning weapon. And if it is, it changes the weapon variable to the weapon the player is holding. And if it isn't holding the weapon, the weapon reference is null. 

    	@SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)
    	public static void onEvent(KeyInputEvent event)
    	{
    	    KeyBinding[] keyBindings = ClientProxy.keyBindings;
    	   
    	    if (keyBindings[0].isPressed()) 
    	    {
    	    	if (first_keypress) 
    	    	{
    	    		first_keypress = false;
    	    		
    	    		Utils.getLogger().info("Trying to check Item.");
    	    		checkItem();
    	    	}
    	    }
    	    else if (!keyBindings[0].isPressed()) 
    	    {
    	    	first_keypress = true;
    	    }
    	}
    	
    	private static void checkItem() 
    	{
    		if (z_lightning != null) 
    		{
    			Utils.getLogger().info("Checked Item.");
        		z_lightning.lightningIndexController();
    		}
    	}

    Next we have the keycheck. If the player presses the designated keybinding and it's the first keypress, then it calls checkItem();. It then changes the first_keypress to false and when you release the button, it changes to true. I am probably going to change the boolean to something as a timer instead if i have more of these events. 

    Anyway, the checkItem(); checks if the weapon reference isn't null, and if it isn't null, it then gets the weapon reference and calls indexController(); on the weapon reference.

    	public void lightningIndexController() 
    	{
            if (this.lightning_index < 2) 
            {
            	this.lightning_index += 1;
            }
            if (this.lightning_index == 2) 
            {
            	this.lightning_index = 0;
            }
            
    		Utils.getLogger().info("Lightning Index: " + this.lightning_index);
    	}

    The index controller adds a number to the index if it is lower than the maximum number, and resets to 0 if it goes to the maximum number. 

     

    Now, the problem is that this doesn't work on servers, it does however work on singleplayer worlds. I have done several checks, and the problem seems to be that the weapon reference doesn't get stored, it only changes to the current weapon inside the weaponcheck. After the weaponcheck inside the updateevent, it just goes back to null. I don't know why this is the case on servers, but not on singleplayer worlds. Would appreciate some pointers here. ^^

     

    EDIT: SOLVED IT! I created and used packets to fix it. 

  18.         	for (Entity entity : this.friendlyList) 	
            	{
            		if (entity.isDead) 
            		{
            			this.friendlyList.remove(entity);
            		}
            	}

    Noticed aswell that if an undead dies, it crashes, i tried making this method to fix it, but to no avail. 

     

    Edit: fixed it. Removed the method in its entirety and it somehow solved the problem ¯\_(ツ)_/¯

     

    But i still need help regarding selecting target that is closest to the entity. 

        @Override
      public void setAttackTarget(EntityLivingBase entitylivingbaseIn) 
      {
      	if (this.canTarget) 
      	{
      		this.enemyList.removeAll(this.friendlyList);
      		Entity enemy = (Entity) this.enemyList.get(0);
      		double d0 = this.getDistanceSqToEntity((Entity) enemy);
      		EntityLivingBase entityToAttack = (EntityLivingBase) enemy;
      		
      		if (d0 < 30.0D && d0 > 0) 
      		{
      			entitylivingbaseIn = (EntityLivingBase) enemy;
          		super.setAttackTarget(entitylivingbaseIn);
      		}
      		
      		else
      		{
      			super.setAttackTarget(null);
      		}
      	 }
      }

    I've started with this, but it's nowhere near done. So i need a few pointers to get the target i want. 

     

    Edit: I fixed it! Thanks for all your help guys! ^^

        @Override
      public void setAttackTarget(EntityLivingBase entitylivingbaseIn) 
      {
      	if (this.canTarget) 
      	{
            for (Entity entity : this.enemyList)
            {
                double d0 = this.getDistanceSqToEntity(entity);
    
                if (d0 < 40.0D)
                {
                	super.setAttackTarget((EntityLivingBase) entity);
                }
            }
      	}
      	
      	else 
      	{
    		super.setAttackTarget(null);
      	}
      }
    @Override
    	protected void updateAITasks() 
    	{
    		this.targetList = this.world.getEntitiesWithinAABBExcludingEntity(this, new AxisAlignedBB((double)this.posX - 17.5D, (double)this.posY - 17.5D, (double)this.posZ - 17.5D, (double)this.posX + 17.5D, (double)this.posY + 17.5D, (double)this.posZ + 17.5D));
    		
        	if (this.getAttackTarget() == null && this.isAlly()) 
        	{
            	
        		for (Entity entity : this.targetList) 
            	{
            		if (entity instanceof EntityUndead && ((EntityUndead) entity).isAlly() && !this.friendlyList.contains(entity)) 
            		{
            			this.friendlyList.add(entity);
            		}
            		
            		if (entity instanceof EntityPlayerMP && !this.friendlyList.contains(entity)) 
            		{
            			this.friendlyList.add(entity);
            		}
            	}
        	}
        	
        	else if (!(this.getAttackTarget() == null)) 
        	{
        		this.canTarget = false;
        		
        		if (this.friendlyList.contains(this.getAttackTarget())) 
        		{
        			this.setAttackTarget(null);
        		}
        	}
        		
        	this.targetList.removeAll(this.friendlyList);
        	this.enemyList.clear();
        	this.enemyList.addAll(this.targetList);
        		
        	if (!this.enemyList.isEmpty()) 
        	{
        		this.canTarget = true;
        	}
        	else if (this.enemyList.isEmpty())
        	{
        		this.canTarget = false;
        	}
        }

     

  19. 1 hour ago, Meldexun said:

    Probably because you set the size of your friendlyList and enemyList to 32

    Tried a much higher limit aswell as no limit. But it still crashes. Any other suggestion on why it crashes? It gets called too often in updateAITasks and i should use some other update method? 

     

    Undead class: https://github.com/triphion/Ancient-Mod/blob/master/src/main/java/ancient/entity/EntityUndead

  20. 16 hours ago, Meldexun said:

    You could make a for loop and check for every entity in the targetList if it is an ally or a player and then add it to your friendlyList.

        	if (this.getAttackTarget() == null && this.isAlly()) 
        	{
            	for (Entity entity : this.targetList) 
            	{
            		if (entity instanceof EntityUndead && ((EntityUndead) entity).isAlly() && !friendlyList.contains(entity)) 
            		{
            			friendlyList.add(entity);
            		}
            		
            		if (entity instanceof EntityPlayerMP && !friendlyList.contains(entity)) 
            		{
            			friendlyList.add(entity);
            		}
            	}
        	}

    Did it and it works, now however i need to check for all entities in the enemy list for the one that is closest to the entity. Any suggestions? 

     

    Edit: I realized that the game crashes when there's too many loyal undeads. Not sure where in the code it gets overexerted. 

  21. What i'm trying to achieve is a filtering system where my loyal undeads will select its next target based on a list that will get updated in updateAITasks. I think i have almost got it, but i'm still running into a few problems, such as the entity selecting a few targets that is not supposed to be targeted. To make sure this does what it's supposed to, i made a targetList which creates an aabb around the entity and then checks if there are any allies in that aabb, if there are, it adds the allies in the aabb. Or atleast is supposed to, but my problem is that i don't know how to reference all the friendly ones and then add them all at the same time. 

     

    My entity class = https://github.com/triphion/Ancient-Mod/blob/master/src/main/java/ancient/entity/EntityUndead

     

    Worth noting is the way i'm adding and filtering. So first of i start with checking if the current target is null and if the targetList has any loyal undeads or players in it. If it has, then it's supposed to add them all. Then i remove them from the targetList and then add all of the remaining entities in the enemyList. Then every time this method gets called, so as to not overexert anything, i remove all the entities in the enemyList and then the process continue. 

×
×
  • Create New...

Important Information

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