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

Fix/rs #2630

Merged
merged 10 commits into from Jul 16, 2018
Expand Up @@ -55,7 +55,7 @@ public static Burnable deserialize(final IFactoryController controller, final NB
@Override
public boolean matches(@NotNull final ItemStack stack)
{
return TileEntityFurnace.isItemFuel(stack) && stack.getCount() >= getCount();
return TileEntityFurnace.isItemFuel(stack);
}

@Override
Expand Down
Expand Up @@ -56,8 +56,10 @@ public static Food deserialize(final IFactoryController controller, final NBTTag
@Override
public boolean matches(@NotNull final ItemStack stack)
{
return stack.getItem() instanceof ItemFood && stack.getCount() >= getCount();
} @Override
return stack.getItem() instanceof ItemFood;
}

@Override
public void setResult(@NotNull final ItemStack result)
{
this.result = result;
Expand Down
Expand Up @@ -130,7 +130,7 @@ public boolean matches(@NotNull final ItemStack stack)
{
if (matchOreDic)
{
return OreDictionary.itemMatches(getStack(), stack, matchMeta) && getCount() <= stack.getCount();
return OreDictionary.itemMatches(getStack(), stack, matchMeta);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please revert this Change. This contraticts the other behaviour of Stack.

}

return ItemStackUtils.compareItemStacksIgnoreStackSize(getStack(), stack, matchMeta, matchNBT);
Expand Down
33 changes: 27 additions & 6 deletions src/main/java/com/minecolonies/coremod/colony/CitizenData.java
Expand Up @@ -1022,25 +1022,41 @@ public double getSaturation()
return this.saturation;
}

/**
* Getter for the inventory.
* @return the direct reference to the citizen inventory.
*/
public InventoryCitizen getInventory()
{
return inventory;
}

/**
* Create a blocking request.
* @param requested the request to create.
* @param <R> the Type
* @return the token of the request.
*/
public <R extends IRequestable> IToken createRequest(@NotNull final R requested)
{
return getWorkBuilding().createRequest(this, requested);
return getWorkBuilding().createRequest(this, requested, false);
}

/**
* Create an async request.
* @param requested the request to create.
* @param <R> the Type
* @return the token of the request.
*/
public <R extends IRequestable> IToken createRequestAsync(@NotNull final R requested)
{
final IToken requestedToken = getWorkBuilding().createRequest(this, requested);

job.getAsyncRequests().add(requestedToken);

return requestedToken;
return getWorkBuilding().createRequest(this, requested, true);
}

/**
* Called on request canceled.
* @param token the token to be canceled.
*/
public void onRequestCancelled(@NotNull final IToken token)
{
if (isRequestAsync(token))
Expand All @@ -1049,6 +1065,11 @@ public void onRequestCancelled(@NotNull final IToken token)
}
}

/**
* Check if a request is async.
* @param token the token to check.
* @return true if it is.
*/
public boolean isRequestAsync(@NotNull final IToken token)
{
return job.getAsyncRequests().contains(token);
Expand Down
Expand Up @@ -18,7 +18,6 @@
import com.minecolonies.api.crafting.ItemStorage;
import com.minecolonies.api.util.*;
import com.minecolonies.api.util.constant.TypeConstants;
import com.minecolonies.coremod.blocks.*;
import com.minecolonies.coremod.colony.*;
import com.minecolonies.coremod.colony.buildings.registry.BuildingRegistry;
import com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester;
Expand Down Expand Up @@ -109,7 +108,7 @@ public void readFromNBT(@NotNull final NBTTagCompound compound)
*/
public void onWakeUp()
{
/**
/*
* Buildings override this if required.
*/
}
Expand Down Expand Up @@ -512,10 +511,21 @@ private Map<IToken<?>, Integer> getCitizensByRequest()
return getDataStore().getCitizensByRequest();
}

public <R extends IRequestable> IToken<?> createRequest(@NotNull final CitizenData citizenData, @NotNull final R requested)
/**
* Create a request for a citizen.
* @param citizenData the data of the citizen.
* @param requested the request to create.
* @param async if async or not.
* @param <R> the type of the request.
* @return the Token of the request.
*/
public <R extends IRequestable> IToken<?> createRequest(@NotNull final CitizenData citizenData, @NotNull final R requested, final boolean async)
{
final IToken requestToken = colony.getRequestManager().createRequest(requester, requested);

if (async)
{
citizenData.getJob().getAsyncRequests().add(requestToken);
}
addRequestToMaps(citizenData.getId(), requestToken, TypeToken.of(requested.getClass()));

colony.getRequestManager().assignRequest(requestToken);
Expand Down
Expand Up @@ -209,6 +209,14 @@ private static boolean isInDirection(final EnumFacing directionX, final EnumFaci
@Override
public List<AbstractEntityBarbarian> getHorde()
{
for (final AbstractEntityBarbarian entity : new ArrayList<>(horde))
{
if (entity.isDead)
{
horde.remove(entity);
}
}

return new ArrayList(horde);
}
}
Expand Up @@ -456,6 +456,7 @@ private void updateIfRequired()
@Override
public void update()
{
this.getRetryingRequestResolver().updateManager(this);
this.getRetryingRequestResolver().update();
}

Expand Down
Expand Up @@ -182,8 +182,7 @@ public ITextComponent getShortDisplayString()
public static class FoodRequest extends AbstractRequest<Food>
{

private static ImmutableList<ItemStack>
foodExamples;
private static ImmutableList<ItemStack> foodExamples;

FoodRequest(@NotNull final IRequester requester, @NotNull final IToken token, @NotNull final Food requested)
{
Expand Down
Expand Up @@ -58,6 +58,11 @@ public boolean canResolveForBuilding(
tileEntities.addAll(building.getAdditionalCountainers().stream().map(manager.getColony().getWorld()::getTileEntity).collect(Collectors.toSet()));
tileEntities.removeIf(Objects::isNull);

if (building.getCitizenForRequest(request.getToken()).isPresent() && building.getCitizenForRequest(request.getToken()).get().isRequestAsync(request.getToken()))
{
return false;
}

return tileEntities.stream()
.map(tileEntity -> InventoryUtils.filterProvider(tileEntity, itemStack -> request.getRequest().matches(itemStack)))
.anyMatch(itemStacks -> !itemStacks.isEmpty());
Expand Down
Expand Up @@ -105,8 +105,7 @@ public List<IToken<?>> attemptResolve(@NotNull final IRequestManager manager, @N
}

@Override
public void resolve(
@NotNull final IRequestManager manager, @NotNull final IRequest<? extends IRetryable> request) throws RuntimeException
public void resolve(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends IRetryable> request) throws RuntimeException
{
delays.put(request.getToken(), getMaximalDelayBetweenRetriesInTicks());
assignedRequests.put(request.getToken(), assignedRequests.containsKey(request.getToken()) ? assignedRequests.get(request.getToken()) + 1 : 1);
Expand All @@ -123,8 +122,7 @@ public IRequest getFollowupRequestForCompletion(@NotNull final IRequestManager m

@Nullable
@Override
public IRequest<?> onRequestCancelled(
@NotNull final IRequestManager manager, @NotNull final IRequest<? extends IRetryable> request)
public IRequest<?> onRequestCancelled(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends IRetryable> request)
{
if (assignedRequests.containsKey(request.getToken()))
{
Expand All @@ -137,8 +135,7 @@ public IRequest<?> onRequestCancelled(
}

@Override
public void onRequestBeingOverruled(
@NotNull final IRequestManager manager, @NotNull final IRequest<? extends IRetryable> request)
public void onRequestBeingOverruled(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends IRetryable> request)
{
onRequestCancelled(manager, request);
}
Expand Down
Expand Up @@ -62,7 +62,8 @@ public boolean canResolve(@NotNull final IRequestManager manager, final IRequest
try
{
return wareHouses.stream().anyMatch(wareHouse -> wareHouse.hasMatchinItemStackInWarehouse(itemStack -> requestToCheck.getRequest().matches(itemStack)));
} catch (Exception e)
}
catch (Exception e)
{
Log.getLogger().error(e);
}
Expand Down
11 changes: 3 additions & 8 deletions src/main/java/com/minecolonies/coremod/entity/EntityCitizen.java
Expand Up @@ -387,19 +387,14 @@ public void onDeath(@NotNull final DamageSource damageSource)
{
if (damageSource.getTrueSource() instanceof EntityPlayer)
{
boolean isBarbarianClose = true;
boolean isBarbarianClose = false;
for(final AbstractEntityBarbarian barbarian : this.getCitizenColonyHandler().getColony().getBarbManager().getHorde())
{
final EntityCitizen citizen = new EntityCitizen(this.getEntityWorld());
if(MathUtils.twoDimDistance(barbarian.getPosition(), citizen.getPosition()) < BARB_DISTANCE_FOR_FREE_DEATH)
if(MathUtils.twoDimDistance(barbarian.getPosition(), this.getPosition()) < BARB_DISTANCE_FOR_FREE_DEATH)
{
isBarbarianClose = true;
break;
}
else
{
isBarbarianClose = false;
}
}
for (final Player player : PermissionUtils.getPlayersWithAtLeastRank(citizenColonyHandler.getColony(), Rank.OFFICER))
{
Expand Down Expand Up @@ -814,7 +809,7 @@ public DesiredActivity getDesiredActivity()
return DesiredActivity.WORK;
}

if (BarbarianUtils.getClosestBarbarianToEntity(this, AVOID_BARBARIAN_RANGE) != null && !(citizenJobHandler.getColonyJob() instanceof AbstractJobGuard))
if (getCitizenColonyHandler().getColony() != null && (getCitizenColonyHandler().getColony().getBarbManager().getHorde().size() > 0) && !(citizenJobHandler.getColonyJob() instanceof AbstractJobGuard))
{
return DesiredActivity.SLEEP;
}
Expand Down
Expand Up @@ -60,46 +60,49 @@ public abstract class AbstractEntityAIBasic<J extends AbstractJob> extends Abstr
/**
* The maximum range to keep from the current building place.
*/
private static final int EXCEPTION_TIMEOUT = 100;
/**
* Buffer time in ticks he will accept a last attacker as valid.
*/
protected static final int ATTACK_TIME_BUFFER = 50;
private static final int EXCEPTION_TIMEOUT = 100;

/**
* The maximum range to keep from the current building place.
*/
private static final int MAX_ADDITIONAL_RANGE_TO_BUILD = 25;
private static final int MAX_ADDITIONAL_RANGE_TO_BUILD = 25;

/**
* Time in ticks to wait until the next check for items.
*/
private static final int DELAY_RECHECK = 10;
private static final int DELAY_RECHECK = 10;

/**
* The default range for any walking to blocks.
*/
private static final int DEFAULT_RANGE_FOR_DELAY = 4;
private static final int DEFAULT_RANGE_FOR_DELAY = 4;

/**
* The number of actions done before item dump.
*/
private static final int ACTIONS_UNTIL_DUMP = 32;
private static final int ACTIONS_UNTIL_DUMP = 32;

/**
* Hit a block every x ticks when mining.
*/
private static final int HIT_EVERY_X_TICKS = 5;
private static final int HIT_EVERY_X_TICKS = 5;

/**
* The block the ai is currently working at or wants to work.
*/
@Nullable
protected BlockPos currentWorkingLocation = null;
protected BlockPos currentWorkingLocation = null;

/**
* The block the ai is currently standing at or wants to stand.
*/
@Nullable
protected BlockPos currentStandingLocation = null;

/**
* The time in ticks until the next action is made.
*/
private int delay = 0;
private int delay = 0;

/**
* If we have waited one delay.
Expand Down
Expand Up @@ -121,7 +121,7 @@ public EntityAIWorkDeliveryman(@NotNull final JobDeliveryman deliveryman)
{
super(deliveryman);
super.registerTargets(
/**
/*
* Check if tasks should be executed.
*/
new AITarget(this::checkIfExecute, IDLE),
Expand Down Expand Up @@ -262,7 +262,7 @@ private BlockPos getRandomBuilding()

/**
* Calculates a random building and returns it.
* @return
* @return a random building.
*/
private AbstractBuilding returnRandomBuilding()
{
Expand Down
Expand Up @@ -58,16 +58,7 @@ public EntityAIGoHome(final EntityCitizen citizen)
@Override
public boolean shouldExecute()
{
boolean areBarbariansInColony;
if(citizen.getCitizenColonyHandler().getColony().getBarbManager().getHorde().size() > 0)
{
areBarbariansInColony = true;
}
else
{
areBarbariansInColony = false;
}
return !citizen.getCitizenColonyHandler().isAtHome() && (citizen.getDesiredActivity() == DesiredActivity.SLEEP || areBarbariansInColony);
return !citizen.getCitizenColonyHandler().isAtHome() && (citizen.getDesiredActivity() == DesiredActivity.SLEEP);
}


Expand Down
Expand Up @@ -94,7 +94,8 @@ private void checkIfStuck()

if (stuckTime >= MAX_STUCK_TIME)
{
if (citizen.getNavigator().getDestination().distanceSq(citizen.posX, citizen.posY, citizen.posZ) < MOVE_AWAY_RANGE)
if (citizen.getNavigator().getDestination().distanceSq(citizen.posX, citizen.posY, citizen.posZ) < MOVE_AWAY_RANGE
|| (Math.abs(citizen.getNavigator().getDestination().getY()-citizen.posY) > 2))
{
stuckTime = 0;
return;
Expand Down
Expand Up @@ -7,7 +7,7 @@

<label size="100% 11" pos="60 30"
label="$(com.minecolonies.coremod.gui.citizen.requests)" color="black"/>
<list id="requests" size="85% 80%" pos="20 50">
<list id="requests" size="80% 75%" pos="20 50">
<box id="requestx" size="100% 40" linewidth="2">
<!--Item icon -->
<itemicon id="requestStack" size="16 16" pos="1 3"/>
Expand Down