Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make waypoints render when buildtool open #1004

Merged
merged 12 commits into from
May 17, 2017
10 changes: 5 additions & 5 deletions src/main/java/com/minecolonies/blockout/views/DropDownList.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.minecolonies.blockout.views;

import com.minecolonies.blockout.OverlayView;
import com.minecolonies.blockout.Pane;
import com.minecolonies.blockout.PaneParams;
import com.minecolonies.blockout.View;
import com.minecolonies.blockout.controls.Button;
import com.minecolonies.blockout.controls.ButtonVanilla;
import com.minecolonies.blockout.controls.Label;
import com.minecolonies.blockout.views.ScrollingList;
import com.minecolonies.blockout.OverlayView;
import com.minecolonies.blockout.Pane;
import com.minecolonies.blockout.PaneParams;
import java.util.function.Consumer;
import org.jetbrains.annotations.NotNull;

import java.util.function.Consumer;

/**
* A DropDownList is a Button which when click display a ScrollingList below it.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.minecolonies.coremod.client.gui;

import com.minecolonies.blockout.Loader;
import com.minecolonies.blockout.OverlayView;
import com.minecolonies.blockout.controls.Button;
import com.minecolonies.blockout.controls.Label;
import com.minecolonies.blockout.controls.Text;
import com.minecolonies.blockout.Loader;
import com.minecolonies.blockout.views.Window;
import com.minecolonies.coremod.lib.Constants;
import com.minecolonies.blockout.OverlayView;
import com.minecolonies.coremod.util.Log;

import java.util.function.ObjIntConsumer;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public int getCharisma()

/**
* Get the saturation of the citizen.
* @return
* @return the saturation a double.
*/
public double getSaturation()
{
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/com/minecolonies/coremod/colony/Colony.java
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ else if(averageSaturation > WELL_SATURATED_LIMIT)
increaseOverallHappiness((averageSaturation - WELL_SATURATED_LIMIT) * HAPPINESS_FACTOR);
}

int relation = guards/workers;
int relation = workers/guards;

if(relation > 1)
{
Expand Down Expand Up @@ -1265,6 +1265,7 @@ private void updateWayPoints()
if (world != null && world.getBlockState(key).getBlock() != (value.getBlock()))
{
wayPoints.remove(key);
markDirty();
}
}
}
Expand Down Expand Up @@ -1820,6 +1821,7 @@ public void removeField(final BlockPos pos)
public void addWayPoint(final BlockPos point, IBlockState block)
{
wayPoints.put(point, block);
markDirty();
}

/**
Expand Down Expand Up @@ -1896,4 +1898,13 @@ public Map<BlockPos, AbstractBuilding> getBuildings()
{
return Collections.unmodifiableMap(buildings);
}

/**
* Get all the waypoints of the colony.
* @return copy of hashmap.
*/
public Map<BlockPos, IBlockState> getWayPoints()
{
return new HashMap<>(wayPoints);
}
}
31 changes: 31 additions & 0 deletions src/main/java/com/minecolonies/coremod/colony/ColonyView.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ public final class ColonyView implements IColony
*/
private Set<Block> freeBlocks = new HashSet<>();

/**
* The Set of waypoints.
*/
private Set<BlockPos> wayPoints = new HashSet<>();

/**
* The overall happiness of the colony.
*/
private double overallHappiness = 5;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Assign this magic number 5 to a well-named constant, and use the constant instead. rule

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to call other classes or create just another constant for this.
I feel like it is okay this way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having an INITIAL_HAPPYNESS is not bad

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have that around at some places but its not on the client and I think it would be bad style if we'd call not client classes from client classes.
But then I'd have to recreate the same thing again here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best would be to make a util.constrants class with these game changing constants and use that instead of all the 5 literals. Would be good to start with that


/**
Expand Down Expand Up @@ -107,6 +115,7 @@ public static void serializeNetworkData(@NotNull final Colony colony, @NotNull f

final Set<Block> freeBlocks = colony.getFreeBlocks();
final Set<BlockPos> freePos = colony.getFreePositions();
final Set<BlockPos> waypoints = colony.getWayPoints().keySet();

buf.writeInt(freeBlocks.size());
for(final Block block : freeBlocks)
Expand All @@ -121,6 +130,12 @@ public static void serializeNetworkData(@NotNull final Colony colony, @NotNull f
}
buf.writeDouble(colony.getOverallHappiness());
buf.writeBoolean(colony.hasWarehouse());

buf.writeInt(waypoints.size());
for(final BlockPos block: waypoints)
{
BlockPosUtil.writeToByteBuf(buf, block);
}
// Citizens are sent as a separate packet
}

Expand Down Expand Up @@ -362,6 +377,7 @@ public IMessage handleColonyViewMessage(@NotNull final ByteBuf buf, final boolea

freePositions = new HashSet<>();
freeBlocks = new HashSet<>();
wayPoints = new HashSet<>();

final int blockListSize = buf.readInt();
for(int i = 0; i < blockListSize; i++)
Expand All @@ -376,6 +392,12 @@ public IMessage handleColonyViewMessage(@NotNull final ByteBuf buf, final boolea
}
this.overallHappiness = buf.readDouble();
this.hasWarehouse = buf.readBoolean();

final int wayPointListSize = buf.readInt();
for(int i = 0; i < wayPointListSize; i++)
{
wayPoints.add(BlockPosUtil.readFromByteBuf(buf));
}
return null;
}

Expand Down Expand Up @@ -569,6 +591,15 @@ public boolean hasTownHall()
return townHall != null;
}

/**
* Get a list of all waypoints in the colony view.
* @return a copy of the list.
*/
public Set<BlockPos> getWayPoints()
{
return new HashSet<>(wayPoints);
}

