Skip to content

Commit 780277b

Browse files
committed
upgraded dependencies, improved worldgen replacement
1 parent 842df54 commit 780277b

15 files changed

+69
-50
lines changed

gradle.properties

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx2G
33

44
# Fabric Properties
55
minecraft_version=1.17.1
6-
yarn_mappings=1.17.1+build.14
7-
loader_version=0.11.6
6+
yarn_mappings=1.17.1+build.64
7+
loader_version=0.12.5
88

99
# Mod Properties
10-
mod_version=2.2.0
10+
mod_version=2.3.0
1111
maven_group=de.dafuqs.lootcrates
1212
archives_base_name=ModularLootcrates
1313

1414
# Dependencies
15-
fabric_version=0.37.0+1.17
15+
fabric_version=0.42.1+1.17
1616
cloth_config_version=5.0.34
1717
modmenu_version=2.0.2

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
1818
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
1919
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
20-
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
21-
import net.minecraft.block.*;
20+
import net.minecraft.block.AbstractBlock;
21+
import net.minecraft.block.Block;
22+
import net.minecraft.block.BlockState;
23+
import net.minecraft.block.DispenserBlock;
2224
import net.minecraft.block.dispenser.BlockPlacementDispenserBehavior;
2325
import net.minecraft.block.entity.BlockEntity;
24-
import net.minecraft.block.entity.TrappedChestBlockEntity;
2526
import net.minecraft.client.render.RenderLayer;
2627
import net.minecraft.client.render.TexturedRenderLayers;
2728
import net.minecraft.client.util.SpriteIdentifier;

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
import net.fabricmc.api.ModInitializer;
1212
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
1313
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
14-
import net.minecraft.block.*;
14+
import net.minecraft.block.DispenserBlock;
15+
import net.minecraft.block.MapColor;
1516
import net.minecraft.block.dispenser.DispenserBehavior;
1617
import net.minecraft.entity.ItemEntity;
1718
import net.minecraft.item.ItemGroup;

src/main/java/de/dafuqs/lootcrates/blocks/LootCrateBlock.java

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import net.minecraft.block.BlockWithEntity;
1212
import net.minecraft.block.Blocks;
1313
import net.minecraft.block.entity.BlockEntity;
14-
import net.minecraft.block.entity.ChestBlockEntity;
1514
import net.minecraft.entity.ItemEntity;
1615
import net.minecraft.entity.LivingEntity;
1716
import net.minecraft.entity.ai.pathing.NavigationType;

