Jump to content

help with an algorithm?


jamiemac262

Recommended Posts

so i'm (still) updating sim-u-kraft to 1.7 and have found a pretty serious bug in the building constructor.

 

for those of you yet to be blessed by the beauty of this mod in 1.6, the Building constructor allows Sims to build houses/shops/factories/anything really if there's a blueprint for it.

 

it takes a txt file full of letters and uses it as a 3D plan of the building in question. a sim is hired, a building chosen and the sim will then build the building.

 

problem is that the way it works just now, the building is just a big block of dirt. i was wondering if someone could help me either resolve the bug or find a new way to do the job?

 

 

here is the code for the builder job class:

 

package info.satscape.simukraft.common.jobs;

import info.satscape.simukraft.ModSimukraft;
import info.satscape.simukraft.ModSimukraft.GameMode;
import info.satscape.simukraft.common.Building;
import info.satscape.simukraft.common.CommonProxy.V3;
import info.satscape.simukraft.common.EntityConBox;
import info.satscape.simukraft.common.FolkData;
import info.satscape.simukraft.common.FolkData.FolkAction;

import java.io.Serializable;
import java.util.ArrayList;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;

public class JobBuilder extends Job implements Serializable
{
    private static final long serialVersionUID = -1177665807904279141L;

    public Stage theStage;
    public FolkData theFolk = null;
    public Vocation vocation = null;

    public int runDelay = 1000;
    public long timeSinceLastRun = 0;

    private transient ArrayList<IInventory> constructorChests = new ArrayList<IInventory>();
    private transient Building theBuilding = null;
    private transient EntityConBox theConBox = null;
    private transient long lastNotifiedOfMaterials = 0;

    /**
     * used to delay the sound effect so it only fires every 2 seconds
     * regardless of build delay
     */
    private transient long soundLastPlayed = 0l;

    int l = 0, ftb = 0, ltr = 0; // 3d build loops
    int xo = 0, zo = 0, acount = 0;
    int cx, cy, cz, ex, ey, ez, bx = 0, by = 0, bz = 0;

    public JobBuilder()
    {
        // not used
    }

    public JobBuilder(FolkData folk)
    {
        theFolk = folk;

        if (theStage == null)
        {
            theStage = Stage.IDLE;
        }

        if (theFolk == null)
        {
            return;
        } // is null when first employing, this is for next day(s)

        if (theFolk.destination == null)
        {
            theFolk.gotoXYZ(theFolk.employedAt, null);
        }

        this.theBuilding = theFolk.theBuilding;
    }

    public void resetJob()
    {
        theStage = Stage.IDLE;
    }

    @Override
    public void onUpdate()
    {
        if (theFolk == null)
        {
            return;
        }

        super.onUpdate();

        //theFolk.levelBuilder=10;
        //ModSimukraft.states.credits=100000;

        if (!ModSimukraft.isDayTime())
        {
            theStage = Stage.IDLE;
        }

        super.onUpdateGoingToWork(theFolk);

        if (theStage == Stage.WAITINGFORRESOURCES)
        {
            runDelay = 3000;

            if (theBuilding != null)
            {
            }
        }

        if (theStage == Stage.INPROGRESS)
        {
            if (step == 1)
            {
                runDelay = (int)(2000 / theFolk.levelBuilder);
            }
        }

        if (System.currentTimeMillis() - timeSinceLastRun < runDelay)
        {
            return;
        }

        timeSinceLastRun = System.currentTimeMillis();

        if (theFolk.theirJob != null)
        {
            if (theFolk.vocation != Vocation.BUILDER)
            {
                theFolk.selfFire();
                return;
            }
        }

        theFolk.updateLocationFromEntity();
        int dist = theFolk.location.getDistanceTo(theFolk.employedAt);

        if (dist <= 3 && theStage == Stage.WORKERASSIGNED)
        {
            theFolk.action = FolkAction.ATWORK;
            theFolk.statusText = "Arrived at work";
            theStage = Stage.BLUEPRINT;
        }

        if (dist < 10 && theStage == Stage.WORKERASSIGNED && theFolk.destination == null)
        {
            theFolk.action = FolkAction.ATWORK;
            theFolk.statusText = "Arrived at work";
            theStage = Stage.BLUEPRINT;
        }

        // ////////////////IDLE
        if ((theStage == Stage.IDLE || theStage == Stage.WORKERASSIGNED)
                && ModSimukraft.isDayTime())
        {
            if (theFolk.action != FolkAction.ONWAYTOWORK)
            {
                theStage = Stage.WORKERASSIGNED;
            }
        }
        else if (theStage == Stage.WORKERASSIGNED)
        {
        }
        else if (theStage == Stage.BLUEPRINT)
        {
            stageBlueprint();
        }
        else if (theStage == Stage.WAITINGFORRESOURCES)
        {
            stageWaitingForResources();
        }
        else if (theStage == Stage.INPROGRESS)
        {
            stageInProgress();
        }
        else if (theStage == Stage.COMPLETE)
        {
            stageComplete();
        }
    }

