Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/fix/build_pipeline' into fix/b…
Browse files Browse the repository at this point in the history
…uild_pipeline2
  • Loading branch information
Thodor12 committed Aug 23, 2024
2 parents a57b7d5 + 7176e53 commit 4ba2f8e
Show file tree
Hide file tree
Showing 19 changed files with 322 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public interface IDeliverable extends IRetryable
*/
IDeliverable copyWithCount(final int newCount);


/**
* Can this type of request be resolved by the building, or only by external resolvers.
* @return true if so.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public Stack(final ItemStack stack, final boolean matchDamage, final boolean mat
this.matchOreDic = matchOreDic;
this.result = result;
this.count = count;
this.minCount = minCount;
this.minCount = Math.min(minCount, count);
this.canBeResolvedByBuilding = canBeResolvedByBuilding;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public AbstractAdvancedPathNavigate getNavigation()
this.navigation = newNavigator;
newNavigator.setSwimSpeedFactor(getSwimSpeedFactor());
newNavigator.setSpeedModifier(0.5);
newNavigator.getPathingOptions().withStartSwimCost(2.5D).withSwimCost(1.0D).withCanEnterDoors(true).withDropCost(1D).withJumpCost(1D).withWalkUnderWater(true).withNonLadderClimbableCost(1D).setPassDanger(true);
newNavigator.getPathingOptions().withStartSwimCost(0.0D).withSwimCost(0.0D).withDivingCost(0.0D).withCanEnterDoors(true).withDropCost(0.0D).withJumpCost(0.0D).withWalkUnderWater(true).withNonLadderClimbableCost(0.0D).setPassDanger(true);
PathingStuckHandler stuckHandler = PathingStuckHandler.createStuckHandler()
.withTakeDamageOnStuck(0.4f)
.withBuildLeafBridges()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.minecolonies.api.tileentities;

import com.minecolonies.api.crafting.ItemStorage;
import com.minecolonies.api.inventory.InventoryCitizen;
import com.minecolonies.api.util.Tuple;
import com.minecolonies.core.tileentities.TileEntityColonyBuilding;
Expand Down Expand Up @@ -69,6 +70,14 @@ public AbstractTileEntityWareHouse(final BlockEntityType<? extends AbstractTileE
@NotNull
public abstract List<Tuple<ItemStack, BlockPos>> getMatchingItemStacksInWarehouse(@NotNull Predicate<ItemStack> itemStackSelectionPredicate);

/**
* Get the count up to some maxCount for some itemstorage in the warehouse.
* @param storage the storage.
* @param maxCount the count.
* @return the maxCount or less.
*/
public abstract int getCountInWarehouse(@NotNull final ItemStorage storage, int maxCount);

