Skip to content

Commit 0e61a36

Browse files
committed
option for item drops
1 parent c1741cc commit 0e61a36

File tree

8 files changed

+44
-55
lines changed

8 files changed

+44
-55
lines changed

example_datapacks/default_config.json5

+5-18
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,9 @@
1212
// other values: "require_key" (player keeps the key) and "consume_key" (key will be destroyed)
1313
"lock": "none",
1414
// proportional weight for this entry to others in this list
15-
"weight": 3
16-
},
17-
{
18-
"crate_rarity": "uncommon",
19-
"once_per_player": true,
20-
"replenish_time_ticks": 1,
21-
"lock": "none",
22-
"weight": 2
23-
},
24-
{
25-
"crate_rarity": "rare",
26-
"once_per_player": true,
27-
"replenish_time_ticks": 1,
28-
"lock": "none",
15+
// can be omitted and assumed 1
2916
"weight": 1
30-
}
17+
},
3118
]
3219
},
3320
{
@@ -42,9 +29,9 @@
4229
},
4330
{
4431
"crate_rarity": "uncommon",
45-
// when specifying a loot_table the original chests loot table
46-
// will be overridden. Otherwise it will keep the original loot table
47-
// like in the entry before. Great for making multiple rarity entries for each loot table
32+
// When specifying a loot_table the original chests loot table will be overridden.
33+
// Otherwise it will keep the original loot table like in the entry before.
34+
// Great for making multiple rarity entries for each loot table
4835
"loot_table": "minecraft:example_loot_table_uncommon",
4936
"once_per_player": true,
5037
"replenish_time_ticks": 1,

src/main/java/de/dafuqs/lootcrates/LootCrateDefinition.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
88
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
99
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
10-
import net.minecraft.block.Blocks;
1110
import net.minecraft.block.MapColor;
1211
import net.minecraft.block.Material;
1312
import net.minecraft.client.util.SpriteIdentifier;
@@ -99,6 +98,9 @@ public FabricBlockSettings getChestBlockSettings() {
9998
} else {
10099
blockSettings = blockSettings.strength(LootCrates.CONFIG.ChestCrateHardness);
101100
}
101+
if(!LootCrates.CONFIG.ChestCratesDropAsItems) {
102+
blockSettings = blockSettings.dropsNothing();
103+
}
102104

103105
if(hasTransparency) {
104106
blockSettings = blockSettings.nonOpaque();
@@ -115,6 +117,9 @@ public FabricBlockSettings getShulkerBlockSettings() {
115117
} else {
116118
blockSettings = blockSettings.strength(LootCrates.CONFIG.ShulkerCrateHardness);
117119
}
120+
if(!LootCrates.CONFIG.ShulkerCratesDropAsItems) {
121+
blockSettings = blockSettings.dropsNothing();
122+
}
118123

119124
// shulker blocks are always opaque
120125
return blockSettings;
@@ -128,6 +133,9 @@ public FabricBlockSettings getLootBarrelBlockSettings() {
128133
} else {
129134
blockSettings = blockSettings.strength(LootCrates.CONFIG.LootBarrelHardness);
130135
}
136+
if(!LootCrates.CONFIG.LootBarrelsDropAsItems) {
137+
blockSettings = blockSettings.dropsNothing();
138+
}
131139

132140
if(hasTransparency) {
133141
blockSettings = blockSettings.nonOpaque();

src/main/java/de/dafuqs/lootcrates/blocks/barrel/LootBarrelBlock.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import de.dafuqs.lootcrates.LootCrates;
44
import de.dafuqs.lootcrates.blocks.LootCrateBlock;
55
import de.dafuqs.lootcrates.blocks.LootCrateBlockEntity;
6-
import de.dafuqs.lootcrates.blocks.LootCratesBlockEntityType;
76
import de.dafuqs.lootcrates.enums.BlockBreakAction;
87
import net.minecraft.block.*;
98
import net.minecraft.block.entity.*;
@@ -13,21 +12,17 @@
1312
import net.minecraft.item.ItemPlacementContext;
1413
import net.minecraft.screen.NamedScreenHandlerFactory;
1514
import net.minecraft.server.world.ServerWorld;
16-
import net.minecraft.stat.Stats;
1715
import net.minecraft.state.StateManager;
1816
import net.minecraft.state.property.BooleanProperty;
1917
import net.minecraft.state.property.DirectionProperty;
2018
import net.minecraft.state.property.Properties;
21-
import net.minecraft.state.property.Property;
2219
import net.minecraft.util.ActionResult;
2320
import net.minecraft.util.BlockMirror;
2421
import net.minecraft.util.BlockRotation;
2522
import net.minecraft.util.Hand;
2623
import net.minecraft.util.hit.BlockHitResult;
2724
import net.minecraft.util.math.BlockPos;
2825
import net.minecraft.util.math.Direction;
29-
import net.minecraft.util.shape.VoxelShape;
30-
import net.minecraft.world.BlockView;
3126
import net.minecraft.world.World;
3227
import org.jetbrains.annotations.Nullable;
3328

@@ -76,7 +71,11 @@ protected BlockBreakAction getBlockBreakAction() {
7671
if(LootCrates.CONFIG.LootBarrelsKeepTheirInventory) {
7772
return BlockBreakAction.KEEP_INVENTORY;
7873
} else {
79-
return BlockBreakAction.DROP_AND_SCATTER_INVENTORY;
74+
if(LootCrates.CONFIG.LootBarrelsDropAsItems) {
75+
return BlockBreakAction.DROP_AND_SCATTER_INVENTORY;
76+
} else {
77+
return BlockBreakAction.DESTROY_AND_SCATTER_INVENTORY;
78+
}
8079
}
8180
}
8281

src/main/java/de/dafuqs/lootcrates/blocks/chest/ChestLootCrateBlock.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ protected BlockBreakAction getBlockBreakAction() {
7777
if(LootCrates.CONFIG.ChestCratesKeepTheirInventory) {
7878
return BlockBreakAction.KEEP_INVENTORY;
7979
} else {
80-
return BlockBreakAction.DROP_AND_SCATTER_INVENTORY;
80+
if(LootCrates.CONFIG.ChestCratesDropAsItems) {
81+
return BlockBreakAction.DROP_AND_SCATTER_INVENTORY;
82+
} else {
83+
return BlockBreakAction.DESTROY_AND_SCATTER_INVENTORY;
84+
}
8185
}
8286
}
8387

src/main/java/de/dafuqs/lootcrates/blocks/shulker/ShulkerLootCrateBlock.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ protected BlockBreakAction getBlockBreakAction() {
5959
if(LootCrates.CONFIG.ShulkerCratesKeepTheirInventory) {
6060
return BlockBreakAction.KEEP_INVENTORY;
6161
} else {
62-
return BlockBreakAction.DROP_AND_SCATTER_INVENTORY;
62+
if(LootCrates.CONFIG.ShulkerCratesDropAsItems) {
63+
return BlockBreakAction.DROP_AND_SCATTER_INVENTORY;
64+
} else {
65+
return BlockBreakAction.DESTROY_AND_SCATTER_INVENTORY;
66+
}
6367
}
6468
}
6569

src/main/java/de/dafuqs/lootcrates/config/LootCratesConfig.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ public class LootCratesConfig implements ConfigData {
2323
@ConfigEntry.Category("general")
2424
public float ShulkerCrateHardness = 3.0F;
2525

26+
@Comment(value = """
27+
If crates that are mined by players should drop as items
28+
Otherwise they will be destroyed and do not drop.""")
29+
@ConfigEntry.Category("general")
30+
public boolean ChestCratesDropAsItems = false;
31+
@ConfigEntry.Category("general")
32+
public boolean LootBarrelsDropAsItems = false;
33+
@ConfigEntry.Category("general")
34+
public boolean ShulkerCratesDropAsItems = true;
35+
2636
@Comment(value = """
2737
Whether chest and shulker loot crates should keep their inventory when broken.
2838
Otherwise they will drop their contents just like broken chests""")
@@ -37,7 +47,7 @@ public class LootCratesConfig implements ConfigData {
3747
@ConfigEntry.Category("worldgen")
3848
@Comment(value = """
3949
If all chests that generate during worldgen should be replaced by loot crates.
40-
This includes vanilla and modded structures.See the granular configuration in LootCratesWorldgenSettings.json5
50+
This includes vanilla and modded structures. See the granular configuration in LootCratesWorldgenSettings.json5
4151
This is especially useful if you want new players to find treasure in structures that were
4252
raided by players before, or if players should have an incentive to visit those structures again.
4353
Setting restocking to <= 0 results them functioning like vanilla chests.

src/main/java/de/dafuqs/lootcrates/worldgen/LootCratesWorldgenReplacer.java

+1-27
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,9 @@ public static void initialize() {
4444
myWriter.write("""
4545
[
4646
{
47-
// the default for all loot tables not specified otherwise
4847
"loot_table": "",
4948
"entries": [
5049
{
51-
// the crate generates loot once for each player opening it
52-
"once_per_player": true,
53-
// the crate can generate loot 1 tick after it was last opened
54-
"replenish_time_ticks": 1,
55-
// the crate is not locked, no key necessary
56-
// other values: "require_key" (player keeps the key) and "consume_key" (key will be destroyed)
57-
"lock": "none",
58-
// proportional weight for this entry to others in this list
59-
"weight": 3
60-
},
61-
{
62-
"crate_rarity": "uncommon",
63-
"once_per_player": true,
64-
"replenish_time_ticks": 1,
65-
"lock": "none",
66-
"weight": 2
67-
},
68-
{
69-
"crate_rarity": "rare",
7050
"once_per_player": true,
7151
"replenish_time_ticks": 1,
7252
"lock": "none",
@@ -86,15 +66,10 @@ public static void initialize() {
8666
},
8767
{
8868
"crate_rarity": "uncommon",
89-
// when specifying a loot_table the original chests loot table
90-
// will be overridden. Otherwise it will keep the original loot table
91-
// like in the entry before. Great for making multiple rarity entries for each loot table
9269
"loot_table": "minecraft:example_loot_table_uncommon",
9370
"once_per_player": true,
9471
"replenish_time_ticks": 1,
9572
"lock": "consume_key",
96-
// since the sum of all weights in this list is 3+2+1=6, this entry will be picked
97-
// 2 out of 6 times. Making it a 1/3 chance
9873
"weight": 2
9974
},
10075
{
@@ -244,11 +219,10 @@ public static void tick(MinecraftServer server) {
244219
}
245220
}
246221
} catch (Exception e) {
247-
LootCrates.LOGGER.error("[LootCrates] Error while replacing a container with loot table '" + replacementPosition.lootTable + "' in the world '" + replacementPosition.worldKey + "' at '" + replacementPosition.blockPos + "' )");
222+
LootCrates.LOGGER.error("[LootCrates] Error while replacing a container with loot table '" + replacementPosition.lootTable + "' in the world '" + replacementPosition.worldKey + "' at '" + replacementPosition.blockPos + "' ) + " + e.getLocalizedMessage());
248223
}
249224
}
250225
}
251226
}
252227

253-
254228
}

src/main/resources/assets/lootcrates/lang/en_us.json

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"text.autoconfig.LootCrates.option.ChestCrateHardness": "Chest Crate hardness",
77
"text.autoconfig.LootCrates.option.LootBarrelHardness": "Loot Barrel hardness",
88
"text.autoconfig.LootCrates.option.ShulkerCrateHardness": "Shulker Crate hardness",
9+
"text.autoconfig.LootCrates.option.ChestCratesDropAsItems": "Chest Crates drop when mined",
10+
"text.autoconfig.LootCrates.option.ShulkerCratesDropAsItems": "Shulker Crates drop when mined",
11+
"text.autoconfig.LootCrates.option.LootBarrelsDropAsItems": "Loot Barrels drop when mined",
912
"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",
1013
"text.autoconfig.LootCrates.option.ChestCratesKeepTheirInventory": "Chest Crates retain their inventory when broken",
1114
"text.autoconfig.LootCrates.option.ShulkerCratesKeepTheirInventory": "Shulker Crates retain their inventory when broken",

0 commit comments

Comments
 (0)