    private void stageBlueprint()
    {
        theBuilding = theFolk.theBuilding;

        if (theBuilding == null)
        {
            theFolk.statusText = "Please choose which building I should build";
        }
        else
        {
            theFolk.statusText = "Looking through blueprints...";
            /*
            if (theBuilding.structure[theBuilding.structure.length - 1] == null) {
            	theBuilding.loadStructure(true);
            }
             */
            theFolk.updateLocationFromEntity();
            double dist = theFolk.location.getDistanceTo(theFolk.employedAt);

            if (dist < 4)
            {
                theFolk.stayPut = true;
            }

            if (ModSimukraft.configFolkTalking)
            {
                if (theFolk.gender == 0)
                {
                    jobWorld.playSound(
                        theFolk.location.x, theFolk.location.y,
                        theFolk.location.z, "satscapesimukraft:readym", 1f, 1f, false);
                }
                else
                {
                    jobWorld.playSound(
                        theFolk.location.x, theFolk.location.y,
                        theFolk.location.z, "satscapesimukraft:readyf", 1f, 1f, false);
                }
            }

            theStage = Stage.WAITINGFORRESOURCES;
            step = 1;

            // create the conBox entity
            if (this.theConBox == null)
            {

                World world = MinecraftServer.getServer()
                              .worldServerForDimension(theFolk.location.theDimension);
                this.theConBox = new EntityConBox(world);
                this.theConBox.theFolk = theFolk;
                //this.theConBox.theFolk.theBuilding.loadStructure(true);
                this.theConBox.setLocationAndAngles(theFolk.employedAt.x + 2, theFolk.employedAt.y, theFolk.employedAt.z, 0f, 0f);

                if (!world.isRemote)
                {
                    world.spawnEntityInWorld(this.theConBox);
                }
            }
        }
    }

    private void stageWaitingForResources()
    {
        theFolk.isWorking = false;

        if (step == 1)
        {
            theFolk.statusText = "Checking building resources...";
            constructorChests = inventoriesFindClosest(theFolk.employedAt, 5);

            if (constructorChests.size() == 0)
            {
                theFolk.statusText = "Please place at least one chest/storage block near to constructor block.";
            }
            else
            {
                try
                {
                    constructorChests.get(0).openInventory();
                }
                catch (Exception e)
                {
                    ModSimukraft.log.info("JobBuilder:JobBuilder's chest was null");
                }

                step = 2;
            }

            int dist = theFolk.location.getDistanceTo(theFolk.employedAt);

            if (dist < 5)
            {
                theFolk.stayPut = true;
            }
        }
        else if (step == 2)
        {
            constructorChests.get(0).closeInventory();
            theStage = Stage.INPROGRESS;
            step = 1;
        }
        else if (step == 3)     // this step triggers mid-build - just send them
        {
            // back in to keep checking
            if (theFolk.vocation == Vocation.BUILDER)
            {
                step = 2;
                theStage = Stage.INPROGRESS;

                if (theFolk.isSpawned())
                {
                    theFolk.updateLocationFromEntity();
                }

                int dist = theFolk.location.getDistanceTo(theFolk.employedAt);

                if (dist < 5)
                {
                    theFolk.stayPut = true;
                }
                else
                {
                    theFolk.gotoXYZ(theFolk.employedAt, null);
                }
            }
            else
            {
                theFolk.selfFire();
                return;
            }
        }
    }

