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

Raider camp/Crop changes #10605

Merged
merged 1 commit into from
Jan 19, 2025
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
118 changes: 61 additions & 57 deletions src/main/java/com/minecolonies/api/loot/ModLootConditions.java
Original file line number Diff line number Diff line change
@@ -1,57 +1,61 @@
package com.minecolonies.api.loot;

import com.minecolonies.api.util.constant.Constants;
import net.minecraft.advancements.critereon.EnchantmentPredicate;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType;
import net.minecraft.world.level.storage.loot.predicates.MatchTool;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.RegistryObject;

import static com.minecolonies.api.util.constant.Constants.MOD_ID;

/** Container class for registering custom loot conditions */
public final class ModLootConditions
{
public final static DeferredRegister<LootItemConditionType> DEFERRED_REGISTER = DeferredRegister.create(Registries.LOOT_CONDITION_TYPE, Constants.MOD_ID);

public static final ResourceLocation ENTITY_IN_BIOME_TAG_ID = new ResourceLocation(MOD_ID, "entity_in_biome_tag");
public static final ResourceLocation RESEARCH_UNLOCKED_ID = new ResourceLocation(MOD_ID, "research_unlocked");

public static final RegistryObject<LootItemConditionType> entityInBiomeTag;
public static final RegistryObject<LootItemConditionType> researchUnlocked;

// also some convenience definitions for existing conditions; some stolen from BlockLootSubProvider
public static final LootItemCondition.Builder HAS_SILK_TOUCH = MatchTool.toolMatches(ItemPredicate.Builder.item().hasEnchantment(new EnchantmentPredicate(Enchantments.SILK_TOUCH, MinMaxBounds.Ints.atLeast(1))));
public static final LootItemCondition.Builder HAS_SHEARS = MatchTool.toolMatches(ItemPredicate.Builder.item().of(Items.SHEARS));
public static final LootItemCondition.Builder HAS_SHEARS_OR_SILK_TOUCH = HAS_SHEARS.or(HAS_SILK_TOUCH);
public static final LootItemCondition.Builder HAS_NO_SHEARS_OR_SILK_TOUCH = HAS_SHEARS_OR_SILK_TOUCH.invert();
public static final LootItemCondition.Builder HAS_HOE = MatchTool.toolMatches(ItemPredicate.Builder.item().of(ItemTags.HOES));

public static void init()
{
// just for classloading
}

static
{
entityInBiomeTag = DEFERRED_REGISTER.register(ModLootConditions.ENTITY_IN_BIOME_TAG_ID.getPath(),
() -> new LootItemConditionType(new EntityInBiomeTag.Serializer()));

researchUnlocked = DEFERRED_REGISTER.register(ModLootConditions.RESEARCH_UNLOCKED_ID.getPath(),
() -> new LootItemConditionType(new ResearchUnlocked.Serializer()));
}


private ModLootConditions()
{
throw new IllegalStateException("Tried to initialize: ModLootConditions but this is a Utility class.");
}
}
package com.minecolonies.api.loot;

import com.minecolonies.api.util.constant.Constants;
import net.minecraft.advancements.critereon.EnchantmentPredicate;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType;
import net.minecraft.world.level.storage.loot.predicates.MatchTool;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.RegistryObject;

import static com.minecolonies.api.util.constant.Constants.MOD_ID;

