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

Fancy fixes #10475

Merged
merged 7 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"minecolonies:yogurt_with_berries",
"minecolonies:mutton_dinner",
"minecolonies:tortillas",
"minecolonies:apple_pie",
"minecolonies:spicy_eggplant"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"values": [
"minecraft:poisonous_potato",
"minecraft:chicken",
"minecraft:spider_eye",
"minecraft:rotten_flesh"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,10 @@ public interface ICitizenDiseaseHandler
* Sets a flag that the citizen is now at the hospital.
*/
void setSleepsAtHospital(final boolean isAtHospital);

/**
* Set a disease on the citizen.
* @param disease to set.
*/
void setDisease(String disease);
}
2 changes: 2 additions & 0 deletions src/main/java/com/minecolonies/api/items/ModTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public class ModTags
public static final TagKey<Item> breakable_ore = ItemTags.create(TagConstants.BREAKABLE_ORE);
public static final TagKey<Item> raw_ore = ItemTags.create(TagConstants.RAW_ORE);

public static final TagKey<Item> poisonous_food = ItemTags.create(TagConstants.POISONOUS_FOOD);

public static final TagKey<EntityType<?>> hostile = TagKey.create(Registries.ENTITY_TYPE, TagConstants.HOSTILE);
public static final TagKey<EntityType<?>> mobAttackBlacklist = TagKey.create(Registries.ENTITY_TYPE, TagConstants.MOB_ATTACK_BLACKLIST);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public final class TagConstants
public static final ResourceLocation TEMPERATE_BIOMES = new ResourceLocation(MOD_ID, "temperatebiomes");
public static final ResourceLocation HUMID_BIOMES = new ResourceLocation(MOD_ID, "humidbiomes");
public static final ResourceLocation DRY_BIOMES = new ResourceLocation(MOD_ID, "drybiomes");
public static final ResourceLocation POISONOUS_FOOD = new ResourceLocation(MOD_ID, "poisonousfood");

public static final String CRAFTING_BAKER = ModJobs.BAKER_ID.getPath();
public static final String CRAFTING_BLACKSMITH = ModJobs.BLACKSMITH_ID.getPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,8 @@ public final class TranslationConstants
@NonNls
public static final String MESSAGE_INTERACTION_COOKIE = "com.minecolonies.coremod.interaction.nocookie";
@NonNls
public static final String MESSAGE_INTERACTION_POISON = "com.minecolonies.coremod.interaction.poison";
@NonNls
public static final String MESSAGE_INTERACTION_VISITOR_FOOD = "com.minecolonies.coremod.interaction.visitor.food";
@NonNls
public static final String WARNING_UPGRADE_BARRACKS = "com.minecolonies.coremod.worker.needbarracks";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ public void setPlacedBy(final Level worldIn, final BlockPos pos, final BlockStat
worldIn.setBlock(pos, tempState, 2);
}