    private void stageInProgress()
    {
        int blockId = Block.getIdFromBlock(Blocks.air);
        boolean alreadyPlaced = false;
        theFolk.updateLocationFromEntity();
        int dist = theFolk.location.getDistanceTo(theFolk.employedAt);

        if (dist > 5 && theFolk.destination == null)
        {
            theFolk.gotoXYZ(theFolk.employedAt, null);
            return;
        }

        if (step == 1)
        {
            cx = theFolk.employedAt.x.intValue();
            cy = theFolk.employedAt.y.intValue();
            cz = theFolk.employedAt.z.intValue();
            ex = theFolk.employedAt.x.intValue();
            ey = theFolk.employedAt.y.intValue();
            ez = theFolk.employedAt.z.intValue();
            bx = ex;
            by = ey;
            bz = ez;

            if (theBuilding.buildDirection.contentEquals("-x"))
            {
                bx = cx + 1;
            }
            else if (theBuilding.buildDirection.contentEquals("+x"))
            {
                bx = cx - 1;
            }
            else if (theBuilding.buildDirection.contentEquals("-z"))
            {
                bz = cz + 1;
            }
            else if (theBuilding.buildDirection.contentEquals("+z"))
            {
                bz = cz - 1;
            }
            else
            {
                ModSimukraft.sendChat("Can't determine the direction to build in, please stand on one of the four sides of the constructor when you right-click it");
                theFolk.selfFire();
                return;
            }

            ModSimukraft.sendChat(theFolk.name + " has started building a "
                                  + theBuilding.displayNameWithoutPK);
            theFolk.statusText = "Building " + theBuilding.displayNameWithoutPK;

            if (theBuilding == null || theBuilding.layerCount == 0)
            {
                ModSimukraft.sendChat(theFolk.name
                                      + " has misplaced the blueprints, fire them and try someone else.");
                return;
            }

            theFolk.stayPut = true;

            if (theBuilding == null)
            {
                theFolk.selfFire();
                return;
            }

            l = 0;
            ftb = 0;
            ltr = 0;
            acount = 0;
            step = 2;
            theBuilding.blockLocations.clear();
            
        }
        else if (step == 2)     // ///////////////// STEP 2
        {
            do
            {
                theFolk.statusText = "Building "
                                     + theBuilding.displayNameWithoutPK;

                if (theBuilding.buildDirection.contentEquals("+z"))
                {
                    xo = ltr;
                    zo = -ftb;
                }
                else if (theBuilding.buildDirection.contentEquals("-z"))
                {
                    xo = -ltr;
                    zo = ftb;
                }
                else if (theBuilding.buildDirection.contentEquals("+x"))
                {
                    xo = -ftb;
                    zo = -ltr;
                }
                else if (theBuilding.buildDirection.contentEquals("-x"))
                {
                    xo = ftb;
                    zo = ltr;
                }

                if (theBuilding == null)
                {
                    theFolk.selfFire();
                    return;
                }

                String[] bl = null;

                try
                {
                    bl = theBuilding.structure[acount].split(":");
                    System.out.println(bl);
                }
                catch (Exception e)
                {
                    ModSimukraft.log.warning("JobBuilder: NULL block in building, using Air instead");
                    bl = "0:0".split(":");
                }

                blockId = Block.getIdFromBlock(Blocks.air);
                int subtype = Integer.parseInt(bl[1]);

                if (blockId == Block.getIdFromBlock(Blocks.grass));
                {

                	blockId = Block.getIdFromBlock(Blocks.dirt);
                }

                if (theBuilding.type.contentEquals("other") && acount == 0)
                {
                	/*TODO: complete*/
                    blockId = theConBox.getEntityId();
                    subtype = 2; //control box other
                }

                if (blockId == theConBox.getEntityId())
                {
                    try
                    {
                        theBuilding.primaryXYZ = new V3((double)(bx + xo), (double)(by + l),
                                                        (double)(bz + zo), theFolk.employedAt.theDimension);
                        theBuilding.saveThisBuilding();
                    }
                    catch (Exception e)
                    {
                        ModSimukraft.log.info("JobBuilder:build is null");
                    }
                }

                if (blockId == 999 && subtype == 999)
                {
                    theBuilding.livingXYZ = new V3((double)(bx + xo), (double)(by + l),
                                                   (double)(bz + zo), theFolk.employedAt.theDimension);
                    blockId = Block.getIdFromBlock(Blocks.air);
                    subtype = 0;
                } else if (blockId==999 && subtype>=0 && subtype <=9) {
                	V3 v3=new V3((double)(bx + xo), (double)(by + l),(double)(bz + zo), theFolk.employedAt.theDimension);
                	v3.meta=subtype;
                	theBuilding.blockSpecial.add(v3);
                	blockId = 0;
                    subtype = 0;
                }

                int currBlockId = 0;
                int currBlockMeta = 0;

                try
                {
                    currBlockId = Block.getIdFromBlock(jobWorld.getBlock(bx + xo, by + l, bz + zo));
                    currBlockMeta = jobWorld.getBlockMetadata(bx + xo, by + l, bz + zo);
                    
                    if (blockId == currBlockId || (blockId==Block.getIdFromBlock(Blocks.dirt) && currBlockId==Block.getIdFromBlock(Blocks.grass))
                    	|| (blockId==Block.getIdFromBlock(Blocks.grass) && currBlockId==Block.getIdFromBlock(Blocks.dirt)))
                    {
                        alreadyPlaced = true;
                    }
                    else
                    {
                        alreadyPlaced = false;
                    }
                }
                catch (Exception e)
                {
                    theFolk.selfFire();
                    return;
                }

                String want = "";
                ItemStack wantIS = new ItemStack(Block.getBlockById(blockId), 1, 0);

                try
			{
			    want = wantIS.getDisplayName();
			    if (blockId != 0)
			    {
			        theBuilding.blockLocations.add(new V3(bx + xo, by + l, bz + zo,theFolk.location.theDimension));
			    }
			    
			}
			catch (Exception e)
			{
			    want = "?";
			    ModSimukraft.log.info("JobBuilder:wantItemStack nulled out, wantIS was null, blockID=" + blockId);
			}

                if (!alreadyPlaced)   // air block it first to clear dirt
                {
                    // away
                    if (currBlockId != 0)
                    {
                        V3 blockToRemove = new V3(bx + xo, by + l, bz + zo);
                        constructorChests = inventoriesFindClosest(theFolk.employedAt, 5);
                        mineBlockIntoChests(constructorChests, blockToRemove);
                        jobWorld.setBlock(bx + xo, by + l, bz + zo, Blocks.air, 0, 0x03);
                        theFolk.isWorking = true;
                    }
                }

                if (!alreadyPlaced)
                {
                    boolean gotBlock = false;
                    boolean requiredBlocks = blockId == Block.getIdFromBlock(Blocks.planks)
                                             || blockId == Block.getIdFromBlock(Blocks.cobblestone)
                                             || blockId == Block.getIdFromBlock(Blocks.glass)
                                             || blockId == Block.getIdFromBlock(Blocks.wool)
                                             || blockId == Block.getIdFromBlock(Blocks.brick_block)
                                             || blockId == Block.getIdFromBlock(Blocks.dirt)
                                             || blockId == Block.getIdFromBlock(Blocks.stonebrick)
                                             || blockId == Block.getIdFromBlock(Blocks.fence)
                                             || blockId == Block.getIdFromBlock(Blocks.stone)
                                             || blockId == Block.getIdFromBlock(Blocks.log);

                    if (ModSimukraft.gameMode == GameMode.NORMAL)
                    {
                        if (requiredBlocks)
                        {
                            constructorChests = inventoriesFindClosest(theFolk.employedAt, 5);
                            ItemStack got = inventoriesGet(constructorChests, new ItemStack(Block.getBlockById(blockId), 1, 0), false,false,-1);

                            if (got != null)
                            {
                                gotBlock = true;
                            }
                            else
                            {
                                gotBlock = false;
                            }
                        }
                        else
                        {
                            gotBlock = true;
                        }
                    }
                    else if (ModSimukraft.gameMode == GameMode.CREATIVE)
                    {
                        gotBlock = true;
                    }
                    else if (ModSimukraft.gameMode == GameMode.HARDCORE)
                    {
                        if (blockId != 0)
                        {
                            // provided blocks in hardcore mode     68=sign
                            if (blockId == Block.getIdFromBlock(Blocks.grass) ||
                                    blockId == Block.getIdFromBlock(Blocks.water) 
                                    || blockId == Block.getIdFromBlock(Blocks.lava) || blockId == Block.getIdFromBlock(Blocks.wall_sign)
                                    || blockId == Block.getIdFromBlock(Blocks.cake) || blockId == Block.getIdFromBlock(Blocks.stone_slab)
                                    || blockId == Block.getIdFromBlock(Blocks.wooden_slab) || blockId == Block.getIdFromBlock(Blocks.double_wooden_slab)
                                    || blockId == Block.getIdFromBlock(Blocks.double_stone_slab) || blockId == Block.getIdFromBlock(Blocks.farmland)
                                    || blockId == Block.getIdFromBlock(Blocks.wooden_door) || blockId ==Block.getIdFromBlock(Blocks.iron_door)
                                    || blockId == Block.getIdFromBlock(Blocks.bed))
                            	//// TODO: WHEN I RE-WRITE - problem here is it needs to translate blocks to items
                            {
                                gotBlock = true;
                            }
                            else
                            {
                                constructorChests = inventoriesFindClosest(theFolk.employedAt, 5);
                                ItemStack got = inventoriesGet(constructorChests, new ItemStack(Block.getBlockById(blockId), 1, 0), false,false,-1);

                                if (got != null)
                                {
                                    gotBlock = true;
                                }
                                else
                                {
                                    gotBlock = false;
                                }

                                if (blockId == theConBox.getEntityId())
                                {
                                    gotBlock = true;
                                }
                            }
                        }
                        else
                        {
                            gotBlock = true;
                        }
                    }

                    if (!gotBlock)
                    {
                        theStage = Stage.WAITINGFORRESOURCES;

                        if (want.toLowerCase().contentEquals("oak wood planks"))
                        {
                            want = "Planks";
                        }

                        if (want.toLowerCase().contentEquals("oak wood"))
                        {
                            want = "Logs";
                        }

                        theFolk.statusText = "Waiting for " + want;

                        if (System.currentTimeMillis() - lastNotifiedOfMaterials > (ModSimukraft.configMaterialReminderInterval * 60 * 1000))
                        {
                            lastNotifiedOfMaterials = System.currentTimeMillis();
                            ModSimukraft.sendChat(theFolk.name + " (who's building a " + theFolk.theBuilding.displayNameWithoutPK
                                                  + ") needs more " + want);
                        }

                        step = 3;
                        return;
                    }

                    try
                    {
                    	
                        if (!alreadyPlaced)
                        {
                            try
                            {
                                if (blockId ==212 || blockId == 3211)
                                {
                                    blockId = theConBox.getEntityId();
                                }

                                // bank control boxes
                                if (blockId == theConBox.getEntityId()
                                        && theBuilding.displayNameWithoutPK.toLowerCase().contentEquals("sim-u-bank"))
                                {
                                    subtype = 1;
                                }

                                //########### PLACE THE BLOCK
                                theFolk.stayPut = true;
                                jobWorld.setBlock(bx + xo, by + l,
                                                  bz + zo, Block.getBlockById(blockId), subtype, 0x03);
                                jobWorld.markBlockForUpdate(bx + xo, by + l, bz + zo);

                                

                                int b4 = (int)Math.floor(theFolk.levelBuilder);

                                //theFolk.levelBuilder=10.0f;
                                if (theFolk.levelBuilder < 10.0f)
                                {
                                    theFolk.levelBuilder += (0.001 / b4);
                                }

                                int aft = (int)Math.floor(theFolk.levelBuilder);

                                if (b4 != aft)
                                {
                                    ModSimukraft.sendChat(theFolk.name + " has just levelled up to Builder Level " + aft);
                                }

                                // PLAY SOUND EFFECT every 2 seconds
                                if (System.currentTimeMillis()
                                        - soundLastPlayed >= 2000)
                                {
                                    mc.worldServers[0].playSound(bx + xo, by + l,
                                                          bz + zo,
                                                          "satscapesimukraft:construction", 1f, 1f, false);
                                    soundLastPlayed = System.currentTimeMillis();
                                }

                                // spawn particles on client side
                                if (mc.worldServers[0].isRemote)
                                {
                                    mc.worldServers[0].spawnParticle("explode", bx
                                                              + xo, by + l, bz + zo, 0, 0.3f, 0);
                                    mc.worldServers[0].spawnParticle("explode", bx
                                                              + xo, by + l, bz + zo, 0, 0.2f, 0);
                                    mc.worldServers[0].spawnParticle("explode", bx
                                                              + xo, by + l, bz + zo, 0, 0.1f, 0);
                                }

                                if (blockId != 0 && ModSimukraft.gameMode != GameMode.CREATIVE)
                                {
                                    ModSimukraft.states.credits -= (0.02f);
                                }
                            }
                            catch (Exception e)
                            {
                                ModSimukraft.log.warning("JobBuilder: Possible non-existant block (from other mod) ID="
                                     + blockId);

                                try
                                {
                                    jobWorld.setBlock(bx + xo, by + l, bz + zo, Blocks.air, 0, 0x03);
                                }
                                catch (Exception e2)
                                {
                                    e2.printStackTrace();
                                }
                            } // this exceptions when another mod's block is placed down
                        }
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
                    }
                }

                //remove from requirements
                /*
                if (!want.contentEquals("")) {
                	try {
                		Iterator it = theFolk.theBuilding.requirements.entrySet().iterator();
                        while (it.hasNext()) {
                            Map.Entry pairs = (Map.Entry)it.next();
                            ItemStack is=(ItemStack) pairs.getKey();
                            if (is.itemID >0) {
                            	if (is.itemID==wantIS.itemID) {
                            		int left=theFolk.theBuilding.requirements.get(wantIS);
                					left--;
                					if (left>0) {
                						theFolk.theBuilding.requirements.put(wantIS, left);
                					} else {
                						theFolk.theBuilding.requirements.remove(wantIS);
                					}
                            	}
                            }
                        }
                	} catch(Exception e) {
                		ModSimukraft.log.info("JobBuilder:Builder requirement was null - no biggie"); }
                }
                */
                acount++;
                ltr++;

                if (ltr == theBuilding.ltrCount)
                {
                    ltr = 0;
                    ftb++;

                    if (ftb == theBuilding.ftbCount)
                    {
                        ftb = 0;
                        l++;

                        if (l == theBuilding.layerCount)
                        {
                            theStage = Stage.COMPLETE;
                            stageComplete();
                            return;
                        }
                    }
                }

                if (blockId == 0 || alreadyPlaced)
                {
                    runDelay = 0;
                }
                else
                {
                    if (ModSimukraft.gameMode == GameMode.CREATIVE)
                    {
                        runDelay = 0;
                    }
                    else
                    {
                        runDelay = (int)(2000 / theFolk.levelBuilder);
                    }
                }

                if (theFolk.theEntity != null)
                {
                    theFolk.theEntity.swingItem();
                }
            }
            while (blockId == 0 || alreadyPlaced);
        } // end step 2
    }

