Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

hmm, okay so debugged and your right, there is a problem there.... blockId = the id for air.... then 2 lines later if the blockId is grass set it to dirt..... how the hell does it get into that if statement if the Id should be 0 0.o

Posted

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

Posted

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/

Posted

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.

Posted

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?

Posted

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/

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



×
×
  • Create New...

Important Information

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