Skip to content

Commit

Permalink
option for item drops
Browse files Browse the repository at this point in the history
DaFuqs committed Sep 20, 2021
1 parent c1741cc commit 0e61a36
Showing 8 changed files with 44 additions and 55 deletions.
23 changes: 5 additions & 18 deletions example_datapacks/default_config.json5
Original file line number Diff line number Diff line change
@@ -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,
10 changes: 9 additions & 1 deletion src/main/java/de/dafuqs/lootcrates/LootCrateDefinition.java
Original file line number Diff line number Diff line change
@@ -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();
Original file line number Diff line number Diff line change
@@ -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,21 +12,17 @@
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;
import net.minecraft.util.Hand;
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;
}
}
}

Original file line number Diff line number Diff line change
@@ -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;
}
}
}

Original file line number Diff line number Diff line change
@@ -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;
}
}
}

12 changes: 11 additions & 1 deletion src/main/java/de/dafuqs/lootcrates/config/LootCratesConfig.java
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
}


}
3 changes: 3 additions & 0 deletions src/main/resources/assets/lootcrates/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -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",

0 comments on commit 0e61a36

Please sign in to comment.