/**
* Dump the inventory of a citizen into the warehouse. Go through all items and search the right chest to dump it in.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Made with Blockbench 4.0.0-beta.0
// Exported for Minecraft version 1.17 with Mojang mappings
// Paste this class into your mod and generate all required imports
package com.minecolonies.core.client.model;

import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
import net.minecraft.world.entity.PathfinderMob;

public class MercenaryModel extends HumanoidModel<PathfinderMob>
{
public MercenaryModel(final ModelPart part)
{
super(part);
hat.visible = false;
}

public static LayerDefinition createMesh()
{
MeshDefinition meshdefinition = HumanoidModel.createMesh(CubeDeformation.NONE, 0.0F);
PartDefinition partdefinition = meshdefinition.getRoot();

PartDefinition bipedHead = partdefinition.addOrReplaceChild("head", CubeListBuilder.create().texOffs(0, 0).addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, new CubeDeformation(0.0F))
.texOffs(32, 0).addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, new CubeDeformation(0.5F)), PartPose.offset(0.0F, 0.0F, 0.0F));

PartDefinition shortBeard = bipedHead.addOrReplaceChild("shortBeard", CubeListBuilder.create().texOffs(24, 0).addBox(-3.5F, -24.0F, -4.0F, 7.0F, 3.0F, 1.0F, new CubeDeformation(0.0F))
.texOffs(24, 4).addBox(-3.5F, -23.0F, -4.0F, 7.0F, 3.0F, 1.0F, new CubeDeformation(0.5F)), PartPose.offset(0.0F, 24.0F, 0.0F));

PartDefinition bipedBody = partdefinition.addOrReplaceChild("body", CubeListBuilder.create().texOffs(16, 16).addBox(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F, new CubeDeformation(0.0F))
.texOffs(16, 32).addBox(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)), PartPose.offset(0.0F, 0.0F, 0.0F));

PartDefinition bipedRightArm = partdefinition.addOrReplaceChild("right_arm", CubeListBuilder.create().texOffs(40, 16).addBox(-3.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F))
.texOffs(40, 32).addBox(-3.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)), PartPose.offset(-5.0F, 2.0F, 0.0F));

PartDefinition bipedLeftArm = partdefinition.addOrReplaceChild("left_arm", CubeListBuilder.create().texOffs(32, 48).addBox(-1.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F))
.texOffs(48, 48).addBox(-1.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)), PartPose.offset(5.0F, 2.0F, 0.0F));

PartDefinition bipedRightLeg = partdefinition.addOrReplaceChild("right_leg", CubeListBuilder.create().texOffs(0, 16).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F))
.texOffs(0, 32).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)), PartPose.offset(-1.9F, 12.0F, 0.0F));

PartDefinition bipedLeftLeg = partdefinition.addOrReplaceChild("left_leg", CubeListBuilder.create().texOffs(16, 48).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.0F))
.texOffs(0, 48).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.25F)), PartPose.offset(1.9F, 12.0F, 0.0F));

return LayerDefinition.create(meshdefinition, 128, 64);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package com.minecolonies.core.client.render.mobs;

import com.minecolonies.api.util.constant.Constants;
import com.minecolonies.core.client.model.MercenaryModel;
import com.minecolonies.core.event.ClientRegistryHandler;
import net.minecraft.client.model.geom.ModelLayers;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer;
import net.minecraft.client.renderer.entity.layers.ItemInHandLayer;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.PathfinderMob;

/**
* Renderer for EntityMercenary.
*/
public class RenderMercenary extends MobRenderer<PathfinderMob, HumanoidModel<PathfinderMob>>
public class RenderMercenary extends MobRenderer<PathfinderMob, MercenaryModel>
{
/**
* Texture of the entity.
Expand All @@ -27,7 +29,7 @@ public class RenderMercenary extends MobRenderer<PathfinderMob, HumanoidModel<Pa
*/
public RenderMercenary(final EntityRendererProvider.Context context)
{
super(context, new HumanoidModel<>(context.bakeLayer(ModelLayers.PLAYER_INNER_ARMOR)), 0.5f);
super(context, new MercenaryModel(context.bakeLayer(ClientRegistryHandler.MERCENARY)), 0.5f);

this.addLayer(new ItemInHandLayer<>(this, context.getItemInHandRenderer()));
this.addLayer(new HumanoidArmorLayer<>(this, new HumanoidModel<>(context.bakeLayer(ModelLayers.PLAYER_INNER_ARMOR)), new HumanoidModel<>(context.bakeLayer(ModelLayers.PLAYER_OUTER_ARMOR)), context.getModelManager()));
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/minecolonies/core/colony/ColonyView.java
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,10 @@ public IMessage handleColonyViewMessage(@NotNull final FriendlyByteBuf buf, @Not

if (buf.readBoolean())
{
this.requestManager = new StandardRequestManager(this);
if (this.requestManager == null)
{
this.requestManager = new StandardRequestManager(this);
}
this.requestManager.deserialize(StandardFactoryController.getInstance(), buf);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,15 @@ private IToken<?> resolve(
//TODO: Change this false to simulation.
resolver.onRequestAssigned(manager, request, false);

for (final IToken<?> childRequestToken :
attemptResult)
for (final IToken<?> childRequestToken : attemptResult)
{
final IRequest<?> childRequest = manager.getRequestHandler().getRequest(childRequestToken);

childRequest.setParent(request.getId());
request.addChild(childRequest.getId());
}

for (final IToken<?> childRequestToken :
attemptResult)
for (final IToken<?> childRequestToken : attemptResult)
{
final IRequest<?> childRequest = manager.getRequestHandler().getRequest(childRequestToken);

Expand Down Expand Up @@ -338,8 +336,7 @@ public void onRequestResolved(final IToken<?> token)
}

//Assign the followup request if need be
if (followupRequests != null && !followupRequests.isEmpty() &&
followupRequests.stream().anyMatch(followupRequest -> !isAssigned(followupRequest.getId())))
if (followupRequests != null && !followupRequests.isEmpty())
{
followupRequests.stream()
.filter(followupRequest -> !isAssigned(followupRequest.getId()))
Expand Down Expand Up @@ -614,8 +611,6 @@ public IRequest<?> getRequest(final IToken<?> token)
@Override
public IRequest<?> getRequestOrNull(final IToken<?> token)
{
manager.log("Retrieving the request for: " + token);

return manager.getRequestIdentitiesDataStore().getIdentities().get(token);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,6 @@ public IRequestResolver<? extends IRequestable> getResolver(final IToken<?> toke
throw new IllegalArgumentException("The given token for a resolver is not known to this manager!");
}

manager.log("Retrieving resolver for: " + token);

return manager.getRequestResolverIdentitiesDataStore().getIdentities().get(token);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.minecolonies.core.colony.buildings.modules.BuildingModules;
import com.minecolonies.core.colony.buildings.modules.CourierAssignmentModule;
import com.minecolonies.core.colony.buildings.modules.WarehouseRequestQueueModule;
import com.minecolonies.core.colony.buildings.workerbuildings.BuildingWareHouse;
import com.minecolonies.core.colony.jobs.JobDeliveryman;
import com.minecolonies.core.colony.requestsystem.resolvers.core.AbstractRequestResolver;
import net.minecraft.network.chat.MutableComponent;
Expand Down Expand Up @@ -44,6 +45,12 @@ public boolean canResolveRequest(@NotNull final IRequestManager manager, final I
return false;
}

if (manager.getColony().getBuildingManager().getBuilding(requestToCheck.getRequester().getLocation().getInDimensionLocation()) instanceof IWareHouse
&& !requestToCheck.getRequester().getLocation().equals(getLocation()))
{
return false;
}

return hasCouriers(manager);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import com.minecolonies.api.colony.requestsystem.requestable.INonExhaustiveDeliverable;
import com.minecolonies.api.colony.requestsystem.requestable.Stack;
import com.minecolonies.api.colony.requestsystem.token.IToken;
import com.minecolonies.api.crafting.ItemStorage;
import com.minecolonies.core.colony.buildings.workerbuildings.BuildingWareHouse;
import com.minecolonies.core.colony.requestsystem.resolvers.core.AbstractWarehouseRequestResolver;
import com.minecolonies.core.tileentities.TileEntityWareHouse;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;

import java.util.List;
Expand All @@ -27,42 +29,41 @@ public WarehouseConcreteRequestResolver(
}

@Override
protected boolean internalCanResolve(final List<TileEntityWareHouse> wareHouses, final IRequest<? extends IDeliverable> requestToCheck)
protected boolean internalCanResolve(final Level level, final List<BuildingWareHouse> wareHouses, final IRequest<? extends IDeliverable> requestToCheck)
{
final IDeliverable deliverable = requestToCheck.getRequest();

if(deliverable instanceof IConcreteDeliverable)
if (deliverable instanceof IConcreteDeliverable)
{
boolean ignoreNBT = false;
boolean ignoreDamage = false;
if (deliverable instanceof Stack)
if (deliverable instanceof Stack stack)
{
if (!((Stack) requestToCheck.getRequest()).matchNBT())
{
ignoreNBT = true;
}
if (!((Stack) requestToCheck.getRequest()).matchDamage())
{
ignoreDamage = true;
}
ignoreNBT = !stack.matchNBT();
ignoreDamage = !stack.matchDamage();
}
for(final ItemStack possible : ((IConcreteDeliverable) deliverable).getRequestedItems())
int totalCount = 0;
for (final ItemStack possible : ((IConcreteDeliverable) deliverable).getRequestedItems())
{
for (final TileEntityWareHouse wareHouse : wareHouses)
for (final BuildingWareHouse wareHouse : wareHouses)
{
if (requestToCheck.getRequest() instanceof INonExhaustiveDeliverable)
if (wareHouse.getTileEntity() == null)
{
continue;
}

if (requestToCheck.getRequest() instanceof INonExhaustiveDeliverable neDeliverable)
{
if (wareHouse.hasMatchingItemStackInWarehouse(possible, requestToCheck.getRequest().getMinimumCount(), ignoreNBT, ignoreDamage, ((INonExhaustiveDeliverable) requestToCheck.getRequest()).getLeftOver()))
{
return true;
}
totalCount += Math.max(0, wareHouse.getTileEntity().getCountInWarehouse(new ItemStorage(possible, requestToCheck.getRequest().getMinimumCount(), ignoreDamage, ignoreNBT), requestToCheck.getRequest().getMinimumCount()) - neDeliverable.getLeftOver());
}
else
{
if (wareHouse.hasMatchingItemStackInWarehouse(possible, requestToCheck.getRequest().getMinimumCount(), ignoreNBT, ignoreDamage, 0))
{
return true;
}
totalCount += wareHouse.getTileEntity().getCountInWarehouse(new ItemStorage(possible, requestToCheck.getRequest().getMinimumCount(), ignoreDamage, ignoreNBT), requestToCheck.getRequest().getMinimumCount());
}

if (totalCount >= requestToCheck.getRequest().getMinimumCount())
{
return true;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
import com.minecolonies.api.colony.requestsystem.requestable.IConcreteDeliverable;
import com.minecolonies.api.colony.requestsystem.requestable.IDeliverable;
import com.minecolonies.api.colony.requestsystem.token.IToken;
import com.minecolonies.api.util.WorldUtil;
import com.minecolonies.core.colony.buildings.workerbuildings.BuildingWareHouse;
import com.minecolonies.core.colony.requestsystem.resolvers.core.AbstractWarehouseRequestResolver;
import com.minecolonies.core.tileentities.TileEntityWareHouse;
import com.minecolonies.core.tileentities.TileEntityRack;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import org.jetbrains.annotations.NotNull;

import java.util.List;
Expand All @@ -24,18 +29,30 @@ public WarehouseRequestResolver(
}

@Override
protected boolean internalCanResolve(final List<TileEntityWareHouse> wareHouses, final IRequest<? extends IDeliverable> requestToCheck)
protected boolean internalCanResolve(final Level level, final List<BuildingWareHouse> wareHouses, final IRequest<? extends IDeliverable> requestToCheck)
{
if(requestToCheck.getRequest() instanceof IConcreteDeliverable)
if (requestToCheck.getRequest() instanceof IConcreteDeliverable)
{
return false;
return false;
}

for (final TileEntityWareHouse wareHouse : wareHouses)
int totalCount = 0;
for (final BuildingWareHouse wareHouse : wareHouses)
{
if (wareHouse.hasMatchingItemStackInWarehouse(itemStack -> requestToCheck.getRequest().matches(itemStack), requestToCheck.getRequest().getMinimumCount()))
for (@NotNull final BlockPos pos : wareHouse.getContainers())
{
return true;
if (WorldUtil.isBlockLoaded(level, pos))
{
final BlockEntity entity = level.getBlockEntity(pos);
if (entity instanceof final TileEntityRack rack && !rack.isEmpty())
{
totalCount += rack.getItemCount(itemStack -> requestToCheck.getRequest().matches(itemStack));
if (totalCount >= requestToCheck.getRequest().getMinimumCount())
{
return true;
}
}
}
}
}
return false;
Expand Down
Loading

0 comments on commit 4ba2f8e

Please sign in to comment.