Skip to content

Commit

Permalink
some small fixes (ldtteam#5590)
Browse files Browse the repository at this point in the history
Allow passing two fence gates by using the direction
Fix display of items in the overview (client side update)
Add a way for the workers to avoid having to path 100% to a chest to pick things up (sometimes mid upgrade this might not be possible)
  • Loading branch information
Raycoms authored Aug 16, 2020
1 parent 21c8764 commit 89330d1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ public void onDataPacket(final NetworkManager net, final SUpdateTileEntityPacket
{
final CompoundNBT compound = packet.getNbtCompound();
colonyId = compound.getInt(TAG_COLONY);
super.onDataPacket(net, packet);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ public void updateItemStorage()
if ((empty && !content.isEmpty()) || !empty && content.isEmpty())
{
updateBlockState();
markDirty();
}
markDirty();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private void updateResources()
final World world = building.getColony().getWorld();

TileEntityRack hut = (TileEntityRack) world.getTileEntity(building.getPosition());
Map<ItemStorage, Integer> hutStorage = ((TileEntityRack) hut).getAllContent();
Map<ItemStorage, Integer> hutStorage = hut.getAllContent();

for (final Map.Entry<ItemStorage, Integer> entry : hutStorage.entrySet())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public abstract class AbstractEntityAIBasic<J extends AbstractJob<?, J>, B exten
*/
protected static final int REQUEST_DELAY = TICKS_20 * 3;

/**
* Number of possible pickup attempts.
*/
private static final int PICKUP_ATTEMPTS = 10;

/**
* The block the ai is currently working at or wants to work.
*/
Expand Down Expand Up @@ -137,6 +142,11 @@ public abstract class AbstractEntityAIBasic<J extends AbstractJob<?, J>, B exten
*/
private final List<ItemStorage> alreadyKept = new ArrayList<>();

/**
* Counter to count pickup attempts.
*/
private int pickUpCounter = 0;

/**
* Sets up some important skeleton stuff for every ai.
*
Expand Down Expand Up @@ -223,7 +233,6 @@ private IAIState getNeededItem()
return getState();
}


if (needsCurrently == null)
{
return getStateAfterPickUp();
Expand All @@ -240,11 +249,13 @@ private IAIState getNeededItem()
walkTo = pos;
}

if (walkToBlock(walkTo))
if (walkToBlock(walkTo) && pickUpCounter++ < PICKUP_ATTEMPTS)
{
return getState();
}

pickUpCounter = 0;

tryTransferFromPosToWorkerIfNeeded(walkTo, needsCurrently);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.pathfinding.GroundPathNavigator;
import net.minecraft.pathfinding.Path;
import net.minecraft.pathfinding.PathPoint;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -25,6 +26,7 @@ public class EntityAIGateInteract extends Goal
* Number of blocks to check for the fence gate - height.
*/
private static final int HEIGHT_TO_CHECK = 2;

/**
* Number of blocks to check for the fence gate - length.
*/
Expand All @@ -33,32 +35,38 @@ public class EntityAIGateInteract extends Goal
/**
* The min distance the gate has to be from the citizen.
*/
private static final double MIN_DISTANCE = 2.25D;
private static final double MIN_DISTANCE = 2.25D;

/**
* Our citizen.
*/
protected MobEntity theEntity;
protected MobEntity theEntity;

/**
* The gate position.
*/
protected BlockPos gatePosition;
protected BlockPos gatePosition;

/**
* The gate block.
*/
@Nullable
protected FenceGateBlock gateBlock;
protected FenceGateBlock gateBlock;

/**
* Check if the interaction with the fenceGate stopped already.
*/
private boolean hasStoppedFenceInteraction;
private boolean hasStoppedFenceInteraction;

/**
* The entities x position.
*/
private double entityPositionX;
private double entityPositionX;

/**
* The entities z position.
*/
private double entityPositionZ;
private double entityPositionZ;

/**
* Constructor called to register the AI class with an entity.
Expand Down Expand Up @@ -108,7 +116,7 @@ private boolean checkPath()
private boolean checkFenceGate(@NotNull final Path path)
{
final int maxLengthToCheck = Math.min(path.getCurrentPathIndex() + LENGTH_TO_CHECK, path.getCurrentPathLength());
for (int i = 0; i < maxLengthToCheck; ++i)
for (int i = Math.max(0, path.getCurrentPathIndex() - 1); i < maxLengthToCheck; ++i)
{
final PathPoint pathpoint = path.getPathPointFromIndex(i);
for (int level = 0; level < HEIGHT_TO_CHECK; level++)
Expand Down Expand Up @@ -176,10 +184,10 @@ public void startExecuting()
@Override
public void tick()
{
final double entityDistX = this.gatePosition.getX() + HALF_BLOCK - this.theEntity.posX;
final double entityDistZ = this.gatePosition.getZ() + HALF_BLOCK - this.theEntity.posZ;
final double totalDist = this.entityPositionX * entityDistX + this.entityPositionZ * entityDistZ;
if (totalDist < 0.0D)
final Direction dir = this.theEntity.getHorizontalFacing();
final double entityDistX = Math.abs(this.gatePosition.getX() + HALF_BLOCK - this.theEntity.getPosX() + dir.getXOffset());
final double entityDistZ = Math.abs(this.gatePosition.getZ() + HALF_BLOCK - this.theEntity.getPosZ() + dir.getZOffset());
if ((entityDistX > HALF_BLOCK && entityDistX < 1.0 ) || (entityDistZ > HALF_BLOCK && entityDistZ < 1.0))
{
this.hasStoppedFenceInteraction = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public boolean shouldContinueExecuting()
@Override
public void startExecuting()
{
super.startExecuting();
this.closeDoorTemporisation = TIME_TO_CLOSE_DOOR;
toggleDoor(true);
}
Expand Down

0 comments on commit 89330d1

Please sign in to comment.