/** Container class for registering custom loot conditions */
public final class ModLootConditions
{
public final static DeferredRegister<LootItemConditionType> DEFERRED_REGISTER = DeferredRegister.create(Registries.LOOT_CONDITION_TYPE, Constants.MOD_ID);

public static final ResourceLocation ENTITY_IN_BIOME_TAG_ID = new ResourceLocation(MOD_ID, "entity_in_biome_tag");
public static final ResourceLocation RESEARCH_UNLOCKED_ID = new ResourceLocation(MOD_ID, "research_unlocked");

public static final RegistryObject<LootItemConditionType> entityInBiomeTag;
public static final RegistryObject<LootItemConditionType> researchUnlocked;

// also some convenience definitions for existing conditions; some stolen from BlockLootSubProvider
public static final LootItemCondition.Builder HAS_SILK_TOUCH = MatchTool.toolMatches(ItemPredicate.Builder.item().hasEnchantment(new EnchantmentPredicate(Enchantments.SILK_TOUCH, MinMaxBounds.Ints.atLeast(1))));
public static final LootItemCondition.Builder HAS_SHEARS = MatchTool.toolMatches(ItemPredicate.Builder.item().of(Items.SHEARS));
public static final LootItemCondition.Builder HAS_SHEARS_OR_SILK_TOUCH = HAS_SHEARS.or(HAS_SILK_TOUCH);
public static final LootItemCondition.Builder HAS_NO_SHEARS_OR_SILK_TOUCH = HAS_SHEARS_OR_SILK_TOUCH.invert();
public static final LootItemCondition.Builder HAS_NETHERITE_HOE = MatchTool.toolMatches(ItemPredicate.Builder.item().of(Items.NETHERITE_HOE));
public static final LootItemCondition.Builder HAS_DIAMOND_HOE = MatchTool.toolMatches(ItemPredicate.Builder.item().of(Items.DIAMOND_HOE));
public static final LootItemCondition.Builder HAS_IRON_HOE = MatchTool.toolMatches(ItemPredicate.Builder.item().of(Items.IRON_HOE));
public static final LootItemCondition.Builder HAS_GOLDEN_HOE = MatchTool.toolMatches(ItemPredicate.Builder.item().of(Items.GOLDEN_HOE));
public static final LootItemCondition.Builder HAS_HOE = MatchTool.toolMatches(ItemPredicate.Builder.item().of(ItemTags.HOES));

public static void init()
{
// just for classloading
}

static
{
entityInBiomeTag = DEFERRED_REGISTER.register(ModLootConditions.ENTITY_IN_BIOME_TAG_ID.getPath(),
() -> new LootItemConditionType(new EntityInBiomeTag.Serializer()));

researchUnlocked = DEFERRED_REGISTER.register(ModLootConditions.RESEARCH_UNLOCKED_ID.getPath(),
() -> new LootItemConditionType(new ResearchUnlocked.Serializer()));
}


private ModLootConditions()
{
throw new IllegalStateException("Tried to initialize: ModLootConditions but this is a Utility class.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ public final class TranslationConstants
@NonNls
public static final String CROP_TOOLTIP = "com.minecolonies.core.item.crop.tooltip";
@NonNls
public static final String CROP_TOOLTIP_HOE = "com.minecolonies.core.item.crop.tooltip.hoe";
@NonNls
public static final String TIER_TOOLTIP = "com.minecolonies.core.item.food.tooltip.tier.";
@NonNls
public static final String BIOME_TOOLTIP = "com.minecolonies.core.item.crop.tooltip.biome";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,14 @@ protected void applySorting(final List<ItemStorage> displayedList)
displayedList.sort((o1, o2) -> {
int score = o1.getItem() instanceof IMinecoloniesFoodItem foodItem ? foodItem.getTier()* -100 : -o1.getItemStack().getFoodProperties(null).getNutrition();
int score2 = o2.getItem() instanceof IMinecoloniesFoodItem foodItem2 ? foodItem2.getTier()* -100 : -o2.getItemStack().getFoodProperties(null).getNutrition();
return score - score2 + o1.getItemStack().getDisplayName().getString().toLowerCase(Locale.US).compareTo(o2.getItemStack().getDisplayName().getString().toLowerCase(Locale.US));

final int scoreComparison = Integer.compare(score, score2);
if (scoreComparison != 0)
{
return scoreComparison;
}

return o1.getItemStack().getDisplayName().getString().toLowerCase(Locale.US).compareTo(o2.getItemStack().getDisplayName().getString().toLowerCase(Locale.US));
});
}

Expand Down
27 changes: 21 additions & 6 deletions src/main/java/com/minecolonies/core/event/EventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ public static void onLootTableLoad(@NotNull final LootTableLoadEvent event)
if (crops != null)
{
// grass blocks have a lot of crops (both MineColonies and vanilla) so the base drop chance is reduced
final float baseChance = event.getName().equals(Blocks.GRASS.getLootTable()) ? 0.001f : 0.01f;
// hoes have a boosted chance
final float hoeChance = 0.1f;
final float chance = event.getName().equals(Blocks.GRASS.getLootTable()) ? 0.001f : 0.01f;

for (final MinecoloniesCropBlock crop : crops)
{
Expand All @@ -197,10 +195,27 @@ public static void onLootTableLoad(@NotNull final LootTableLoadEvent event)

pool.add(AlternativesEntry.alternatives()
.otherwise(LootItem.lootTableItem(crop)
.when(ModLootConditions.HAS_HOE)
.when(LootItemRandomChanceCondition.randomChance(hoeChance)))
.when(ModLootConditions.HAS_NETHERITE_HOE)
.when(LootItemRandomChanceCondition.randomChance(chance * 4f)))
.otherwise(LootItem.lootTableItem(crop)
.when(LootItemRandomChanceCondition.randomChance(baseChance))));
.when(ModLootConditions.HAS_DIAMOND_HOE)
.when(LootItemRandomChanceCondition.randomChance(chance * 3.5f)))
.otherwise(LootItem.lootTableItem(crop)
.when(ModLootConditions.HAS_IRON_HOE)
.when(LootItemRandomChanceCondition.randomChance(chance * 3f)))
.otherwise(LootItem.lootTableItem(crop)
.when(ModLootConditions.HAS_GOLDEN_HOE)
.when(LootItemRandomChanceCondition.randomChance(chance * 2.5f)))
.otherwise(LootItem.lootTableItem(crop)
.when(ModLootConditions.HAS_HOE
.and(ModLootConditions.HAS_NETHERITE_HOE.invert())
.and(ModLootConditions.HAS_DIAMOND_HOE.invert())
.and(ModLootConditions.HAS_IRON_HOE.invert())
.and(ModLootConditions.HAS_GOLDEN_HOE.invert()))
.when(LootItemRandomChanceCondition.randomChance(chance * 2f)))
.otherwise(LootItem.lootTableItem(crop)
.when(ModLootConditions.HAS_HOE.invert())
.when(LootItemRandomChanceCondition.randomChance(chance))));

event.getTable().addPool(pool.build());
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/minecolonies/core/items/ItemCrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.minecolonies.api.util.MessageUtils;
import com.minecolonies.api.util.constant.TranslationConstants;
import com.minecolonies.core.blocks.MinecoloniesCropBlock;
import net.minecraft.ChatFormatting;
import net.minecraft.core.Holder;
import net.minecraft.network.chat.Component;
import net.minecraft.tags.TagKey;
Expand Down Expand Up @@ -64,11 +65,12 @@ protected boolean canPlace(BlockPlaceContext ctx, @NotNull BlockState state)
@Override
public void appendHoverText(@NotNull final ItemStack stack, @Nullable final Level worldIn, @NotNull final List<Component> tooltip, @NotNull final TooltipFlag flagIn)
{
tooltip.add(Component.translatable(TranslationConstants.CROP_TOOLTIP));
tooltip.add(Component.translatable(TranslationConstants.CROP_TOOLTIP).withStyle(ChatFormatting.GRAY));
if (preferredBiome != null)
{
tooltip.add(Component.translatable(TranslationConstants.BIOME_TOOLTIP + "." + preferredBiome.location().getPath()));
}
tooltip.add(Component.translatable(TranslationConstants.CROP_TOOLTIP_HOE).withStyle(ChatFormatting.DARK_AQUA).withStyle(ChatFormatting.ITALIC));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2644,8 +2644,9 @@
"entity.minecolonies.drownedchiefpirate": "Drowned Pirate Chief",
"death.attack.entity.minecolonies.drownedchiefpirate": "%s was put to a watery grave by a drowned Pirate Chief",
"com.minecolonies.core.exit_interactions": "Exit Interactions",
"com.minecolonies.core.crop.cantplant": "You do not possess the necessary knowledge to plant this crop. You should ask a Farmer to plant this for you!",
"com.minecolonies.core.crop.cantplant": "You do not possess the necessary knowledge to plant this crop. You should ask a Colony's Farmer to plant this for you!",
"com.minecolonies.core.item.crop.tooltip": "Ask a Farmer to plant this for you",
"com.minecolonies.core.item.crop.tooltip.hoe": "Easier to find with a quality hoe",
"com.minecolonies.core.item.crop.tooltip.biome.coldbiomes": "Only suitable for Cold Biomes",
"com.minecolonies.core.item.crop.tooltip.biome.temperatebiomes": "Only suitable for Temperate Biomes",
"com.minecolonies.core.item.crop.tooltip.biome.humidbiomes": "Only suitable for Hot and Humid Biomes",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"type": "minecraft:jigsaw",
"biomes": "#minecolonies:has_structure/amazon_camp",
"adapt_noise": false,
"adapt_noise": true,
"terrain_adaptation": "beard_box",
"start_pool": "minecolonies:amazon_camp",
"spawn_overrides": {},
"size": 7,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"type": "minecraft:jigsaw",
"biomes": "#minecolonies:has_structure/barbarian_camp",
"adapt_noise": false,
"adapt_noise": true,
"terrain_adaptation": "beard_box",
"start_pool": "minecolonies:barbarian_camp",
"spawn_overrides": {},
"size": 1,
"step": "surface_structures",

"start_height": {
"absolute": 0
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"type": "minecraft:jigsaw",
"biomes": "#minecolonies:has_structure/desert_camp",
"adapt_noise": false,
"adapt_noise": true,
"terrain_adaptation": "beard_box",
"start_pool": "minecolonies:desert_camp",
"spawn_overrides": {},
"size": 1,
Expand All @@ -10,7 +11,6 @@
"start_height": {
"absolute": 0
},
"terrain_adaptation": "beard_box",
"project_start_to_heightmap": "WORLD_SURFACE_WG",
"max_distance_from_center": 16,
"use_expansion_hack": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
],
"placement": {
"salt": 1225566777,
"spacing": 55,
"separation": 25,
"spacing": 95,
"separation": 45,
"type": "minecraft:random_spread"
}
}
Loading