src/main/java/de/dafuqs/lootcrates/blocks/LootCrateBlockEntity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void checkLootInteraction(@Nullable PlayerEntity player) {
167167
if (player != null && this.lootTableId != null && this.world.getServer() != null && shouldGenerateNewLoot(player, false)) {
168168
LootTable lootTable = this.world.getServer().getLootManager().getTable(this.lootTableId);
169169
if (player instanceof ServerPlayerEntity) {
170-
Criteria.PLAYER_GENERATES_CONTAINER_LOOT.test((ServerPlayerEntity)player, this.lootTableId);
170+
Criteria.PLAYER_GENERATES_CONTAINER_LOOT.trigger((ServerPlayerEntity)player, this.lootTableId);
171171
}
172172
LootContext.Builder builder = (new LootContext.Builder((ServerWorld)this.world)).parameter(LootContextParameters.ORIGIN, Vec3d.ofCenter(this.pos)).random(this.lootTableSeed);
173173
builder.luck(player.getLuck()).parameter(LootContextParameters.THIS_ENTITY, player);

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import de.dafuqs.lootcrates.blocks.LootCrateBlock;
55
import de.dafuqs.lootcrates.blocks.LootCrateBlockEntity;
66
import de.dafuqs.lootcrates.enums.BlockBreakAction;
7-
import net.minecraft.block.*;
8-
import net.minecraft.block.entity.*;
7+
import net.minecraft.block.Block;
8+
import net.minecraft.block.BlockRenderType;
9+
import net.minecraft.block.BlockState;
10+
import net.minecraft.block.entity.BlockEntity;
911
import net.minecraft.block.piston.PistonBehavior;
1012
import net.minecraft.entity.mob.PiglinBrain;
1113
import net.minecraft.entity.player.PlayerEntity;

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

+8-14
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,41 @@
88
import de.dafuqs.lootcrates.blocks.LootCrateBlockEntity;
99
import de.dafuqs.lootcrates.blocks.LootCratesBlockEntityType;
1010
import net.minecraft.block.BarrelBlock;
11-
import net.minecraft.block.Block;
1211
import net.minecraft.block.BlockState;
13-
import net.minecraft.block.entity.BarrelBlockEntity;
1412
import net.minecraft.block.entity.BlockEntityType;
15-
import net.minecraft.block.entity.ChestLidAnimator;
16-
import net.minecraft.block.entity.ChestStateManager;
17-
import net.minecraft.client.block.ChestAnimationProgress;
13+
import net.minecraft.block.entity.ViewerCountManager;
1814
import net.minecraft.entity.player.PlayerEntity;
1915
import net.minecraft.entity.player.PlayerInventory;
2016
import net.minecraft.inventory.Inventory;
2117
import net.minecraft.item.ItemStack;
2218
import net.minecraft.screen.GenericContainerScreenHandler;
2319
import net.minecraft.screen.ScreenHandler;
2420
import net.minecraft.sound.SoundEvents;
25-
import net.minecraft.text.Text;
26-
import net.minecraft.text.TranslatableText;
2721
import net.minecraft.util.collection.DefaultedList;
2822
import net.minecraft.util.math.BlockPos;
2923
import net.minecraft.world.BlockView;
3024
import net.minecraft.world.World;
3125

3226
public class LootBarrelBlockEntity extends LootCrateBlockEntity {
3327

34-
private final ChestStateManager stateManager;
28+
private final ViewerCountManager stateManager;
3529

3630
public LootBarrelBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) {
3731
super(blockEntityType, blockPos, blockState);
3832

3933
this.inventory = DefaultedList.ofSize(27, ItemStack.EMPTY);
40-
this.stateManager = new ChestStateManager() {
41-
protected void onChestOpened(World world, BlockPos pos, BlockState state) {
34+
this.stateManager = new ViewerCountManager() {
35+
protected void onContainerOpen(World world, BlockPos pos, BlockState state) {
4236
playSound(world, pos, state, SoundEvents.BLOCK_BARREL_OPEN);
4337
setOpen(state, true);
4438
}
4539

46-
protected void onChestClosed(World world, BlockPos pos, BlockState state) {
40+
protected void onContainerClose(World world, BlockPos pos, BlockState state) {
4741
playSound(world, pos, state, SoundEvents.BLOCK_BARREL_CLOSE);
4842
setOpen(state, false);
4943
}
5044

51-
protected void onInteracted(World world, BlockPos pos, BlockState state, int oldViewerCount, int newViewerCount) {
45+
protected void onViewerCountUpdate(World world, BlockPos pos, BlockState state, int oldViewerCount, int newViewerCount) {
5246
onInvOpenOrClose(world, pos, state, oldViewerCount, newViewerCount);
5347
}
5448

@@ -94,14 +88,14 @@ protected ScreenHandler createScreenHandler(int syncId, PlayerInventory playerIn
9488
@Override
9589
public void onOpen(PlayerEntity player) {
9690
if (!this.removed && !player.isSpectator()) {
97-
this.stateManager.openChest(player, this.getWorld(), this.getPos(), this.getCachedState());
91+
this.stateManager.openContainer(player, this.getWorld(), this.getPos(), this.getCachedState());
9892
}
9993
}
10094

10195
@Override
10296
public void onClose(PlayerEntity player) {
10397
if (!this.removed && !player.isSpectator()) {
104-
this.stateManager.closeChest(player, this.getWorld(), this.getPos(), this.getCachedState());
98+
this.stateManager.closeContainer(player, this.getWorld(), this.getPos(), this.getCachedState());
10599
}
106100
}
107101

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

+8-11
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,38 @@
1111
import net.minecraft.block.BlockState;
1212
import net.minecraft.block.entity.BlockEntityType;
1313
import net.minecraft.block.entity.ChestLidAnimator;
14-
import net.minecraft.block.entity.ChestStateManager;
14+
import net.minecraft.block.entity.ViewerCountManager;
1515
import net.minecraft.client.block.ChestAnimationProgress;
1616
import net.minecraft.entity.player.PlayerEntity;
1717
import net.minecraft.entity.player.PlayerInventory;
1818
import net.minecraft.inventory.Inventory;
1919
import net.minecraft.item.ItemStack;
2020
import net.minecraft.screen.GenericContainerScreenHandler;
2121
import net.minecraft.screen.ScreenHandler;
22-
import net.minecraft.sound.SoundEvents;
23-
import net.minecraft.text.Text;
24-
import net.minecraft.text.TranslatableText;
2522
import net.minecraft.util.collection.DefaultedList;
2623
import net.minecraft.util.math.BlockPos;
2724
import net.minecraft.world.BlockView;
2825
import net.minecraft.world.World;
2926

3027
public class ChestLootCrateBlockEntity extends LootCrateBlockEntity implements ChestAnimationProgress {
3128

32-
private final ChestStateManager stateManager;
29+
private final ViewerCountManager stateManager;
3330
private final ChestLidAnimator lidAnimator;
3431

3532
public ChestLootCrateBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) {
3633
super(blockEntityType, blockPos, blockState);
3734

3835
this.inventory = DefaultedList.ofSize(27, ItemStack.EMPTY);
39-
this.stateManager = new ChestStateManager() {
40-
protected void onChestOpened(World world, BlockPos pos, BlockState state) {
36+
this.stateManager = new ViewerCountManager() {
37+
protected void onContainerOpen(World world, BlockPos pos, BlockState state) {
4138
playOpenSoundEffect();
4239
}
4340

44-
protected void onChestClosed(World world, BlockPos pos, BlockState state) {
41+
protected void onContainerClose(World world, BlockPos pos, BlockState state) {
4542
playCloseSoundEffect();
4643
}
4744

48-
protected void onInteracted(World world, BlockPos pos, BlockState state, int oldViewerCount, int newViewerCount) {
45+
protected void onViewerCountUpdate(World world, BlockPos pos, BlockState state, int oldViewerCount, int newViewerCount) {
4946
onInvOpenOrClose(world, pos, state, oldViewerCount, newViewerCount);
5047
}
5148

@@ -88,14 +85,14 @@ protected ScreenHandler createScreenHandler(int syncId, PlayerInventory playerIn
8885
@Override
8986
public void onOpen(PlayerEntity player) {
9087
if (!this.removed && !player.isSpectator()) {
91-
this.stateManager.openChest(player, this.getWorld(), this.getPos(), this.getCachedState());
88+
this.stateManager.openContainer(player, this.getWorld(), this.getPos(), this.getCachedState());
9289
}
9390
}
9491

9592
@Override
9693
public void onClose(PlayerEntity player) {
9794
if (!this.removed && !player.isSpectator()) {
98-
this.stateManager.closeChest(player, this.getWorld(), this.getPos(), this.getCachedState());
95+
this.stateManager.closeContainer(player, this.getWorld(), this.getPos(), this.getCachedState());
9996
}
10097
}
10198

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

-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
import net.minecraft.entity.player.PlayerEntity;
1616
import net.minecraft.item.ItemPlacementContext;
1717
import net.minecraft.state.StateManager;
18-
import net.minecraft.state.property.BooleanProperty;
1918
import net.minecraft.state.property.DirectionProperty;
20-
import net.minecraft.state.property.Properties;
2119
import net.minecraft.util.*;
2220
import net.minecraft.util.hit.BlockHitResult;
2321
import net.minecraft.util.math.BlockPos;

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

-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package de.dafuqs.lootcrates.blocks.shulker;
22

3-
import de.dafuqs.lootcrates.LootCrateAtlas;
43
import de.dafuqs.lootcrates.blocks.LootCrateBlockEntity;
54
import de.dafuqs.lootcrates.blocks.LootCratesBlockEntityType;
65
import net.minecraft.block.Block;
@@ -9,7 +8,6 @@
98
import net.minecraft.block.entity.BlockEntityType;
109
import net.minecraft.block.entity.ShulkerBoxBlockEntity;
1110
import net.minecraft.block.piston.PistonBehavior;
12-
import net.minecraft.client.util.SpriteIdentifier;
1311
import net.minecraft.entity.Entity;
1412
import net.minecraft.entity.MovementType;
1513
import net.minecraft.entity.mob.ShulkerEntity;
@@ -19,8 +17,6 @@
1917
import net.minecraft.item.ItemStack;
2018
import net.minecraft.screen.ScreenHandler;
2119
import net.minecraft.screen.ShulkerBoxScreenHandler;
22-
import net.minecraft.text.Text;
23-
import net.minecraft.text.TranslatableText;
2420
import net.minecraft.util.math.*;
2521
import net.minecraft.util.shape.VoxelShapes;
2622
import net.minecraft.world.BlockView;

src/main/java/de/dafuqs/lootcrates/compat/QuickShulkerCompat.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private void checkLootInteraction(ItemStack stack, ServerPlayerEntity player) {
146146
if (player != null && lootTableId != null && player.getServer() != null && shouldGenerateNewLoot(stack, player, false)) {
147147
LootTable lootTable = player.getServer().getLootManager().getTable(lootTableId);
148148

149-
Criteria.PLAYER_GENERATES_CONTAINER_LOOT.test( player, lootTableId);
149+
Criteria.PLAYER_GENERATES_CONTAINER_LOOT.trigger( player, lootTableId);
150150

151151
LootContext.Builder builder = (new LootContext.Builder((ServerWorld) player.world)).parameter(LootContextParameters.ORIGIN, Vec3d.ofCenter(player.getBlockPos())).random(lootTableSeed);
152152
builder.luck(player.getLuck()).parameter(LootContextParameters.THIS_ENTITY, player);

src/main/java/de/dafuqs/lootcrates/mixin/LootableContainerBlockEntityMixin.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
import net.minecraft.util.registry.RegistryKey;
1414
import net.minecraft.world.BlockView;
1515
import net.minecraft.world.ChunkRegion;
16+
import net.minecraft.world.HeightLimitView;
1617
import net.minecraft.world.World;
18+
import net.minecraft.world.chunk.ProtoChunk;
19+
import org.apache.logging.log4j.core.jmx.Server;
1720
import org.spongepowered.asm.mixin.Mixin;
1821
import org.spongepowered.asm.mixin.injection.At;
1922
import org.spongepowered.asm.mixin.injection.Inject;
@@ -27,13 +30,23 @@ public abstract class LootableContainerBlockEntityMixin {
2730
@Inject(method = "setLootTable(Lnet/minecraft/world/BlockView;Ljava/util/Random;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/Identifier;)V", at = @At("TAIL"))
2831
private static void noteChestForLootCrateConversion(BlockView world, Random random, BlockPos pos, Identifier id, CallbackInfo ci) {
2932
if(LootCrates.CONFIG.ReplaceVanillaWorldgenChests) {
30-
3133
RegistryKey<World> worldRegistryKey;
32-
if (world instanceof ChunkRegion chunkRegion) {
34+
if(world instanceof ProtoChunk protoChunk) {
35+
ProtoChunkAccessor protoChunkAccessor = ((ProtoChunkAccessor) protoChunk);
36+
HeightLimitView heightLimitView = protoChunkAccessor.getWorld();
37+
if(heightLimitView instanceof ChunkRegion chunkRegion) {
38+
worldRegistryKey = chunkRegion.toServerWorld().getRegistryKey();
39+
} else if(heightLimitView instanceof ServerWorld serverWorld) {
40+
worldRegistryKey = serverWorld.getRegistryKey();
41+
} else {
42+
return;
43+
}
44+
} else if (world instanceof ChunkRegion chunkRegion) {
3345
worldRegistryKey = chunkRegion.toServerWorld().getRegistryKey();
34-
} else {
35-
ServerWorld serverWorld = (ServerWorld) world;
46+
} else if(world instanceof ServerWorld serverWorld) {
3647
worldRegistryKey = serverWorld.getRegistryKey();
48+
} else {
49+
return;
3750
}
3851

3952
if (!LootCrates.CONFIG.ReplaceVanillaWorldgenChestsDimensionsBlacklist.contains(worldRegistryKey.getValue().toString())) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package de.dafuqs.lootcrates.mixin;
2+
3+
import net.minecraft.world.HeightLimitView;
4+
import net.minecraft.world.chunk.ProtoChunk;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.gen.Accessor;
7+
8+
@Mixin(ProtoChunk.class)
9+
public interface ProtoChunkAccessor {
10+
11+
@Accessor("world")
12+
HeightLimitView getWorld();
13+
14+
}

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
import net.minecraft.util.JsonHelper;
1818
import org.apache.logging.log4j.Level;
1919

20-
import java.io.*;
20+
import java.io.File;
21+
import java.io.FileReader;
22+
import java.io.FileWriter;
23+
import java.io.IOException;
2124
import java.util.*;
2225

2326
public class LootCratesWorldgenReplacer {

src/main/resources/lootcrates.mixins.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"mixins": [
77
"BlockEntityMixin",
88
"LootableContainerBlockEntityMixin",
9-
"LootTableAccessor"
9+
"LootTableAccessor",
10+
"ProtoChunkAccessor"
1011
],
1112
"client": [
1213
],

0 commit comments

Comments
 (0)