@Override
public VoxelShape getCollisionShape(final BlockState p_60572_, final BlockGetter p_60573_, final BlockPos p_60574_, final CollisionContext p_60575_)
{
return Shapes.empty();
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ private void startPatrolNext()
{
if (curguard.getEntity().isPresent())
{
if (curguard.getEntity().get().getCitizenJobHandler().getColonyJob() instanceof AbstractJobGuard guardEntity)
if (curguard.getJob() instanceof AbstractJobGuard guardEntity)
{
((AbstractEntityAIGuard<?, ?>) guardEntity.getWorkerAI()).setNextPatrolTarget(lastPatrolPoint);
((AbstractEntityAIGuard<?, ?>) guardEntity.getWorkerAI()).setNextPatrolTargetAndMove(lastPatrolPoint);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ public void alterItemsToBeKept(final TriConsumer<Predicate<ItemStack>, Integer,
for (final ItemStorage menuItem : menu)
{
consumer.accept(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, menuItem.getItemStack(), false, true), menuItem.getItemStack().getMaxStackSize() * getExpectedStock(), false);
if (canCook && MinecoloniesAPIProxy.getInstance().getFurnaceRecipes().getFirstSmeltingRecipeByResult(menuItem) instanceof RecipeStorage recipeStorage)
{
final ItemStack smeltStack = recipeStorage.getInput().get(0).getItemStack();
consumer.accept(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, smeltStack, false, true), smeltStack.getMaxStackSize() * getExpectedStock(), false);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public class BuildingCook extends AbstractBuilding
public BuildingCook(final IColony c, final BlockPos l)
{
super(c, l);
keepX.put(stack -> !ItemStackUtils.isEmpty(stack.getCraftingRemainingItem()) && !stack.getCraftingRemainingItem().getItem().equals(Items.BUCKET), new Tuple<>(STACKSIZE, false));
}

/**
Expand All @@ -90,6 +89,12 @@ public void onUpgradeComplete(final int newLevel)
initTags = false;
}

@Override
protected boolean keepFood()
{
return false;
}

/**
* Gets the next sitting position to use for eating, just keeps iterating the aviable positions, so we do not have to keep track of who is where.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ public BlockPos getRandomBuilding()

for (int i = 0; i < possibleGuards.size() && i <= 3; i++)
{
((AbstractEntityAIGuard<?, ?>) possibleGuards.get(i).getCitizenData().getJob().getWorkerAI()).setNextPatrolTarget(lastBuilding);
((AbstractEntityAIGuard<?, ?>) possibleGuards.get(i).getCitizenData().getJob().getWorkerAI()).setNextPatrolTargetAndMove(lastBuilding);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ public IAIState patrol()

if (currentPatrolPoint != null)
{
setNextPatrolTarget(currentPatrolPoint);
setNextPatrolTargetAndMove(currentPatrolPoint);
}
}
}
Expand Down Expand Up @@ -562,11 +562,11 @@ public IAIState patrolMine()
final MinerLevel level = buildingMiner.getFirstModuleOccurance(MinerLevelManagementModule.class).getCurrentLevel();
if (level == null)
{
setNextPatrolTarget(buildingMiner.getPosition());
setNextPatrolTargetAndMove(buildingMiner.getPosition());
}
else
{
setNextPatrolTarget(level.getRandomCompletedNode(buildingMiner));
setNextPatrolTargetAndMove(level.getRandomCompletedNode(buildingMiner));
}
}
else
Expand All @@ -587,14 +587,9 @@ public IAIState patrolMine()
*
* @param target the next patrol target.
*/
public void setNextPatrolTarget(final BlockPos target)
public void setNextPatrolTargetAndMove(final BlockPos target)
{
currentPatrolPoint = target;
if (getState() == CombatAIStates.NO_TARGET)
{
worker.isWorkerAtSiteWithMove(currentPatrolPoint, 2);
}

registerTarget(new AIOneTimeEventTarget(() ->
{
if (getState() == CombatAIStates.NO_TARGET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.minecolonies.api.inventory.InventoryCitizen;
import com.minecolonies.api.inventory.container.ContainerCitizenInventory;
import com.minecolonies.api.items.ModItems;
import com.minecolonies.api.items.ModTags;
import com.minecolonies.api.sounds.EventType;
import com.minecolonies.api.util.*;
import com.minecolonies.api.util.MessageUtils.MessagePriority;
Expand Down Expand Up @@ -74,6 +75,8 @@
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.DamageTypeTags;
import net.minecraft.tags.FluidTags;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.CombatRules;
Expand All @@ -83,7 +86,10 @@
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.animal.FlyingAnimal;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
Expand All @@ -92,8 +98,10 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.ShieldItem;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.Shapes;
Expand Down Expand Up @@ -131,6 +139,10 @@
@SuppressWarnings({"PMD.ExcessiveImports", "PMD.CouplingBetweenObjects", "PMD.ExcessiveClassLength"})
public class EntityCitizen extends AbstractEntityCitizen implements IThreatTableEntity
{
private static final UUID SLOW_FALLING_ID = UUID.fromString("A5B6CF2A-2F7C-31EF-9022-7C3E7D5E6ABA");
private static final AttributeModifier SLOW_FALLING = new AttributeModifier(SLOW_FALLING_ID, "Slow falling acceleration reduction", -0.07, AttributeModifier.Operation.ADDITION); // Add -0.07 to 0.08 so we get the vanilla default of 0.01


/**
* Cooldown for calling help, in ticks.
*/
Expand Down Expand Up @@ -486,6 +498,26 @@ private InteractionResult directPlayerInteraction(final Player player, final Int
return InteractionResult.CONSUME;
}

if (usedStack.is(ModTags.poisonous_food))
{
usedStack.shrink(1);
player.setItemInHand(hand, usedStack);

if (!level.isClientSide())
{
getCitizenDiseaseHandler().setDisease(IColonyManager.getInstance().getCompatibilityManager().getRandomDisease());
playSound(SoundEvents.VILLAGER_HURT, 1.0f, (float) SoundUtils.getRandomPitch(getRandom()));
getCitizenData().markDirty(20);

MessageUtils.format(MESSAGE_INTERACTION_POISON, this.getCitizenData().getName())
.withPriority(MessagePriority.DANGER)
.sendTo(player);
}

interactionCooldown = 20 * 60 * 5;
return InteractionResult.CONSUME;
}

if (getCitizenDiseaseHandler().isSick())
{
return null;
Expand Down Expand Up @@ -560,7 +592,7 @@ private InteractionResult directPlayerInteraction(final Player player, final Int
public boolean isInteractionItem(final ItemStack stack)
{
return ISFOOD.test(stack) || stack.getItem() == Items.BOOK || stack.getItem() == Items.GOLDEN_APPLE || stack.getItem() == Items.CACTUS
|| stack.getItem() == Items.GLOWSTONE_DUST;
|| stack.getItem() == Items.GLOWSTONE_DUST || stack.is(ModTags.poisonous_food);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public void tick()
}
}

public void setDisease(final String disease)
{
this.disease = disease;
}

/**
* Check if the citizen may become sick.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ protected void addTags(final HolderLookup.Provider p_256380_)
.add(Items.RAW_COPPER)
.add(Items.RAW_GOLD);

tag(ModTags.poisonous_food)
.add(Items.POISONOUS_POTATO)
.add(Items.CHICKEN)
.add(Items.SPIDER_EYE)
.add(Items.ROTTEN_FLESH);

final Item[] paperExtras = getDomumExtra(ExtraBlockType.BASE_PAPER, ExtraBlockType.LIGHT_PAPER);

tag(ModTags.crafterIngredient.get(TagConstants.CRAFTING_BAKER))
Expand Down Expand Up @@ -268,7 +274,6 @@ protected void addTags(final HolderLookup.Provider p_256380_)
.add(ModItems.yogurt_with_berries)
.add(ModItems.mutton_dinner)
.add(ModItems.tortillas)
.add(ModItems.apple_pie)
.add(ModItems.spicy_eggplant);

tag(ModTags.crafterProductExclusions.get(TagConstants.CRAFTING_COOK))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,7 @@
"com.minecolonies.coremod.interaction.notnow": "%s: I can't do that right now",
"com.minecolonies.coremod.interaction.ouch": "%s: Oh is that for me... Ouch!",
"com.minecolonies.coremod.interaction.visitor.food": "Tasty food? I guess I'll stay a bit longer here",
"com.minecolonies.coremod.interaction.poison": "Ugh! What was that? I'm not feeling very well now.",

"com.minecolonies.coremod.gui.townhall.happiness.homelessness": "Housing",
"com.minecolonies.coremod.gui.townhall.happiness.unemployment": "Unemployment",
Expand Down