From 0e61a363e693f1b66491df2e019f7dbb55b7cba5 Mon Sep 17 00:00:00 2001 From: DaFuqs Date: Mon, 20 Sep 2021 22:13:40 +0200 Subject: [PATCH] option for item drops --- example_datapacks/default_config.json5 | 23 ++++----------- .../lootcrates/LootCrateDefinition.java | 10 ++++++- .../blocks/barrel/LootBarrelBlock.java | 11 ++++---- .../blocks/chest/ChestLootCrateBlock.java | 6 +++- .../blocks/shulker/ShulkerLootCrateBlock.java | 6 +++- .../lootcrates/config/LootCratesConfig.java | 12 +++++++- .../worldgen/LootCratesWorldgenReplacer.java | 28 +------------------ .../assets/lootcrates/lang/en_us.json | 3 ++ 8 files changed, 44 insertions(+), 55 deletions(-) diff --git a/example_datapacks/default_config.json5 b/example_datapacks/default_config.json5 index c0fd253..72dfafc 100644 --- a/example_datapacks/default_config.json5 +++ b/example_datapacks/default_config.json5 @@ -12,22 +12,9 @@ // other values: "require_key" (player keeps the key) and "consume_key" (key will be destroyed) "lock": "none", // proportional weight for this entry to others in this list - "weight": 3 - }, - { - "crate_rarity": "uncommon", - "once_per_player": true, - "replenish_time_ticks": 1, - "lock": "none", - "weight": 2 - }, - { - "crate_rarity": "rare", - "once_per_player": true, - "replenish_time_ticks": 1, - "lock": "none", + // can be omitted and assumed 1 "weight": 1 - } + }, ] }, { @@ -42,9 +29,9 @@ }, { "crate_rarity": "uncommon", - // when specifying a loot_table the original chests loot table - // will be overridden. Otherwise it will keep the original loot table - // like in the entry before. Great for making multiple rarity entries for each loot table + // When specifying a loot_table the original chests loot table will be overridden. + // Otherwise it will keep the original loot table like in the entry before. + // Great for making multiple rarity entries for each loot table "loot_table": "minecraft:example_loot_table_uncommon", "once_per_player": true, "replenish_time_ticks": 1, diff --git a/src/main/java/de/dafuqs/lootcrates/LootCrateDefinition.java b/src/main/java/de/dafuqs/lootcrates/LootCrateDefinition.java index c38dfd5..a56fa93 100644 --- a/src/main/java/de/dafuqs/lootcrates/LootCrateDefinition.java +++ b/src/main/java/de/dafuqs/lootcrates/LootCrateDefinition.java @@ -7,7 +7,6 @@ import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.block.Blocks; import net.minecraft.block.MapColor; import net.minecraft.block.Material; import net.minecraft.client.util.SpriteIdentifier; @@ -99,6 +98,9 @@ public FabricBlockSettings getChestBlockSettings() { } else { blockSettings = blockSettings.strength(LootCrates.CONFIG.ChestCrateHardness); } + if(!LootCrates.CONFIG.ChestCratesDropAsItems) { + blockSettings = blockSettings.dropsNothing(); + } if(hasTransparency) { blockSettings = blockSettings.nonOpaque(); @@ -115,6 +117,9 @@ public FabricBlockSettings getShulkerBlockSettings() { } else { blockSettings = blockSettings.strength(LootCrates.CONFIG.ShulkerCrateHardness); } + if(!LootCrates.CONFIG.ShulkerCratesDropAsItems) { + blockSettings = blockSettings.dropsNothing(); + } // shulker blocks are always opaque return blockSettings; @@ -128,6 +133,9 @@ public FabricBlockSettings getLootBarrelBlockSettings() { } else { blockSettings = blockSettings.strength(LootCrates.CONFIG.LootBarrelHardness); } + if(!LootCrates.CONFIG.LootBarrelsDropAsItems) { + blockSettings = blockSettings.dropsNothing(); + } if(hasTransparency) { blockSettings = blockSettings.nonOpaque(); diff --git a/src/main/java/de/dafuqs/lootcrates/blocks/barrel/LootBarrelBlock.java b/src/main/java/de/dafuqs/lootcrates/blocks/barrel/LootBarrelBlock.java index c6c3c4b..47c0296 100644 --- a/src/main/java/de/dafuqs/lootcrates/blocks/barrel/LootBarrelBlock.java +++ b/src/main/java/de/dafuqs/lootcrates/blocks/barrel/LootBarrelBlock.java @@ -3,7 +3,6 @@ import de.dafuqs.lootcrates.LootCrates; import de.dafuqs.lootcrates.blocks.LootCrateBlock; import de.dafuqs.lootcrates.blocks.LootCrateBlockEntity; -import de.dafuqs.lootcrates.blocks.LootCratesBlockEntityType; import de.dafuqs.lootcrates.enums.BlockBreakAction; import net.minecraft.block.*; import net.minecraft.block.entity.*; @@ -13,12 +12,10 @@ import net.minecraft.item.ItemPlacementContext; import net.minecraft.screen.NamedScreenHandlerFactory; import net.minecraft.server.world.ServerWorld; -import net.minecraft.stat.Stats; import net.minecraft.state.StateManager; import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.DirectionProperty; import net.minecraft.state.property.Properties; -import net.minecraft.state.property.Property; import net.minecraft.util.ActionResult; import net.minecraft.util.BlockMirror; import net.minecraft.util.BlockRotation; @@ -26,8 +23,6 @@ import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.world.BlockView; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; @@ -76,7 +71,11 @@ protected BlockBreakAction getBlockBreakAction() { if(LootCrates.CONFIG.LootBarrelsKeepTheirInventory) { return BlockBreakAction.KEEP_INVENTORY; } else { - return BlockBreakAction.DROP_AND_SCATTER_INVENTORY; + if(LootCrates.CONFIG.LootBarrelsDropAsItems) { + return BlockBreakAction.DROP_AND_SCATTER_INVENTORY; + } else { + return BlockBreakAction.DESTROY_AND_SCATTER_INVENTORY; + } } } diff --git a/src/main/java/de/dafuqs/lootcrates/blocks/chest/ChestLootCrateBlock.java b/src/main/java/de/dafuqs/lootcrates/blocks/chest/ChestLootCrateBlock.java index 3a2602d..2f0c0bf 100644 --- a/src/main/java/de/dafuqs/lootcrates/blocks/chest/ChestLootCrateBlock.java +++ b/src/main/java/de/dafuqs/lootcrates/blocks/chest/ChestLootCrateBlock.java @@ -77,7 +77,11 @@ protected BlockBreakAction getBlockBreakAction() { if(LootCrates.CONFIG.ChestCratesKeepTheirInventory) { return BlockBreakAction.KEEP_INVENTORY; } else { - return BlockBreakAction.DROP_AND_SCATTER_INVENTORY; + if(LootCrates.CONFIG.ChestCratesDropAsItems) { + return BlockBreakAction.DROP_AND_SCATTER_INVENTORY; + } else { + return BlockBreakAction.DESTROY_AND_SCATTER_INVENTORY; + } } } diff --git a/src/main/java/de/dafuqs/lootcrates/blocks/shulker/ShulkerLootCrateBlock.java b/src/main/java/de/dafuqs/lootcrates/blocks/shulker/ShulkerLootCrateBlock.java index b15d1b0..f112a23 100644 --- a/src/main/java/de/dafuqs/lootcrates/blocks/shulker/ShulkerLootCrateBlock.java +++ b/src/main/java/de/dafuqs/lootcrates/blocks/shulker/ShulkerLootCrateBlock.java @@ -59,7 +59,11 @@ protected BlockBreakAction getBlockBreakAction() { if(LootCrates.CONFIG.ShulkerCratesKeepTheirInventory) { return BlockBreakAction.KEEP_INVENTORY; } else { - return BlockBreakAction.DROP_AND_SCATTER_INVENTORY; + if(LootCrates.CONFIG.ShulkerCratesDropAsItems) { + return BlockBreakAction.DROP_AND_SCATTER_INVENTORY; + } else { + return BlockBreakAction.DESTROY_AND_SCATTER_INVENTORY; + } } } diff --git a/src/main/java/de/dafuqs/lootcrates/config/LootCratesConfig.java b/src/main/java/de/dafuqs/lootcrates/config/LootCratesConfig.java index 8e5b5ff..476566f 100644 --- a/src/main/java/de/dafuqs/lootcrates/config/LootCratesConfig.java +++ b/src/main/java/de/dafuqs/lootcrates/config/LootCratesConfig.java @@ -23,6 +23,16 @@ public class LootCratesConfig implements ConfigData { @ConfigEntry.Category("general") public float ShulkerCrateHardness = 3.0F; + @Comment(value = """ + If crates that are mined by players should drop as items + Otherwise they will be destroyed and do not drop.""") + @ConfigEntry.Category("general") + public boolean ChestCratesDropAsItems = false; + @ConfigEntry.Category("general") + public boolean LootBarrelsDropAsItems = false; + @ConfigEntry.Category("general") + public boolean ShulkerCratesDropAsItems = true; + @Comment(value = """ Whether chest and shulker loot crates should keep their inventory when broken. Otherwise they will drop their contents just like broken chests""") @@ -37,7 +47,7 @@ public class LootCratesConfig implements ConfigData { @ConfigEntry.Category("worldgen") @Comment(value = """ If all chests that generate during worldgen should be replaced by loot crates. - This includes vanilla and modded structures.See the granular configuration in LootCratesWorldgenSettings.json5 + This includes vanilla and modded structures. See the granular configuration in LootCratesWorldgenSettings.json5 This is especially useful if you want new players to find treasure in structures that were raided by players before, or if players should have an incentive to visit those structures again. Setting restocking to <= 0 results them functioning like vanilla chests. diff --git a/src/main/java/de/dafuqs/lootcrates/worldgen/LootCratesWorldgenReplacer.java b/src/main/java/de/dafuqs/lootcrates/worldgen/LootCratesWorldgenReplacer.java index 64ab3df..909940a 100644 --- a/src/main/java/de/dafuqs/lootcrates/worldgen/LootCratesWorldgenReplacer.java +++ b/src/main/java/de/dafuqs/lootcrates/worldgen/LootCratesWorldgenReplacer.java @@ -44,29 +44,9 @@ public static void initialize() { myWriter.write(""" [ { - // the default for all loot tables not specified otherwise "loot_table": "", "entries": [ { - // the crate generates loot once for each player opening it - "once_per_player": true, - // the crate can generate loot 1 tick after it was last opened - "replenish_time_ticks": 1, - // the crate is not locked, no key necessary - // other values: "require_key" (player keeps the key) and "consume_key" (key will be destroyed) - "lock": "none", - // proportional weight for this entry to others in this list - "weight": 3 - }, - { - "crate_rarity": "uncommon", - "once_per_player": true, - "replenish_time_ticks": 1, - "lock": "none", - "weight": 2 - }, - { - "crate_rarity": "rare", "once_per_player": true, "replenish_time_ticks": 1, "lock": "none", @@ -86,15 +66,10 @@ public static void initialize() { }, { "crate_rarity": "uncommon", - // when specifying a loot_table the original chests loot table - // will be overridden. Otherwise it will keep the original loot table - // like in the entry before. Great for making multiple rarity entries for each loot table "loot_table": "minecraft:example_loot_table_uncommon", "once_per_player": true, "replenish_time_ticks": 1, "lock": "consume_key", - // since the sum of all weights in this list is 3+2+1=6, this entry will be picked - // 2 out of 6 times. Making it a 1/3 chance "weight": 2 }, { @@ -244,11 +219,10 @@ public static void tick(MinecraftServer server) { } } } catch (Exception e) { - LootCrates.LOGGER.error("[LootCrates] Error while replacing a container with loot table '" + replacementPosition.lootTable + "' in the world '" + replacementPosition.worldKey + "' at '" + replacementPosition.blockPos + "' )"); + LootCrates.LOGGER.error("[LootCrates] Error while replacing a container with loot table '" + replacementPosition.lootTable + "' in the world '" + replacementPosition.worldKey + "' at '" + replacementPosition.blockPos + "' ) + " + e.getLocalizedMessage()); } } } } - } diff --git a/src/main/resources/assets/lootcrates/lang/en_us.json b/src/main/resources/assets/lootcrates/lang/en_us.json index c554066..c082ace 100644 --- a/src/main/resources/assets/lootcrates/lang/en_us.json +++ b/src/main/resources/assets/lootcrates/lang/en_us.json @@ -6,6 +6,9 @@ "text.autoconfig.LootCrates.option.ChestCrateHardness": "Chest Crate hardness", "text.autoconfig.LootCrates.option.LootBarrelHardness": "Loot Barrel hardness", "text.autoconfig.LootCrates.option.ShulkerCrateHardness": "Shulker Crate hardness", + "text.autoconfig.LootCrates.option.ChestCratesDropAsItems": "Chest Crates drop when mined", + "text.autoconfig.LootCrates.option.ShulkerCratesDropAsItems": "Shulker Crates drop when mined", + "text.autoconfig.LootCrates.option.LootBarrelsDropAsItems": "Loot Barrels drop when mined", "text.autoconfig.LootCrates.option.ChestCratesKeepTheirInventory.@PrefixText": "Whether chest and shulker loot crates should keep their inventory when broken. Otherwise they will drop their contents just like broken chests", "text.autoconfig.LootCrates.option.ChestCratesKeepTheirInventory": "Chest Crates retain their inventory when broken", "text.autoconfig.LootCrates.option.ShulkerCratesKeepTheirInventory": "Shulker Crates retain their inventory when broken",