    private void stageComplete()
    {
        theFolk.isWorking = false;

        if (theBuilding != null)
        {
            if (theBuilding.buildingComplete)
            {
         //       return;
            }

            if (theBuilding != null)
            {
                theBuilding.buildingComplete = true;
                ModSimukraft.sendChat(theFolk.name
                                      + " has completed building a "
                                      + theBuilding.displayNameWithoutPK);
                /*TODO: Re-Implement*/
                //ModSimukraft.proxy.getClientWorld().playSound(
                 //   mc.thePlayer.posX, mc.thePlayer.posY,
                 //   mc.thePlayer.posZ, "satscapesimukraft:cash", 1f, 1f, false);
                theBuilding.saveThisBuilding();
                theFolk.theBuilding=null;
            }
            else
            {
                ModSimukraft
                .sendChat("Error: could not set the building that "
                          + theFolk.name
                          + " was building "
                          + "to 'complete', try rebuilding right away (no cost) to try again");
            }
        }

        if (theFolk.theEntity != null)
        {
            theFolk.theEntity.setSneaking(false);
        }

        theFolk.stayPut = false;
        theFolk.selfFire();
        theStage = Stage.IDLE;
        //bodgy fix to make sure buildings are complete - probably no longer needed, original bug caused by V3 class bug
        boolean activeBuilders = false;

        for (int f = 0; f < ModSimukraft.theFolks.size(); f++)
        {
            FolkData fd = ModSimukraft.theFolks.get(f);

            if (fd.vocation == Vocation.BUILDER)
            {
                activeBuilders = true;
            }
        }

        if (!activeBuilders)
        {
            for (int b = 0; b < ModSimukraft.theBuildings.size(); b++)
            {
                Building building = ModSimukraft.theBuildings.get(b);
                building.buildingComplete = true;
            }
        }
    }

