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
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
11 changes: 11 additions & 0 deletions src/main/java/com/minecolonies/coremod/colony/Colony.java
Original file line number Diff line number Diff line change
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
@@ -0,0 +1,65 @@
package com.minecolonies.coremod.util.constants;
Copy link
Member

Choose a reason for hiding this comment

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

wrong package


import com.minecolonies.blockout.Render;
import com.minecolonies.coremod.colony.ColonyManager;
import com.minecolonies.coremod.colony.ColonyView;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.entity.item.EntityEnderCrystal;
import net.minecraft.util.math.BlockPos;

import java.util.Set;

/**
* Used for some rendering purpose like waypoint rendering.
*/
public final class RenderUtils
{
/**
* Half point offset to get in the middle of a block.
*/
private static final double HALF_BLOCK_OFFSET = 0.5;

/**
* Offset where the waypoint rendering marks to.
*/
private static final int FIX_POINT_OFFSET = 10;

/**
* Private constructor to hide the explicit one.
*/
private RenderUtils()
{
/**
* Intentionally left empty.
*/
}

/**
* Render all waypoints.
* @param position the position of the build tool click.
* @param clientWorld the world.
* @param partialTicks the partial ticks
*/
public static void renderWayPoints(final BlockPos position, final WorldClient clientWorld, final float partialTicks)
{
final ColonyView colonyView = ColonyManager.getClosestColonyView(clientWorld, position);

if(colonyView == null)
{
return;
}

final Set<BlockPos> waypoints = colonyView.getWayPoints();
for (final BlockPos pos : waypoints)
{
final EntityEnderCrystal crystal = new EntityEnderCrystal(clientWorld);
crystal.setPosition(pos.getX() + HALF_BLOCK_OFFSET, pos.getY(), pos.getZ() + HALF_BLOCK_OFFSET);
crystal.setBeamTarget(pos.up(FIX_POINT_OFFSET));
crystal.setShowBottom(false);
crystal.innerRotation = 0;

Minecraft.getMinecraft().getRenderManager().renderEntityStatic(crystal, 0.0F, true);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.minecolonies.structures.event;

import com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructure;
import com.minecolonies.coremod.util.BlockUtils;
import com.minecolonies.coremod.util.constants.RenderUtils;
import com.minecolonies.structures.helpers.Settings;
import com.minecolonies.structures.helpers.Structure;
import net.minecraft.client.Minecraft;
Expand All @@ -9,6 +11,8 @@
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import java.util.Set;

/**
* EventHandler used to display the schematics on the client.
*/
Expand Down Expand Up @@ -58,6 +62,11 @@ public void onRenderWorldLast(final RenderWorldLastEvent event)
position = position.subtract(offset);
}
structure.renderStructure(position, Minecraft.getMinecraft().theWorld, Minecraft.getMinecraft().thePlayer, event.getPartialTicks());

if(Settings.instance.getStructureName().contains(AbstractEntityAIStructure.WAYPOINT_STRING))
{
RenderUtils.renderWayPoints(position, Minecraft.getMinecraft().theWorld, event.getPartialTicks());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.minecolonies.coremod.MineColonies;
import com.minecolonies.coremod.colony.ColonyManager;
import com.minecolonies.coremod.colony.ColonyView;
import com.minecolonies.coremod.colony.Structures;
import com.minecolonies.coremod.configuration.Configurations;
import com.minecolonies.coremod.lib.Constants;
Expand All @@ -12,8 +13,11 @@
import com.minecolonies.structures.fake.FakeWorld;
import com.minecolonies.structures.lib.ModelHolder;
import net.minecraft.block.Block;
import net.minecraft.block.BlockBeacon;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
Expand All @@ -24,6 +28,7 @@
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.item.EntityEnderCrystal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
Expand All @@ -48,6 +53,7 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.Set;
import java.util.zip.*;
import javax.xml.bind.DatatypeConverter;

Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/META-INF/minecolonies_at.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ public net.minecraft.client.renderer.ViewFrustum func_178161_a(Lnet/minecraft/ut

public net.minecraft.nbt.NBTTagCompound func_150298_a(Ljava/lang/String;Lnet/minecraft/nbt/NBTBase;Ljava/io/DataOutput;)V # writeEntry
public net.minecraft.world.gen.structure.template.Template field_186270_a # blocks
public net.minecraft.world.gen.structure.template.Template field_186271_b # entities
public net.minecraft.world.gen.structure.template.Template field_186271_b # entities

public net.minecraft.tileentity.TileEntityBeacon field_146015_k # isComplete of beacon
public net.minecraft.tileentity.TileEntityBeacon field_146012_l # Levels of beacon