/**
* Returns the ID of the view.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
import net.minecraftforge.fml.relauncher.SideOnly;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.*;
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.minecolonies.coremod.colony.CitizenData;
import com.minecolonies.coremod.colony.Colony;
import com.minecolonies.coremod.colony.Structures;
import com.minecolonies.coremod.colony.buildings.AbstractBuilding;
import com.minecolonies.coremod.colony.buildings.BuildingBuilder;
import com.minecolonies.coremod.colony.jobs.JobBuilder;
import com.minecolonies.coremod.colony.Structures;
import com.minecolonies.coremod.util.BlockPosUtil;
import com.minecolonies.coremod.util.LanguageHandler;
import com.minecolonies.coremod.util.Log;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.*;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.minecolonies.coremod.entity.ai.basic;

import com.minecolonies.coremod.blocks.ModBlocks;
import com.minecolonies.coremod.colony.buildings.AbstractBuilding;
import com.minecolonies.coremod.colony.jobs.AbstractJob;
import com.minecolonies.coremod.colony.jobs.AbstractJobStructure;
import com.minecolonies.coremod.configuration.Configurations;
Expand All @@ -12,7 +11,8 @@
import com.minecolonies.coremod.placementhandlers.IPlacementHandler;
import com.minecolonies.coremod.placementhandlers.PlacementHandlers;
import com.minecolonies.coremod.util.*;
import net.minecraft.block.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
Expand Down Expand Up @@ -43,7 +43,8 @@
import java.util.stream.Collectors;

import static com.minecolonies.coremod.entity.ai.util.AIState.*;
import static com.minecolonies.coremod.placementhandlers.IPlacementHandler.ActionProcessingResult.*;
import static com.minecolonies.coremod.placementhandlers.IPlacementHandler.ActionProcessingResult.ACCEPT;
import static com.minecolonies.coremod.placementhandlers.IPlacementHandler.ActionProcessingResult.DENY;

/**
* This base ai class is used by ai's who need to build entire structures.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.minecolonies.coremod.entity.ai.citizen.miner;

import com.minecolonies.coremod.colony.buildings.BuildingMiner;
import com.minecolonies.coremod.colony.Structures;
import com.minecolonies.coremod.colony.buildings.BuildingMiner;
import com.minecolonies.coremod.colony.jobs.JobMiner;
import com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructure;
import com.minecolonies.coremod.entity.ai.util.AIState;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package com.minecolonies.coremod.event;

import com.minecolonies.coremod.colony.Structures;
import com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructure;
import com.minecolonies.coremod.entity.pathfinding.Pathfinding;
import com.minecolonies.coremod.util.constants.RenderUtils;
import com.minecolonies.structures.helpers.Settings;
import com.minecolonies.structures.helpers.Structure;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.jetbrains.annotations.NotNull;
Expand All @@ -12,11 +19,31 @@ public class ClientEventHandler
{
/**
* Used to catch the renderWorldLastEvent in order to draw the debug nodes for pathfinding.
*
* @param event the catched event.
*/
@SubscribeEvent
public void renderWorldLastEvent(@NotNull final RenderWorldLastEvent event)
{
Pathfinding.debugDraw(event.getPartialTicks());

final Structure structure = Settings.instance.getActiveStructure();
if (structure != null)
{
final BlockPos position = Settings.instance.getPosition();
if (Settings.instance.getStructureName().contains(AbstractEntityAIStructure.WAYPOINT_STRING))
{
RenderUtils.renderWayPoints(position, Minecraft.getMinecraft().theWorld, event.getPartialTicks());
}
else
{
Structures.StructureName name = new Structures.StructureName(Settings.instance.getStructureName());
if (name.isHut())
{
RenderUtils.renderColonyBorder(position, Minecraft.getMinecraft().theWorld, event.getPartialTicks(), Minecraft.getMinecraft().thePlayer);
}
}
}
RenderUtils.colonyBorder.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.HashMap;
import java.util.Map;

/**
* Class handling the colony styles messages.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.minecolonies.coremod.network.messages;

import com.minecolonies.coremod.configuration.Configurations;
import com.minecolonies.coremod.MineColonies;
import com.minecolonies.coremod.colony.Structures;
import com.minecolonies.coremod.util.*;
import com.minecolonies.coremod.configuration.Configurations;
import com.minecolonies.coremod.util.ClientStructureWrapper;
import com.minecolonies.coremod.util.Log;
import com.minecolonies.structures.helpers.Structure;
import io.netty.buffer.ByteBuf;
import net.minecraft.util.text.TextComponentString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.UUID;

/**
* Class handling the Server UUID Message.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import net.minecraftforge.fml.common.FMLCommonHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.io.File;


/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/minecolonies/coremod/proxy/IProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import com.minecolonies.coremod.colony.CitizenDataView;
import net.minecraft.util.math.BlockPos;
import java.io.*;

import javax.annotation.Nullable;
import java.io.File;

/**
* Basic proxy interface.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.minecolonies.coremod.lib.Constants;
import net.minecraftforge.fml.common.FMLCommonHandler;

import java.io.File;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.minecolonies.coremod.util;

import com.minecolonies.coremod.colony.Structures;
import com.minecolonies.structures.helpers.Structure;
import com.minecolonies.structures.helpers.Settings;
import com.minecolonies.structures.helpers.Structure;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.minecolonies.coremod.util;

import net.minecraft.block.Block;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/minecolonies/coremod/util/SoundUtils.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.minecolonies.coremod.util;

import com.minecolonies.coremod.entity.EntityCitizen;
import com.minecolonies.coremod.sounds.*;
import com.minecolonies.coremod.sounds.AbstractWorkerSounds;
import com.minecolonies.coremod.sounds.ModSoundEvents;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
Expand Down
Loading