    @Override
    public void onArrivedAtWork()
    {
        int dist = 0;
        dist = theFolk.location.getDistanceTo(theFolk.employedAt);

        if (dist <= 1)
        {
            theFolk.action = FolkAction.ATWORK;
            theFolk.stayPut = true;
            theFolk.statusText = "Arrived at the building site";
            theStage = Stage.BLUEPRINT;
        }
        else
        {
            theFolk.gotoXYZ(theFolk.employedAt, null);
        }
    }

    public enum Stage
    {
        IDLE, WORKERASSIGNED, BLUEPRINT, WAITINGFORRESOURCES, INPROGRESS, COMPLETE;

        @Override
        public String toString()
        {
            String ret = "";

            if (this == IDLE)
            {
                ret = "Idle";
            }
            else if (this == WORKERASSIGNED)
            {
                ret = "Builder has been hired and on their way";
            }
            else if (this == BLUEPRINT)
            {
                ret = "Builder is looking though blueprints";
            }
            else if (this == WAITINGFORRESOURCES)
            {
                ret = "Builder is checking the resources for the building";
            }
            else if (this == INPROGRESS)
            {
                ret = "Builder is busy building";
            }
            else if (this == COMPLETE)
            {
                ret = "Building work is complete";
            }

            return ret;
        }
    }
}

 

as far as i can tell, the bug is inside the onUpdate() method but beyond that i'm, lost

Link to comment
Share on other sites

I don't have the time to read this in depth right now, but if you are saying its building it all out of dirt, then your problem is somewhere around the code segment in the following spoiler.  Its the only place you set something to dirt.  That or its misreading the block ID from the file to dirt everytime.

 

 

 

                blockId = Block.getIdFromBlock(Blocks.air);

                int subtype = Integer.parseInt(bl[1]);

 

                if (blockId == Block.getIdFromBlock(Blocks.grass));

                {

 

                blockId = Block.getIdFromBlock(Blocks.dirt);

                }

 

 

 

 

 

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

