Skip to content

Commit

Permalink
upgraded dependencies, improved worldgen replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
DaFuqs committed Nov 18, 2021
1 parent 842df54 commit 780277b
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 50 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx2G

# Fabric Properties
minecraft_version=1.17.1
yarn_mappings=1.17.1+build.14
loader_version=0.11.6
yarn_mappings=1.17.1+build.64
loader_version=0.12.5

# Mod Properties
mod_version=2.2.0
mod_version=2.3.0
maven_group=de.dafuqs.lootcrates
archives_base_name=ModularLootcrates

# Dependencies
fabric_version=0.37.0+1.17
fabric_version=0.42.1+1.17
cloth_config_version=5.0.34
modmenu_version=2.0.2
7 changes: 4 additions & 3 deletions src/main/java/de/dafuqs/lootcrates/LootCrateAtlas.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.DispenserBlock;
import net.minecraft.block.dispenser.BlockPlacementDispenserBehavior;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.TrappedChestBlockEntity;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.TexturedRenderLayers;
import net.minecraft.client.util.SpriteIdentifier;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/de/dafuqs/lootcrates/LootCrates.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.block.*;
import net.minecraft.block.DispenserBlock;
import net.minecraft.block.MapColor;
import net.minecraft.block.dispenser.DispenserBehavior;
import net.minecraft.entity.ItemEntity;
import net.minecraft.item.ItemGroup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.minecraft.block.BlockWithEntity;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.pathing.NavigationType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void checkLootInteraction(@Nullable PlayerEntity player) {
if (player != null && this.lootTableId != null && this.world.getServer() != null && shouldGenerateNewLoot(player, false)) {
LootTable lootTable = this.world.getServer().getLootManager().getTable(this.lootTableId);
if (player instanceof ServerPlayerEntity) {
Criteria.PLAYER_GENERATES_CONTAINER_LOOT.test((ServerPlayerEntity)player, this.lootTableId);
Criteria.PLAYER_GENERATES_CONTAINER_LOOT.trigger((ServerPlayerEntity)player, this.lootTableId);
}
LootContext.Builder builder = (new LootContext.Builder((ServerWorld)this.world)).parameter(LootContextParameters.ORIGIN, Vec3d.ofCenter(this.pos)).random(this.lootTableSeed);
builder.luck(player.getLuck()).parameter(LootContextParameters.THIS_ENTITY, player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import de.dafuqs.lootcrates.blocks.LootCrateBlock;
import de.dafuqs.lootcrates.blocks.LootCrateBlockEntity;
import de.dafuqs.lootcrates.enums.BlockBreakAction;
import net.minecraft.block.*;
import net.minecraft.block.entity.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.entity.mob.PiglinBrain;
import net.minecraft.entity.player.PlayerEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,41 @@
import de.dafuqs.lootcrates.blocks.LootCrateBlockEntity;
import de.dafuqs.lootcrates.blocks.LootCratesBlockEntityType;
import net.minecraft.block.BarrelBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BarrelBlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.ChestLidAnimator;
import net.minecraft.block.entity.ChestStateManager;
import net.minecraft.client.block.ChestAnimationProgress;
import net.minecraft.block.entity.ViewerCountManager;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;

public class LootBarrelBlockEntity extends LootCrateBlockEntity {

private final ChestStateManager stateManager;
private final ViewerCountManager stateManager;

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

this.inventory = DefaultedList.ofSize(27, ItemStack.EMPTY);
this.stateManager = new ChestStateManager() {
protected void onChestOpened(World world, BlockPos pos, BlockState state) {
this.stateManager = new ViewerCountManager() {
protected void onContainerOpen(World world, BlockPos pos, BlockState state) {
playSound(world, pos, state, SoundEvents.BLOCK_BARREL_OPEN);
setOpen(state, true);
}

protected void onChestClosed(World world, BlockPos pos, BlockState state) {
protected void onContainerClose(World world, BlockPos pos, BlockState state) {
playSound(world, pos, state, SoundEvents.BLOCK_BARREL_CLOSE);
setOpen(state, false);
}

protected void onInteracted(World world, BlockPos pos, BlockState state, int oldViewerCount, int newViewerCount) {
protected void onViewerCountUpdate(World world, BlockPos pos, BlockState state, int oldViewerCount, int newViewerCount) {
onInvOpenOrClose(world, pos, state, oldViewerCount, newViewerCount);
}

Expand Down Expand Up @@ -94,14 +88,14 @@ protected ScreenHandler createScreenHandler(int syncId, PlayerInventory playerIn
@Override
public void onOpen(PlayerEntity player) {
if (!this.removed && !player.isSpectator()) {
this.stateManager.openChest(player, this.getWorld(), this.getPos(), this.getCachedState());
this.stateManager.openContainer(player, this.getWorld(), this.getPos(), this.getCachedState());
}
}

@Override
public void onClose(PlayerEntity player) {
if (!this.removed && !player.isSpectator()) {
this.stateManager.closeChest(player, this.getWorld(), this.getPos(), this.getCachedState());
this.stateManager.closeContainer(player, this.getWorld(), this.getPos(), this.getCachedState());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,38 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.ChestLidAnimator;
import net.minecraft.block.entity.ChestStateManager;
import net.minecraft.block.entity.ViewerCountManager;
import net.minecraft.client.block.ChestAnimationProgress;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;

public class ChestLootCrateBlockEntity extends LootCrateBlockEntity implements ChestAnimationProgress {

private final ChestStateManager stateManager;
private final ViewerCountManager stateManager;
private final ChestLidAnimator lidAnimator;

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

this.inventory = DefaultedList.ofSize(27, ItemStack.EMPTY);
this.stateManager = new ChestStateManager() {
protected void onChestOpened(World world, BlockPos pos, BlockState state) {
this.stateManager = new ViewerCountManager() {
protected void onContainerOpen(World world, BlockPos pos, BlockState state) {
playOpenSoundEffect();
}

protected void onChestClosed(World world, BlockPos pos, BlockState state) {
protected void onContainerClose(World world, BlockPos pos, BlockState state) {
playCloseSoundEffect();
}

protected void onInteracted(World world, BlockPos pos, BlockState state, int oldViewerCount, int newViewerCount) {
protected void onViewerCountUpdate(World world, BlockPos pos, BlockState state, int oldViewerCount, int newViewerCount) {
onInvOpenOrClose(world, pos, state, oldViewerCount, newViewerCount);
}

Expand Down Expand Up @@ -88,14 +85,14 @@ protected ScreenHandler createScreenHandler(int syncId, PlayerInventory playerIn
@Override
public void onOpen(PlayerEntity player) {
if (!this.removed && !player.isSpectator()) {
this.stateManager.openChest(player, this.getWorld(), this.getPos(), this.getCachedState());
this.stateManager.openContainer(player, this.getWorld(), this.getPos(), this.getCachedState());
}
}

@Override
public void onClose(PlayerEntity player) {
if (!this.removed && !player.isSpectator()) {
this.stateManager.closeChest(player, this.getWorld(), this.getPos(), this.getCachedState());
this.stateManager.closeContainer(player, this.getWorld(), this.getPos(), this.getCachedState());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
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.util.*;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.dafuqs.lootcrates.blocks.shulker;

import de.dafuqs.lootcrates.LootCrateAtlas;
import de.dafuqs.lootcrates.blocks.LootCrateBlockEntity;
import de.dafuqs.lootcrates.blocks.LootCratesBlockEntityType;
import net.minecraft.block.Block;
Expand All @@ -9,7 +8,6 @@
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.ShulkerBoxBlockEntity;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.entity.Entity;
import net.minecraft.entity.MovementType;
import net.minecraft.entity.mob.ShulkerEntity;
Expand All @@ -19,8 +17,6 @@
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ShulkerBoxScreenHandler;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.math.*;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void checkLootInteraction(ItemStack stack, ServerPlayerEntity player) {
if (player != null && lootTableId != null && player.getServer() != null && shouldGenerateNewLoot(stack, player, false)) {
LootTable lootTable = player.getServer().getLootManager().getTable(lootTableId);

Criteria.PLAYER_GENERATES_CONTAINER_LOOT.test( player, lootTableId);
Criteria.PLAYER_GENERATES_CONTAINER_LOOT.trigger( player, lootTableId);

LootContext.Builder builder = (new LootContext.Builder((ServerWorld) player.world)).parameter(LootContextParameters.ORIGIN, Vec3d.ofCenter(player.getBlockPos())).random(lootTableSeed);
builder.luck(player.getLuck()).parameter(LootContextParameters.THIS_ENTITY, player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.BlockView;
import net.minecraft.world.ChunkRegion;
import net.minecraft.world.HeightLimitView;
import net.minecraft.world.World;
import net.minecraft.world.chunk.ProtoChunk;
import org.apache.logging.log4j.core.jmx.Server;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -27,13 +30,23 @@ public abstract class LootableContainerBlockEntityMixin {
@Inject(method = "setLootTable(Lnet/minecraft/world/BlockView;Ljava/util/Random;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/Identifier;)V", at = @At("TAIL"))
private static void noteChestForLootCrateConversion(BlockView world, Random random, BlockPos pos, Identifier id, CallbackInfo ci) {
if(LootCrates.CONFIG.ReplaceVanillaWorldgenChests) {

RegistryKey<World> worldRegistryKey;
if (world instanceof ChunkRegion chunkRegion) {
if(world instanceof ProtoChunk protoChunk) {
ProtoChunkAccessor protoChunkAccessor = ((ProtoChunkAccessor) protoChunk);
HeightLimitView heightLimitView = protoChunkAccessor.getWorld();
if(heightLimitView instanceof ChunkRegion chunkRegion) {
worldRegistryKey = chunkRegion.toServerWorld().getRegistryKey();
} else if(heightLimitView instanceof ServerWorld serverWorld) {
worldRegistryKey = serverWorld.getRegistryKey();
} else {
return;
}
} else if (world instanceof ChunkRegion chunkRegion) {
worldRegistryKey = chunkRegion.toServerWorld().getRegistryKey();
} else {
ServerWorld serverWorld = (ServerWorld) world;
} else if(world instanceof ServerWorld serverWorld) {
worldRegistryKey = serverWorld.getRegistryKey();
} else {
return;
}

if (!LootCrates.CONFIG.ReplaceVanillaWorldgenChestsDimensionsBlacklist.contains(worldRegistryKey.getValue().toString())) {
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/de/dafuqs/lootcrates/mixin/ProtoChunkAccessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package de.dafuqs.lootcrates.mixin;

import net.minecraft.world.HeightLimitView;
import net.minecraft.world.chunk.ProtoChunk;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(ProtoChunk.class)
public interface ProtoChunkAccessor {

@Accessor("world")
HeightLimitView getWorld();

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
import net.minecraft.util.JsonHelper;
import org.apache.logging.log4j.Level;

import java.io.*;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;

public class LootCratesWorldgenReplacer {
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/lootcrates.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"mixins": [
"BlockEntityMixin",
"LootableContainerBlockEntityMixin",
"LootTableAccessor"
"LootTableAccessor",
"ProtoChunkAccessor"
],
"client": [
],
Expand Down

0 comments on commit 780277b

Please sign in to comment.