diff --git a/README.md b/README.md index 0c486b2..7a1386c 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,10 @@ As a challenge I'm trying to make it as user-friendly as possible. (It ain't the ## Server Side - [x] Chat Calculator + ## Client Side + +### New Features - [x] Teleportation Angle Viewer for [this machine](https://www.youtube.com/watch?v=FnUE-ZaALLw) ![Teleportation Keybindings](https://i.imgur.com/gjO1H3d.png) - [x] Removed game fog (lava, water, etc.) @@ -48,6 +51,11 @@ As a challenge I'm trying to make it as user-friendly as possible. (It ain't the - [x] Removed darkness effect - [x] Toggleable +### Changes +- Shared Ender Chest + - [x] Open/close EC block while opening/closing SEC + - [x] Play open & close sounds + # Features to come ## Server Side diff --git a/src/main/java/wtf/hak/survivalfabric/sharedenderchest/SharedEnderChest.java b/src/main/java/wtf/hak/survivalfabric/sharedenderchest/SharedEnderChest.java index 0923f02..ae428e7 100644 --- a/src/main/java/wtf/hak/survivalfabric/sharedenderchest/SharedEnderChest.java +++ b/src/main/java/wtf/hak/survivalfabric/sharedenderchest/SharedEnderChest.java @@ -10,6 +10,7 @@ import net.fabricmc.fabric.api.event.player.UseBlockCallback; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; +import net.minecraft.block.Blocks; import net.minecraft.block.EnderChestBlock; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.Inventories; @@ -20,6 +21,7 @@ import net.minecraft.nbt.NbtSizeTracker; import net.minecraft.screen.GenericContainerScreenHandler; import net.minecraft.screen.SimpleNamedScreenHandlerFactory; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; @@ -88,15 +90,13 @@ public class SharedEnderChest implements ServerLifecycleEvents.ServerStopping, S if (!player.isSpectator()) { if(!getConfig().sharedEnderChestLimitedAccess) { if (world.isClient()) return ActionResult.SUCCESS; - playEnderChestOpenSound(world, hitResult.getBlockPos()); - openSharedEnderChest(player); + openSharedEnderChest(player, world, hitResult.getBlockPos()); return ActionResult.SUCCESS; } else { for(String name : getConfig().sharedEnderChestNames) { if(name.toLowerCase().strip().equalsIgnoreCase(player.getNameForScoreboard().toLowerCase())) { if (world.isClient()) return ActionResult.SUCCESS; - playEnderChestOpenSound(world, hitResult.getBlockPos()); - openSharedEnderChest(player); + openSharedEnderChest(player, world, hitResult.getBlockPos()); return ActionResult.SUCCESS; } } @@ -113,7 +113,10 @@ public class SharedEnderChest implements ServerLifecycleEvents.ServerStopping, S } - public static void openSharedEnderChest(PlayerEntity player) { + public static void openSharedEnderChest(PlayerEntity player, World world, BlockPos pos) { + playEnderChestOpenSound(world, pos); + fakeEnderChestOpen(world, pos, true); + sharedInventory.openedEnderChests.put(player, pos); player.openHandledScreen(new SimpleNamedScreenHandlerFactory((int_1, playerInventory, playerEntity) -> new GenericContainerScreenHandler(getConfig().screenHandlerType(), int_1, playerInventory, sharedInventory, getConfig().sharedEnderChestRows), Text.of(getConfig().sharedEnderChestName))); } @@ -122,6 +125,19 @@ public class SharedEnderChest implements ServerLifecycleEvents.ServerStopping, S world.playSound(null, pos, SoundEvents.BLOCK_ENDER_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F); } + public static void playEnderChestCloseSound(World world, BlockPos pos) { + world.playSound(null, pos, SoundEvents.BLOCK_ENDER_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F); + } + + public static void fakeEnderChestOpen(World world, BlockPos pos, boolean open) { + if (!(world.getBlockState(pos).getBlock() instanceof EnderChestBlock)) { + return; + } + + world.addSyncedBlockEvent(pos, Blocks.ENDER_CHEST, 1, open ? 1 : 0); + } + + private static File getFile(MinecraftServer server) { return server.getSavePath(WorldSavePath.ROOT).resolve("sharedenderchest.sav").toFile(); } diff --git a/src/main/java/wtf/hak/survivalfabric/sharedenderchest/SharedInventory.java b/src/main/java/wtf/hak/survivalfabric/sharedenderchest/SharedInventory.java index 20e721b..82af0df 100644 --- a/src/main/java/wtf/hak/survivalfabric/sharedenderchest/SharedInventory.java +++ b/src/main/java/wtf/hak/survivalfabric/sharedenderchest/SharedInventory.java @@ -5,10 +5,15 @@ import net.minecraft.inventory.Inventories; import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; import net.minecraft.util.collection.DefaultedList; +import net.minecraft.util.math.BlockPos; + +import java.util.HashMap; +import java.util.Map; public class SharedInventory implements Inventory { private final DefaultedList stacks; + public final Map openedEnderChests = new HashMap<>(); public SharedInventory(int inventoryRows) { this.stacks = DefaultedList.ofSize(inventoryRows * 9, ItemStack.EMPTY); @@ -80,4 +85,11 @@ public class SharedInventory implements Inventory { public void clear() { stacks.clear(); } + + @Override + public void onClose(PlayerEntity player) { + BlockPos pos = openedEnderChests.remove(player); + SharedEnderChest.fakeEnderChestOpen(player.getWorld(), pos, false); + SharedEnderChest.playEnderChestCloseSound(player.getWorld(), pos); + } } \ No newline at end of file