so anybody else notice the semicolon at the end of the if condition? haha

 

now my new problem, this looks like a design problem, blockId is always 0, it's never set to anything else :/

 

i really would appreciate if someone could let me contact them on skype and help me out with this class

Link to comment
Share on other sites

There are several places in the code where the structure of the if statements don't make much logical sense.  For example you set it to air and then immediately test if it is grass (which can never be true at that point).  Then you test for building type which might change the block type to some sort of "entity type" (whatever that is) and then you test for the block type (usually you'd just continue with the code that handles the case), then you test if it is 999 which it could never be because it can only be air or that entity type (unless that could be 999) and so on. 

 

Anyway, the way to debug these type of things is very easy.  Just put a console statement (System.out.println("something useful")) at each point in the logic where the console statement is something useful.  Like before each if statement print out the condition you're testing so you can see if it is true or false, and after each time you change the blockID print it out.  It should be quickly obvious where things are going wrong.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Style and efficiency point here:

I see no reason why your code should ever call getBlockIdFromBlock(). Blocks are identical to or different from other blocks and can be compared directly. Their IDs are meaningless most of the time.

Link to comment
Share on other sites

just a heads up, i didnt write this code, the original developer did mention he doesnt do this professionally and thus alot of the code may not make sense haha.... i think i am going to re-write the class, instead of if statements, load the building's blueprint (which is an array i believe) into an array and then create 3 for loops, for x, y, z..... so that it builds the building in a logical manner

 

all i would need is that the x y and z loops are the sizes of the building and make it look like this

 

for y

    for z

        for x

            Block.setBlock(<block id of current block>)

 

 

 

does that make sense/ would that work?

 

thoughts?

Link to comment
Share on other sites

