• 0

    posted a message on Better way to check for Entities in World. [SOLVED]
    Quote from Choonster»


    You can use Java 8 with any version of Minecraft, though only newer versions of Forge will warn the user when they're using mods that require Java 8 while running an older version.


    ConcurrentModificationException is also thrown when you add an element to a collection while iterating through it. World#spawnEntityInWorld adds the Entity to World#loadedEntityList, you call this while iterating through that list.

    I solved this by creating a new list from the stream of matching EntityItems found in World#loadedEntityList (the Stream#collect call) and then iterating through the new list. This is probably more tedious and expensive to do without streams, so I'd recommend creating a list to store the EntityItems you want to spawn and then spawning them after the outer loop.

    remainingInputs should also be declared in the outer loop.



    Instead of creating the new list to store the EntityItem i want to spawn, i just declared a null EntityItem, assigned it in the loop in which i spawned the item previously, and then spawned it after a null check. It works perfectly, and doesn't lag with those 3 items.



    Thanks for all the help.

    Posted in: Modification Development
  • 0

    posted a message on Better way to check for Entities in World. [SOLVED]
    Quote from Choonster»


    I'm not sure exactly what's preventing it from working, but I do see some mistakes.

    • You're still using a global timer. Why should a book being spawned at 0,0,0 in the Overworld affect a book being spawned at 20,100,20 in the Nether?
    • You're removing elements from the items Set as you're iterating through it, which is undefined behaviour that will usually cause an error. The only way to remove an element from a collection while iterating is with Iterator#remove. You don't actually need to iterate through the Set at all, just use Set#contains or the return value of Set#remove.
    • You're also removing elements from World#loadedEntityList while iterating it.
    • The foundEntityItems List should be defined within the outer for loop or cleared at the end of it to prevent partially matching entities (e.g. a book with no bone or feather near it) from being modified.
    • You're spawning your book twice.

    I've implemented this in 1.10.2 using some Java 8 features like streams, lambdas and method references here. I didn't include a timer, but that could be done using capabilities.



    I'm still working on 1.8, so I can't use the lambadas, but I updated the code a bit by adding the hashset INPUT and creating a mutable copy of it.

    However, I'm getting a ConcurrentModificationException on my outer for-loop line, and I don't know why it's causing it, I thought that error only shows if you try removing an object of a list while looping through it, and I don't loop through my Set.

    Here is the error,
    and Here is the current code.

    Posted in: Modification Development
  • 0

    posted a message on Better way to check for Entities in World. [SOLVED]
    Quote from Leviathan143»

    Doesn't work how? Does it crash or does it just not work?



    Just doesn't work.

    Posted in: Modification Development
  • 0

    posted a message on Better way to check for Entities in World. [SOLVED]
    http://pastebin.com/Mqu6Zu2w

    This doesn't work. I can't seem to see what I'm doing wrong.

    Posted in: Modification Development
  • 0

    posted a message on Better way to check for Entities in World. [SOLVED]
    Quote from UpcraftLP»

    What about using the Item#onEntityItemUpdate() method of your first item to check for the second one?


    How could I do that using vanilla Items? I'm doing this inside my EventHandler, and I thought you only used Events inside there when you are using stuff from vanilla minecraft?
    Posted in: Modification Development
  • 0

    posted a message on Better way to check for Entities in World. [SOLVED]

    Got it working!

    Since I only had 2 items to check for, I removed the Set and the Array, and did one more check if forgot at the top for EntityItem

    And it seems to be working, with fine performance (frame rate is pretty constant)

    I did it with Choonster's method: by getting one item from the List of entities and then checking for the other one with

    World.getEntitiesWithinAABBExcludingEntity


    Here's the code: (I'm open to any other suggestions however)


    @SubscribeEvent
    public void onWorldTick(WorldTickEvent event) {
     if (event.side.isServer()) {
     	World world = event.world;
     		// The item will spawn on the server side. If you don't check, it
     		// will run on client and create a 'phantom' item
     		if (!world.isRemote) {
     			Item wantedItem = Items.bone;
    
     			if (bookSpawnDelay > 0)
     				bookSpawnDelay--;
     				else {
    				 @SuppressWarnings("unchecked")
     				List < Entity > entities = world.loadedEntityList;
     				for (int i = 0; i < entities.size(); i++) {
     					// Wanted to be book item
     					if (entities.get(i) instanceof EntityItem) {
     					EntityItem item = (EntityItem) entities.get(i);
     					if (item.getEntityItem().getItem() == Items.book) {
     					int xBound = item.getPosition().getX() + 3;
     					int yBound = item.getPosition().getY() + 3;
     					int zBound = item.getPosition().getZ() + 3;
     					List < Entity > list = world.getEntitiesWithinAABBExcludingEntity(item,
     						new AxisAlignedBB(item.getPosition(), new BlockPos(xBound, yBound, zBound)));
     					for (int j = 0; j < list.size(); j++) {
     						Entity entity = list.get(j);
     						if (entity instanceof EntityItem) {
     						EntityItem entityItem = (EntityItem) entity;
     						if (entityItem.getEntityItem().getItem() == wantedItem) {
     							bookSpawnDelay += 20;
     							int x = item.getPosition().getX();
     							int y = item.getPosition().getY();
     							int z = item.getPosition().getZ();
     							WorldServer worldServer = (WorldServer) world;
     							worldServer.spawnParticle(EnumParticleTypes.SMOKE_LARGE, false, x + 0.5 D,
     									y + 1.0 D, z + 0.5 D, 1, 0.0 D, 0.0 D, 0.0 D, 0.0 D, new int[0]);
     							world.spawnEntityInWorld(new EntityItem(world, x, y, z,
     							new ItemStack(ARKCraftItems.info_book)));
     							entityItem.getEntityItem().stackSize--;
     							item.getEntityItem().stackSize--;
     							if (entityItem.getEntityItem().stackSize <= 0)
     							entityItem.setDead();
     							if (item.getEntityItem().stackSize <= 0)
     							item.setDead();
    
     							}
     						}
     					}
     				}
    
     			}
    		 }
     		}
     	}
     	}
     }							
    Posted in: Modification Development
  • 0

    posted a message on Better way to check for Entities in World. [SOLVED]
    Quote from Choonster»

    I'd suggest iterating through the list once to find the first item entity, then using World#getEntitiesInAABBexcluding to get all other item entities with matching items nearby.


    You can create a Set containing the Items you want to find, then remove each Item as you find it. You can also create a List to contain the matching EntityItems as you find them. When the Set is empty, you can perform the effect, iterate through the List, reduce each item entity's stack size by 1 and call Entity#setDead if the stack size is less than or equal to 0.





    Is the way I create my AxisAlignedBB correct?

    What do I use instead of TreeSet when I declare the Set?

    My code is really messy. Am I doing something wrong? Looping through unnecessarily? I only need to check for two items, so is the best way really to use a set?


    I didn't add the array list, because I only need to check for two items. (I know in my post I said three, but I only really need two)

    I tried doing it like this:

    Posted in: Modification Development
  • 0

    posted a message on Better way to check for Entities in World. [SOLVED]

    So, i've been doing a feature where you can throw 2 items on the ground, and then get an item back.

    Currently, i'm using onWorldTick() to tick every time the world ticks, and inside the method, I create an instance of world.loadedEntityList

    Then, I loop through 2 times, offsetting the second loop by one.

    I create positions, instances of the EntityItem and instances of the Item inside EntityItem.

    I then check for my desired items in loadedEntityList.

    If I have those, i wait 100 ticks, then spawn my desired item, decrement the stackSize of the EntityItem, and remove the Entities.


    //Checked if world is on server side with both
    if(event.side.isServer()) {
    World world = event.world;
    if(!world.isRemote) {
    List<Entity> entities = world.loadedEntityList;
    for (int i = 0; i < entities.size(); i++)
    {
        for (int j = 1; j < entities.size(); j++)
        {
            if (entities.get(i) instanceof EntityItem && entities.get(j) instanceof EntityItem)
            {
                EntityItem target = (EntityItem) entities.get(i);
                EntityItem targetJ = (EntityItem) entities.get(j);
     
                int x = target.getPosition().getX();
                int y = target.getPosition().getY();
                int z = target.getPosition().getZ();
     
                int xJ = targetJ.getPosition().getX();
                int yJ = targetJ.getPosition().getY();
                int zJ = targetJ.getPosition().getZ();
     
                Item item = target.getEntityItem().getItem();
                Item itemJ = targetJ.getEntityItem().getItem();
     
                if ((item == Items.book && itemJ == Items.bone) || (item == Items.bone && itemJ == Items.book) && !target.isDead && !targetJ.isDead)
                {
                    if (target.ticksExisted > 100 && targetJ.ticksExisted > 100)
                    {
                        //This is just position checking, I don't think there's much to change here?
                        if (Math.abs(x - xJ) <= 3 && Math.abs(y - yJ) <= 1 && Math
                                                    .abs(z - zJ) <= 3) {
                            target.getEntityItem().stackSize--;
                                                targetJ.getEntityItem().stackSize--;
                                                if (target.getEntityItem().stackSize == 0) world
                                                        .removeEntity(target);
                                                if (targetJ.getEntityItem().stackSize == 0) world
                                                        .removeEntity(targetJ);
                        }
    //closing brace stuff



    My questions are:

    - Is this the best way to do this? When i add a third loop, it lags out the game quite a lot, and even with only two loops, it decreases performance. I first thought of using some sort of event where it gets called every time an EntityItem hit a block, but ended up not finding anything and going with the loops.


    - If there is no other way to do this, how can I check for a third item without rendering the game almost unplayable?


    Thanks

    Posted in: Modification Development
  • 1

    posted a message on The Deep Sea Mod

    I've always had a love for sea life. Love what you're doing!

    Posted in: WIP Mods
  • 0

    posted a message on [WIP] ARKCraft | The ARK: Survival Evolved Minecraft Mod (BETA is out now!)

    A bit of explosion in your life :)

    (This is just a different version we played around with to craft the info book)

    Posted in: Minecraft Mods
  • 0

    posted a message on [WIP] ARKCraft: Survival Evolved - Dinos, Taming, Breeding, and More!

    Hey! We've switched forums. Look at all our new progress, and get actual responses to your queries :) (apart from this one of course)

    http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/2722534-wip-arkcraft-the-ark-survival-evolved-minecraft

    Posted in: WIP Mods
  • 0

    posted a message on [WIP] ARKCraft: Survival Evolved - Dinos, Taming, Breeding, and More!

    [filthy casual hating intensifies]

    Quote from aletab5»

    72 try 297
    Posted in: WIP Mods
  • 0

    posted a message on [WIP] ARKCraft: Survival Evolved - Dinos, Taming, Breeding, and More!

    look in FAQ

    Posted in: WIP Mods
  • 0

    posted a message on [WIP] ARKCraft: Survival Evolved - Dinos, Taming, Breeding, and More!

    If that is in ARK, we will add it as a biome, most likely.

    Posted in: WIP Mods
  • 0

    posted a message on [WIP] ARKCraft: Survival Evolved - Dinos, Taming, Breeding, and More!

    1.Is the world generation gonna be same as the game like the caves and the landscape?

    A: Yes. It is planned that world generation will be the same as in vanilla minecraft - The reason we are planning to have an extra world is so that people can decide not to generate the special biomes we have planned and still enjoy the other features of ARK.


    note: maybe inside a server config file we will have that option, to generate ark biomes or not to generate them.


    2.Are the dinosaurs gonna fight each other?

    A: As I'm aware, in ARK dinosaurs do fight each other, so I think that will be added.


    3.Will the mechanics of the mod gonna be the same as the game? (Lighting, gravity, the cold, heat, and also weight of the items holding food spoilage)

    A: We thought that most of those things will just be annoying to the player. But, i guess if enough people want it after the release, we will find some way to do it, and maybe put it in the config. Right now we are still working more on core concepts in the mod (like the dinos, the book, farming, etc.)


    4.Are the structures in the game gonna be same as the mod?

    A: I think we are going to be adding some structure generation for some ARK structures, but that might come after the first alpha release.

    Posted in: WIP Mods
  • To post a comment, please or register a new account.