That makes sense and is the way I do structures.  However, it seems that the point of his mod is to have worker entities do the building step by step over time depending on available resources.  So it may be more complicated then just looping through and placing the blocks (which is normally a great way to do structures as long as you want the whole structure to instantly appear).

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I am working on a modpack. When I try to access my server, Minecraft suddenly stops responding for no apparent reason, but I tested the same modpack on my friend's PC and it functions flawlessly there. One thing I have noticed is that the message "[Render thread/WARN] [io.gi.ap.ap.Apoli/]: Received unknown attacker" appears in the log each time my game crashes. My frame rate is high, about 100, and I do not have any mods called Apoli. 9000 MB of the 16000 MB of RAM are allotted to me. Almost everything I could do has been done (updating drivers, removing some mods, lowering the graphic settings, testing singleplayer, etc.) I will leave the moderator list and the latest.log down here.   https://mclo.gs/pYqKP15 (Cannot upload due to file size on pastebin.) Mods: [✔] [1.18.2]-Medieval-Siege-Machines-v1.17 [✔] [1.18.2-forge]-Epic-Knights-8.2 [✔] AchievementOptimizer-1.18.2-1.0.2 [✔] AdvancementPlaques-1.18.2-1.4.5.1 [✔] alexsmobs-1.18.6 [✔] antiqueatlas-7.1.1-forge-mc1.18.2 [✔] Apotheosis-1.18.2-5.8.1 [✔] appleskin-forge-mc1.18.2-2.5.1 [✔] Aquaculture-1.18.2-2.3.12 [✔] aquamirae-5.api10 [✔] archbows-1.0.9-1.18.2 [✔] architectury-4.12.94-forge [✔] armorunder-mc1.18.2-3.0.1 [✔] astikorcarts-1.18.2-1.1.2 [✔] Atlas-Lib-1.18.2-1.1.8 [✔] BetterAdvancements-1.18.2-0.2.0.146 [✔] betteranimalsplus-1.18.2-11.0.10-forge [✔] betterbiomeblend-1.18.2-1.3.5-forge [✔] BetterCompatibilityChecker-1.1.21-build.48+mc1.18.2 [✔] betterfpsdist-1.18.2-1.5 [✔] BetterPingDisplay-1.18.2-1.1 [✔] blockui-1.18.2-0.0.71-ALPHA [✔] BloodAndMadness-Forge1.18.2-v2.1.4 [✔] blueprint-1.18.2-5.5.0 [✔] BOMD-Forge-1.18.2-1.0.6 [✔] Bonfires-1.18.2-1.2.18-2062213 [✔] Bookshelf-Forge-1.18.2-13.3.56 [✔] born_in_chaos_[Forge]1.18.2_1.17 [✔] BrassAmberBattleTowers-1.18.2-2.3.12 [✔] caelus-forge-1.18.1-3.0.0.2 [✔] callablehorses-1.18.2-1.2.2.5 [✔] cameraoverhaul-1.0-1.18.2 [✔] carrotslib-mc1.18.2-4.0 [✔] catalogue-1.6.2-1.18.2 [✔] champions-forge-1.18.2-2.1.6.3 [✔] citadel-1.11.3-1.18.2 [✔] cloth-config-6.5.116-forge [✔] ColdSweat-2.3-b04f [✔] collective-1.18.2-7.7 [✔] configured-2.0.1-1.18.2 [✔] connectedness-1.18.2-2.0.1a [✔] Controlling-forge-1.18.2-9.0+23 [✔] corpse-1.18.2-1.0.2 [✔] CosmeticArmorReworked-1.18.2-v2a [✔] create-1.18.2-0.5.1.f [✔] Croptopia-1.18.2-FORGE-2.1.0 [✔] ctov-2.9.4 [✔] CullLessLeaves-Reforged-1.18.2-1.0.5 [✔] curios-forge-1.18.2-5.0.9.2 [✔] DarkerSouls1.18.2Forgev1.3.1 [✔] Divine Weaponry v1.4 1.18.2 [✔] DoggyTalentsNext-1.18.2-1.18.18 [✔] domum_ornamentum-1.18.2-1.0.77-ALPHA-universal [✔] dragonmagicandrelics-1.18.2-2.1.38 [✔] dragonseeker-1.1.1-1.18.2 [✔] dungeons_enhanced-1.18.2-3.2.1 [✔] DungeonsArise-1.18.2-2.1.52-release [✔] dungeonsweaponry-1.12.2-1.18.2 [✔] EFMCompat 18.2.0 [✔] EnchantmentDescriptions-Forge-1.18.2-10.0.17 [✔] EnigmaticLegacy-2.25.0 [✔] Entity_Collision_FPS_Fix-forge-1.18.2-1.0.0 [✔] entity_model_features_forge_1.18.2-2.0.2 [✔] entity_texture_features_forge_1.18.2-6.0.1 [✔] entityculling-forge-1.6.1-mc1.18.2 [✔] epic_fight_battle_styles-1.0.2 [✔] EpicFight-18.5.24 [✔] falchionmoveset-18.5.0 [✔] FarmersDelight-1.18.2-1.2.3 [✔] Fastload-Reforged-mc1.18.2-3.4.0 [✔] ferritecore-4.2.2-forge [✔] finsandtails-1.18.2-1.1.1 [✔] fish_of_thieves-mc1.18.2-v1.1.1-forge [✔] Forge 1.18.2 Minecraft Middle Ages 0.0.4 [✔] francium-1.18.2-1.0.1 [✔] ftb-essentials-1802.2.2-build.83 [✔] ftb-library-forge-1802.3.11-build.177 [✔] geckolib-forge-1.18-3.0.57 [✔] getittogetherdrops-forge-1.18.2-1.3 [✔] Gobber2-Forge-1.18.2-2.6.37 [✔] goblintraders-1.8.0-1.18.2 [✔] goodall-1.0.2-forge [✔] gpumemleakfix-1.18.2-1.6 [✔] guardvillagers-1.18.2.1.4.4 [✔] healingcampfire-1.18.2-5.2 [✔] hexerei-0.2.2 [✔] horsecombatcontrols-1.18.2-1.0.1 [✔] iceandfire-2.1.13-1.18.2-beta-3 [✔] Iceberg-1.18.2-forge-1.0.49 [✔] ImmediatelyFastReforged-1.18.2-1.1.10 [✔] immersive_melodies-0.1.2+1.18.2-forge [✔] ironchest-1.18.2-13.2.11 [✔] ironfurnaces-1.18.2-3.3.3 [✔] irons_spellbooks-1.18.2-1.1.4.5 [✔] ItemBorders-1.18.1-1.1.5 [✔] ItShallNotTick-1.0.22-build.34 [✔] Jade-1.18.2-forge-5.3.2 [✔] JadeAddons-1.18.2-forge-2.5.0 [✔] jecalculation-forge-1.18.2-4.0.4 [✔] jeed-1.18.2-1.11 [✔] jei-1.18.2-forge-10.2.1.1008 [✔] jepp-1.18-1.0.0 [✔] JustEnoughAdvancements-1.18.2-3.2.0 [✔] justenoughbreeding-forge-1.18.2-1.2.1 [✔] JustEnoughProfessions-1.18.2-1.3.0 [✔] JustEnoughResources-1.18.2-0.14.2.206 [✔] Kobolds-2.9.3-1.18.2-final [✔] kotlinforforge-3.12.0-all [✔] L_Enders Cataclysm-0.51-changed Them -1.18.2 [✔] lazydfu-1.0-1.18+ [✔] leaky-1.18.2-1.3 [✔] LegendaryTooltips-1.18.2-1.3.1 [✔] letmedespawn-1.18.x-1.19.x-forge-1.0.3 [✔] LibX-1.18.2-3.2.19 [✔] lightspeed-1.18.2-1.0.5 [✔] lodestone-1.18.2-1.4.2 [✔] loot_journal-1.1.0-1.18 [✔] lootr-forge-1.18.2-0.3.29.71 [✔] malum-1.18.2-1.5.0.1 [✔] medieval_paintings-1.18.2-7.0 [✔] memoryleakfix-forge-1.17+-1.1.2 [✔] MerchantMarkers-1.18.2-forge-1.3.1 [✔] minecolonies-1.18.2-1.1.148-BETA [✔] MmmMmmMmmMmm-1.18.2-1.5.2 [✔] mna-2.0.0.33 [✔] modernfix-forge-5.18.0+mc1.18.2 [✔] modonomicon-1.18.2-1.33.1 [✔] mowziesmobs-1.6.3 [✔] multi-piston-1.18.2-1.2.15-ALPHA [✔] mythicmounts-18.2-7.2-forge [✔] NefsFarmDecoExpGear+v0.3(1.18.2) [✔] nutritionalbalance-1.18.2-3.2.4 [✔] obscure_api-10 [✔] occultism-1.18.2-1.84.0 [✔] octolib-1.18.2-0.3 [✔] oculus-mc1.18.2-1.6.4 [✔] OfflineSkins-1.18.2-v2 [✔] Orcz_0.83_1.18.2 [AI FIXES] [✔] origins-classes-forge-1.1.6 [✔] origins-forge-1.18.2-1.5.0.2-all [✔] Paraglider-1.18.2-1.6.0.6 [✔] Patchouli-1.18.2-71.1 [✔] physics-mod-pro-v153-forge-1.18.2 [✔] Placebo-1.18.2-6.6.7 [✔] player-animation-lib-forge-1.0.2+1.18 [✔] pluto-mc1.18.2-0.0.6 [✔] polymorph-forge-1.18.2-0.50 [✔] Prism-1.18.2-1.0.1 [✔] projectvibrantjourneys-1.18.2-4.1.1 [✔] puffish_attributes-0.5.0-1.18.2-forge [✔] puffish_skills-0.13.1-1.18.2-forge [✔] realmrpg_imps_and_demons_0.9.0_forge_1.18.2 [✔] recruits-1.18.2-1.11.4.2 [✔] reforgium-1.18.2-1.0.12a [✔] Reldas+Medieval+Armor+1.18.2(2.0) [✔] relics-1.18.2-0.6.2.4 [✔] reputation-1.18.2-1.0.0 [✔] RPG_style_more_weapons_4.9.6R [✔] Rrls-1.18.2-3.1.0-forge [✔] rubidium-0.5.6 [✔] rubidium-extra-0.4.18+mc1.18.2-build.86 [✔] saturn-mc1.18.2-0.1.5 [✔] savage_and_ravage-1.18.2-4.0.1 [✔] seaborgium-mc1.18.2-0.1.3b [✔] SereneSeasons-1.18.2-7.0.0.15 [✔] ShoulderSurfing-Forge-1.18.2-4.2.1 [✔] SimpleLogin-1.18.2-1.0.0 [✔] simplyswords-forge-1.40-1.18.2 [✔] SleepingOverhaul-2.0.2-Forge-1.18.2 [✔] smallships-forge-1.18.2-2.0.0-b1.3.1 [✔] SmartBrainLib-forge-1.18.2-1.9 [✔] smoothboot(reloaded)-mc1.18.2-0.0.4 [✔] sophisticatedbackpacks-1.18.2-3.20.2.1036 [✔] sophisticatedcore-1.18.2-0.6.4.604 [✔] soul_like_armors_reworked_1.18.2_(v138) [✔] SpartanShields-1.18.2-3.0.1 [✔] SpartanWeaponry-1.18.2-3.0.5-all [✔] SpitItOut-1.18.2-1.0.1 [✔] starterkit-1.18.2-5.3 [✔] Structory-1.18.2-1.0.2 [✔] structure_gel-1.18.2-2.4.8 [✔] structurize-1.18.2-1.0.424-ALPHA [✔] swem-forge-1.18.2-1.4.6 [✔] takesapillage-1.0.3-1.18.2 [✔] TerraForged-1.18.2-0.3.1-alpha-2 [✔] TextruesRubidiumOptions-1.0.8-mc1.18.2 [✔] theimpossiblelibrary-1.18.2-0.3.1 [✔] torchmaster-18.2.1 [✔] Totemic-forge-1.18.2-0.12.9.1 [✔] tov-0.1(ALPHA) [✔] towns_and_towers_forge-1.10.0.1+1.18.2 [✔] TravelersTitles-1.18.2-Forge-2.1.1 [✔] unoriginal-datapack [✔] untamedwilds-1.18.2-2.4.3 [✔] upgrade_aquatic-1.18.2-4.0.0 [✔] valhelsia_core-forge-1.18.2-0.4.0 [✔] valhelsia_structures-1.18.2-0.1.1 [✔] Vampirism-1.18.2-1.8.8 [✔] WeaponsOfMiracles-18.1.7.38 [✔] Werewolves-1.18.2-1.0.0.1 [✔] workers-1.18.2-1.7.8 [✔] YouDied-1.18.1-1.0.2.9 [✔] YungsApi-1.18.2-Forge-2.2.9 [✔] YungsBetterMineshafts-1.18.2-Forge-2.2 [✔] YungsBetterStrongholds-1.18.2-Forge-2.1.1 [✔] zoomerzoom-1.4
    • Turn casual moments into unforgettable dates – choose the best casual dating site! Sexy Womans from your town
    • I am trying to make a Modpack for me and my friend and the buddycard expansion mod keeps crashing is there anything I can do, I'll copy and paste the crash message and the attack a link to the crash log below: Buddycards Expainsion (buddycardsexp) encountered an error during the common_setup event phase java.lang.NoSuchMethodError: 'void com.wildcard.buddycards.item.BuddycardBinderItem.<init>(com.wildcard.buddycards.registries.BuddycardsItems$BuddycardRequirement, net.minedcraft.world.item.Item$Properties, com.wildcard.buddycards.core.BuddycardSet)'   https://drive.google.com/file/d/1XlEYKVi2uUyS_UxRKByqCKlfnVswvHbb/view?usp=sharing
    • So, my friend and I are playing modpack on version 1.20.1. Sometimes, when a friend dies, he crashes from the server and cant rejoin anymore, so I have to load backup of the world. After loading the backup, everything goes well, but then sometimes it crashes again after death. Here is lof file: https://pastebin.com/KaZTmvhc The lines where the friend crashes start at line 2471 
    • The Minecraft launcher is now "preparing" the game but is taking forever. Any suggestions?
  • Topics

×
×
  • Create New...

Important Information

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