From 9d528f3ba69cfdd1a9ead54e49d253038313bf97 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Tue, 2 Jan 2024 15:04:29 -0600 Subject: [PATCH 01/17] Rework light switch and shower handle --- .../pfm/blocks/BasicShowerHandleBlock.java | 3 ++- .../pfm/blocks/LightSwitchBlock.java | 3 ++- .../blockentities/LightSwitchBlockEntity.java | 13 ++++++---- .../ShowerHandleBlockEntity.java | 25 ++++++++++--------- .../pfm/items/LightSwitchItem.java | 15 ++++++++--- .../pfm/items/ShowerHandleItem.java | 12 +++++---- 6 files changed, 43 insertions(+), 28 deletions(-) diff --git a/common/src/main/java/com/unlikepaladin/pfm/blocks/BasicShowerHandleBlock.java b/common/src/main/java/com/unlikepaladin/pfm/blocks/BasicShowerHandleBlock.java index c32a43336..33d68227f 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/blocks/BasicShowerHandleBlock.java +++ b/common/src/main/java/com/unlikepaladin/pfm/blocks/BasicShowerHandleBlock.java @@ -107,7 +107,8 @@ public BlockState toggleOpen(BlockState state, World world, BlockPos pos, boolea state = state.cycle(POWERED);} world.setBlockState(pos, state, Block.NOTIFY_ALL); this.updateNeighbors(state, world, pos); - ((ShowerHandleBlockEntity)(world.getBlockEntity(pos))).setState(state.get(POWERED)); + if (world.getBlockEntity(pos) instanceof ShowerHandleBlockEntity) + ((ShowerHandleBlockEntity)(world.getBlockEntity(pos))).setState(state.get(POWERED)); return state; } diff --git a/common/src/main/java/com/unlikepaladin/pfm/blocks/LightSwitchBlock.java b/common/src/main/java/com/unlikepaladin/pfm/blocks/LightSwitchBlock.java index cdf5b51c0..08b3c05ec 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/blocks/LightSwitchBlock.java +++ b/common/src/main/java/com/unlikepaladin/pfm/blocks/LightSwitchBlock.java @@ -112,7 +112,8 @@ public BlockState togglePower(BlockState state, World world, BlockPos pos, boole state = state.cycle(POWERED);} world.setBlockState(pos, state, Block.NOTIFY_ALL); this.updateNeighbors(state, world, pos); - ((LightSwitchBlockEntity)world.getBlockEntity(pos)).setState(state.get(POWERED)); + if (world.getBlockEntity(pos) instanceof LightSwitchBlockEntity) + ((LightSwitchBlockEntity)world.getBlockEntity(pos)).setState(state.get(POWERED)); return state; } diff --git a/common/src/main/java/com/unlikepaladin/pfm/blocks/blockentities/LightSwitchBlockEntity.java b/common/src/main/java/com/unlikepaladin/pfm/blocks/blockentities/LightSwitchBlockEntity.java index feb2ea815..f9b49e486 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/blocks/blockentities/LightSwitchBlockEntity.java +++ b/common/src/main/java/com/unlikepaladin/pfm/blocks/blockentities/LightSwitchBlockEntity.java @@ -48,18 +48,21 @@ public void addLight(long pos) } } + + public void setState(boolean powered) { if(!lights.isEmpty()) { - lights.removeIf(lightPos -> + lights.removeIf(offset -> { - BlockState state = world.getBlockState(lightPos); + BlockState state = world.getBlockState(this.pos.subtract(offset)); return !(state.getBlock() instanceof PowerableBlock); }); - lights.forEach(lightPos -> + lights.forEach(offset -> { - BlockState state = world.getBlockState(lightPos); - ((PowerableBlock) state.getBlock()).setPowered(world, lightPos, powered); + BlockPos actualPos = this.pos.subtract(offset); + BlockState state = world.getBlockState(actualPos); + ((PowerableBlock) state.getBlock()).setPowered(world, actualPos, powered); }); diff --git a/common/src/main/java/com/unlikepaladin/pfm/blocks/blockentities/ShowerHandleBlockEntity.java b/common/src/main/java/com/unlikepaladin/pfm/blocks/blockentities/ShowerHandleBlockEntity.java index 5bf981f47..17b31324c 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/blocks/blockentities/ShowerHandleBlockEntity.java +++ b/common/src/main/java/com/unlikepaladin/pfm/blocks/blockentities/ShowerHandleBlockEntity.java @@ -10,17 +10,17 @@ import net.minecraft.util.math.BlockPos; public class ShowerHandleBlockEntity extends BlockEntity { - protected BlockPos showerHead; + protected BlockPos showerOffset; public ShowerHandleBlockEntity(BlockPos pos, BlockState state) { super(BlockEntities.SHOWER_HANDLE_BLOCK_ENTITY, pos, state); - this.showerHead = null; + this.showerOffset = null; } @Override public NbtCompound writeNbt(NbtCompound nbt) { super.writeNbt(nbt); - if (this.showerHead != null) { - NbtLong showerHeadPos = NbtLong.of(this.showerHead.asLong()); + if (this.showerOffset != null) { + NbtLong showerHeadPos = NbtLong.of(this.showerOffset.asLong()); nbt.put("showerHead", showerHeadPos); } return nbt; @@ -30,21 +30,22 @@ public NbtCompound writeNbt(NbtCompound nbt) { public void readNbt(NbtCompound nbt) { super.readNbt(nbt); if(nbt.contains("showerHead", NbtElement.LONG_TYPE)){ - this.showerHead = BlockPos.fromLong(nbt.getLong("showerHead")); + this.showerOffset = BlockPos.fromLong(nbt.getLong("showerHead")); } } public void setState(boolean open) { - if (this.showerHead != null) { - if(this.world.getBlockEntity(this.showerHead) != null) { + if (this.showerOffset != null) { + BlockPos showerHeadPos = this.pos.subtract(this.showerOffset); + if(this.world.getBlockEntity(showerHeadPos) != null) { - BlockState state = world.getBlockState(this.showerHead); - ((ShowerHeadBlockEntity)world.getBlockEntity(this.showerHead)).setOpen(open); + BlockState state = world.getBlockState(showerHeadPos); + ((ShowerHeadBlockEntity)world.getBlockEntity(showerHeadPos)).setOpen(open); - world.updateListeners(this.showerHead, state, state, Block.NOTIFY_LISTENERS); - } else if (this.world.getBlockEntity(this.showerHead) == null) { - this.showerHead = null; + world.updateListeners(showerHeadPos, state, state, Block.NOTIFY_LISTENERS); + } else if (this.world.getBlockEntity(showerHeadPos) == null) { + this.showerOffset = null; } } } diff --git a/common/src/main/java/com/unlikepaladin/pfm/items/LightSwitchItem.java b/common/src/main/java/com/unlikepaladin/pfm/items/LightSwitchItem.java index fde1c37b0..4fe648344 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/items/LightSwitchItem.java +++ b/common/src/main/java/com/unlikepaladin/pfm/items/LightSwitchItem.java @@ -83,20 +83,27 @@ protected boolean canPlace(ItemPlacementContext context, BlockState state) { WorldView world = context.getWorld(); Direction side = context.getSide(); NbtList lights = getLights(context.getStack()); + if (!side.getAxis().isHorizontal()) { + return false; + } if (lights != null) { ArrayList removedLights = new ArrayList<>(); - Direction facing = context.getPlayerFacing(); - + ArrayList lightOffsets = new ArrayList<>(); for (Iterator iterator = lights.iterator(); iterator.hasNext();) { NbtElement nbtElement = iterator.next(); BlockPos lightPos = BlockPos.fromLong(((NbtLong) nbtElement).longValue()); - BlockPos placedPos = pos.offset(facing); - double distance = Math.sqrt(lightPos.getSquaredDistance(placedPos.getX() + 0.5, placedPos.getY() + 0.5, placedPos.getZ() + 0.5, true)); + double distance = Math.sqrt(lightPos.getSquaredDistance(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, true)); if (distance > 16) { removedLights.add(BlockPos.fromLong(((NbtLong) nbtElement).longValue())); iterator.remove(); + } else { + lightOffsets.add(pos.subtract(lightPos)); } } + context.getStack().setNbt(new NbtCompound()); + for (BlockPos blockPos : lightOffsets) { + addLight(context.getStack(), blockPos); + } if (!removedLights.isEmpty() && context.getWorld().isClient){ context.getPlayer().sendMessage(new TranslatableText("message.pfm.light_switch_far", removedLights.toString()), false); diff --git a/common/src/main/java/com/unlikepaladin/pfm/items/ShowerHandleItem.java b/common/src/main/java/com/unlikepaladin/pfm/items/ShowerHandleItem.java index e74dbc5ef..42410a61b 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/items/ShowerHandleItem.java +++ b/common/src/main/java/com/unlikepaladin/pfm/items/ShowerHandleItem.java @@ -63,20 +63,22 @@ public ActionResult useOnBlock(ItemUsageContext context) { protected boolean canPlace(ItemPlacementContext context, BlockState state) { BlockPos pos = context.getBlockPos(); WorldView world = context.getWorld(); - NbtLong showerHeadPos = getShowerHead(context.getStack()); + NbtLong showerHeadLong = getShowerHead(context.getStack()); Direction playerFacing = context.getPlayerFacing(); Direction placeDirection = context.getSide(); - if (showerHeadPos != null) { - BlockPos lightPos = BlockPos.fromLong(showerHeadPos.longValue()); + if (showerHeadLong != null) { + BlockPos headPos = BlockPos.fromLong(showerHeadLong.longValue()); BlockPos placedPos = pos.offset(playerFacing); - double distance = Math.sqrt(lightPos.getSquaredDistance(placedPos.getX() + 0.5, placedPos.getY() + 0.5, placedPos.getZ() + 0.5, true)); + double distance = Math.sqrt(headPos.getSquaredDistance(placedPos.getX() + 0.5, placedPos.getY() + 0.5, placedPos.getZ() + 0.5, true)); if (distance > 16 && world.isClient()){ - context.getPlayer().sendMessage(new TranslatableText("message.pfm.shower_handle_far", lightPos.toString()), false); + context.getPlayer().sendMessage(new TranslatableText("message.pfm.shower_handle_far", headPos.toString()), false); } if (distance > 16) { context.getStack().setNbt(null); + } else { + setShowerHeadPosNBT(context.getStack(), pos.subtract(headPos)); } return state.getBlock().canPlaceAt(state, world, pos) && placeDirection.getAxis().isHorizontal(); } From 1626083555aea5da211bce62d8f25f1eb5439a8c Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Tue, 2 Jan 2024 15:08:59 -0600 Subject: [PATCH 02/17] Fix Freezer's missing particles --- .../pfm/models/block/iron_fridge/iron_fridge_bottom.json | 3 ++- .../pfm/models/block/iron_fridge/iron_fridge_bottom_open.json | 3 ++- .../assets/pfm/models/block/iron_fridge/iron_fridge_full.json | 3 ++- .../pfm/models/block/iron_fridge/iron_fridge_middle.json | 3 ++- .../pfm/models/block/iron_fridge/iron_fridge_middle_open.json | 3 ++- .../pfm/models/block/iron_fridge/iron_fridge_single.json | 3 ++- .../pfm/models/block/iron_fridge/iron_fridge_single_open.json | 3 ++- .../assets/pfm/models/block/iron_fridge/iron_fridge_top.json | 3 ++- .../pfm/models/block/iron_fridge/iron_fridge_top_open.json | 3 ++- 9 files changed, 18 insertions(+), 9 deletions(-) diff --git a/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_bottom.json b/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_bottom.json index f35f77904..bd1cee7cd 100644 --- a/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_bottom.json +++ b/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_bottom.json @@ -3,7 +3,8 @@ "textures": { "2": "pfm:block/fridge/fridge_back", "legs": "block/light_gray_concrete", - "base": "block/iron_block" + "base": "block/iron_block", + "particle": "block/iron_block" }, "elements": [ { diff --git a/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_bottom_open.json b/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_bottom_open.json index cdc88da33..25750f33b 100644 --- a/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_bottom_open.json +++ b/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_bottom_open.json @@ -3,7 +3,8 @@ "textures": { "2": "pfm:block/fridge/fridge_back", "legs": "block/light_gray_concrete", - "base": "block/iron_block" + "base": "block/iron_block", + "particle": "block/iron_block" }, "elements": [ { diff --git a/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_full.json b/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_full.json index c862e1d28..e397b25fd 100644 --- a/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_full.json +++ b/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_full.json @@ -3,7 +3,8 @@ "textures": { "2": "pfm:block/fridge/fridge_back", "legs": "block/light_gray_concrete", - "base": "block/iron_block" + "base": "block/iron_block", + "particle": "block/iron_block" }, "elements": [ { diff --git a/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_middle.json b/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_middle.json index b77b35db6..0afab21b3 100644 --- a/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_middle.json +++ b/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_middle.json @@ -3,7 +3,8 @@ "textures": { "2": "pfm:block/fridge/fridge_back", "legs": "block/light_gray_concrete", - "base": "block/iron_block" + "base": "block/iron_block", + "particle": "block/iron_block" }, "elements": [ { diff --git a/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_middle_open.json b/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_middle_open.json index 85914ac5b..397d07d9a 100644 --- a/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_middle_open.json +++ b/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_middle_open.json @@ -3,7 +3,8 @@ "textures": { "2": "pfm:block/fridge/fridge_back", "legs": "block/light_gray_concrete", - "base": "block/iron_block" + "base": "block/iron_block", + "particle": "block/iron_block" }, "elements": [ { diff --git a/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_single.json b/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_single.json index 9d92cacb6..f09b67a21 100644 --- a/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_single.json +++ b/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_single.json @@ -3,7 +3,8 @@ "textures": { "2": "pfm:block/fridge/fridge_back", "legs": "block/light_gray_concrete", - "base": "block/iron_block" + "base": "block/iron_block", + "particle": "block/iron_block" }, "elements": [ { diff --git a/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_single_open.json b/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_single_open.json index b104b3937..eb47bbc7c 100644 --- a/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_single_open.json +++ b/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_single_open.json @@ -3,7 +3,8 @@ "textures": { "2": "pfm:block/fridge/fridge_back", "legs": "block/light_gray_concrete", - "base": "block/iron_block" + "base": "block/iron_block", + "particle": "block/iron_block" }, "elements": [ { diff --git a/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_top.json b/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_top.json index 24b70519c..84b7f54be 100644 --- a/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_top.json +++ b/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_top.json @@ -3,7 +3,8 @@ "textures": { "2": "pfm:block/fridge/fridge_back", "legs": "block/light_gray_concrete", - "base": "block/iron_block" + "base": "block/iron_block", + "particle": "block/iron_block" }, "elements": [ { diff --git a/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_top_open.json b/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_top_open.json index 95c83f688..34cc68e1f 100644 --- a/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_top_open.json +++ b/common/src/main/resources/assets/pfm/models/block/iron_fridge/iron_fridge_top_open.json @@ -3,7 +3,8 @@ "textures": { "2": "pfm:block/fridge/fridge_back", "legs": "block/light_gray_concrete", - "base": "block/iron_block" + "base": "block/iron_block", + "particle": "block/iron_block" }, "elements": [ { From dc9f9fd66856242c5cd80b909dbf258247115402 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Tue, 2 Jan 2024 16:05:36 -0600 Subject: [PATCH 03/17] Fix a mirror with immersive portals issue --- .../pfm/compat/imm_ptl/fabric/PFMImmersivePortalsImpl.java | 3 ++- .../pfm/compat/imm_ptl/fabric/entity/PFMMirrorEntity.java | 4 +--- .../pfm/compat/imm_ptl/forge/PFMImmersivePortalsImpl.java | 3 ++- .../pfm/compat/imm_ptl/forge/entity/PFMMirrorEntity.java | 4 +--- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/fabric/src/main/java/com/unlikepaladin/pfm/compat/imm_ptl/fabric/PFMImmersivePortalsImpl.java b/fabric/src/main/java/com/unlikepaladin/pfm/compat/imm_ptl/fabric/PFMImmersivePortalsImpl.java index e9e857e04..00e660b03 100644 --- a/fabric/src/main/java/com/unlikepaladin/pfm/compat/imm_ptl/fabric/PFMImmersivePortalsImpl.java +++ b/fabric/src/main/java/com/unlikepaladin/pfm/compat/imm_ptl/fabric/PFMImmersivePortalsImpl.java @@ -16,10 +16,11 @@ public class PFMImmersivePortalsImpl implements PFMModCompatibility { private PFMClientModCompatibility clientModCompatibility; - public static final EntityType MIRROR = EntityType.Builder.create(PFMMirrorEntity::new, SpawnGroup.MISC).setDimensions(0.0F, 0.0F).makeFireImmune().disableSummon().build("mirror_entity"); + public static EntityType MIRROR; @Override public void registerEntityTypes() { + MIRROR = EntityType.Builder.create(PFMMirrorEntity::new, SpawnGroup.MISC).setDimensions(0.0F, 0.0F).makeFireImmune().disableSummon().build("mirror_entity"); EntityRegistry.registerEntityType("mirror_entity", MIRROR); } diff --git a/fabric/src/main/java/com/unlikepaladin/pfm/compat/imm_ptl/fabric/entity/PFMMirrorEntity.java b/fabric/src/main/java/com/unlikepaladin/pfm/compat/imm_ptl/fabric/entity/PFMMirrorEntity.java index 1c5a7cc5d..22c9cb51d 100644 --- a/fabric/src/main/java/com/unlikepaladin/pfm/compat/imm_ptl/fabric/entity/PFMMirrorEntity.java +++ b/fabric/src/main/java/com/unlikepaladin/pfm/compat/imm_ptl/fabric/entity/PFMMirrorEntity.java @@ -24,7 +24,6 @@ import java.util.stream.Stream; public class PFMMirrorEntity extends Mirror { - public static EntityType entityType = PFMImmersivePortalsImpl.MIRROR; @Nullable public IntBox wallArea; @Nullable @@ -34,7 +33,6 @@ public class PFMMirrorEntity extends Mirror { public PFMMirrorEntity(EntityType entityType, World world) { super(entityType, world); - PFMMirrorEntity.entityType = entityType; } @Override @@ -151,7 +149,7 @@ public static void createMirror(ServerWorld world, BlockPos glassPos, Direction return; } - PFMMirrorEntity pfmMirrorEntity = PFMMirrorEntity.entityType.create(world); + PFMMirrorEntity pfmMirrorEntity = PFMImmersivePortalsImpl.MIRROR.create(world); double distanceToCenter = -0.452; Box wallBox = getWallBox(world, shape.area.stream()); diff --git a/forge/src/main/java/com/unlikepaladin/pfm/compat/imm_ptl/forge/PFMImmersivePortalsImpl.java b/forge/src/main/java/com/unlikepaladin/pfm/compat/imm_ptl/forge/PFMImmersivePortalsImpl.java index e682d3433..857cf5011 100644 --- a/forge/src/main/java/com/unlikepaladin/pfm/compat/imm_ptl/forge/PFMImmersivePortalsImpl.java +++ b/forge/src/main/java/com/unlikepaladin/pfm/compat/imm_ptl/forge/PFMImmersivePortalsImpl.java @@ -16,10 +16,11 @@ public class PFMImmersivePortalsImpl implements PFMModCompatibility { private PFMClientModCompatibility clientModCompatibility; - public static final EntityType MIRROR = EntityType.Builder.create(PFMMirrorEntity::new, SpawnGroup.MISC).setDimensions(0.0F, 0.0F).makeFireImmune().disableSummon().build("mirror_entity"); + public static EntityType MIRROR; @Override public void registerEntityTypes() { + MIRROR = EntityType.Builder.create(PFMMirrorEntity::new, SpawnGroup.MISC).setDimensions(0.0F, 0.0F).makeFireImmune().disableSummon().build("mirror_entity"); EntityRegistry.registerEntityType("mirror_entity", MIRROR); } diff --git a/forge/src/main/java/com/unlikepaladin/pfm/compat/imm_ptl/forge/entity/PFMMirrorEntity.java b/forge/src/main/java/com/unlikepaladin/pfm/compat/imm_ptl/forge/entity/PFMMirrorEntity.java index 5bfadffa6..3879677a1 100644 --- a/forge/src/main/java/com/unlikepaladin/pfm/compat/imm_ptl/forge/entity/PFMMirrorEntity.java +++ b/forge/src/main/java/com/unlikepaladin/pfm/compat/imm_ptl/forge/entity/PFMMirrorEntity.java @@ -24,7 +24,6 @@ import java.util.stream.Stream; public class PFMMirrorEntity extends Mirror { - public static EntityType entityType = PFMImmersivePortalsImpl.MIRROR; @Nullable public IntBox wallArea; @Nullable @@ -34,7 +33,6 @@ public class PFMMirrorEntity extends Mirror { public PFMMirrorEntity(EntityType entityType, World world) { super(entityType, world); - PFMMirrorEntity.entityType = entityType; } @Override @@ -151,7 +149,7 @@ public static void createMirror(ServerWorld world, BlockPos glassPos, Direction return; } - PFMMirrorEntity pfmMirrorEntity = PFMMirrorEntity.entityType.create(world); + PFMMirrorEntity pfmMirrorEntity = PFMImmersivePortalsImpl.MIRROR.create(world); double distanceToCenter = -0.452; Box wallBox = getWallBox(world, shape.area.stream()); From d855151355007f099a4b2bff0df4a38b1657e072 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Tue, 2 Jan 2024 17:12:34 -0600 Subject: [PATCH 04/17] Moved to new JSON config system --- .../pfm/config/PaladinFurnitureModConfig.java | 115 +++++++++++++----- .../pfm/fabric/PaladinFurnitureModFabric.java | 2 +- .../pfm/forge/PaladinFurnitureModForge.java | 2 +- 3 files changed, 87 insertions(+), 32 deletions(-) diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/PaladinFurnitureModConfig.java b/common/src/main/java/com/unlikepaladin/pfm/config/PaladinFurnitureModConfig.java index ca42c327e..42f11b5ba 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/config/PaladinFurnitureModConfig.java +++ b/common/src/main/java/com/unlikepaladin/pfm/config/PaladinFurnitureModConfig.java @@ -1,14 +1,15 @@ package com.unlikepaladin.pfm.config; +import com.google.gson.*; +import com.google.gson.reflect.TypeToken; import com.unlikepaladin.pfm.PaladinFurnitureMod; import com.unlikepaladin.pfm.config.option.AbstractConfigOption; import com.unlikepaladin.pfm.config.option.BooleanConfigOption; import com.unlikepaladin.pfm.config.option.Side; import net.minecraft.text.TranslatableText; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.*; +import java.lang.reflect.Type; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; @@ -21,10 +22,12 @@ public class PaladinFurnitureModConfig { private static final String COMMENT = "This file stores configuration options for Paladin's Furniture Mod"; private final Path propertiesPath; + private final Path directoryPath; public HashMap options = new LinkedHashMap<>(); public static final String MOD_OPTIONS = "pfm.config.categories.mod_options"; public static final String GAMEPLAY_OPTIONS = "pfm.config.categories.gameplay_options"; + static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create(); public PaladinFurnitureModConfig(Path propertiesPath) { this.addOptions( @@ -40,7 +43,8 @@ public PaladinFurnitureModConfig(Path propertiesPath) { renderImmersivePortalsMirrors = new BooleanConfigOption(new TranslatableText("pfm.option.renderImmersivePortalsMirrors"), new TranslatableText("pfm.option.renderImmersivePortalsMirrors.tooltip"), GAMEPLAY_OPTIONS, true, Side.CLIENT), spawnImmersivePortalsMirror = new BooleanConfigOption(new TranslatableText("pfm.option.spawnImmersivePortalsMirror"), new TranslatableText("pfm.option.spawnImmersivePortalsMirror.tooltip"), GAMEPLAY_OPTIONS, true, Side.SERVER) ); - this.propertiesPath = propertiesPath; + this.propertiesPath = propertiesPath.resolve("pfm.json"); + this.directoryPath = propertiesPath; } private void addOptions(AbstractConfigOption... args) { @@ -133,17 +137,74 @@ public Path getPath() { * * @throws IOException if the file cannot be loaded */ - public void load() throws IOException { + Path legacyConfig = directoryPath.resolve("pfm.properties"); + if (Files.exists(legacyConfig)) + loadLegacyProperties(legacyConfig); + if (!Files.exists(propertiesPath)) { return; } + JsonObject config = new JsonObject(); + try (FileReader reader = new FileReader(propertiesPath.toString())) { + JsonElement element = new JsonParser().parse(reader); + if (element.isJsonObject()) { + config = element.getAsJsonObject(); + } + } + + checkForUpdates.setValue(getFromJsonElement(config.get("checkForUpdates"), true)); + shaderSolidFix.setValue(getFromJsonElement(config.get("shaderSolidFix"), false)); + doChairsFacePlayer.setValue(getFromJsonElement(config.get("chairsFacePlayer"), true)); + countersOfDifferentMaterialsConnect.setValue(getFromJsonElement(config.get("countersOfDifferentMaterialsConnect"), false)); + tablesOfDifferentMaterialsConnect.setValue(getFromJsonElement(config.get("tablesOfDifferentMaterialsConnect"), false)); + foodPopsOffStove.setValue(getFromJsonElement(config.get("foodPopsOffStove"), false)); + enableBook.setValue(getFromJsonElement(config.get("enableBook"), false)); + differentMirrorsConnect.setValue(getFromJsonElement(config.get("differentMirrorsConnect"), false)); + mobsSitOnChairs.setValue(getFromJsonElement(config.get("mobsSitOnChairs"), false)); + renderImmersivePortalsMirrors.setValue(getFromJsonElement(config.get("renderImmersivePortalsMirrors"), true)); + spawnImmersivePortalsMirror.setValue(getFromJsonElement(config.get("spawnImmersivePortalsMirror"), true)); + + for (String key : options.keySet()) { + if (!config.has(key.replace("pfm.option.", ""))){ + PaladinFurnitureMod.GENERAL_LOGGER.warn("Missing Config Option: " + key.replace("pfm.option.", "") + ", resetting to default value."); + options.get(key).setValue(options.get(key).getDefaultValue()); + save(); + } + } + } + + + public static T getFromJsonElement(JsonElement element, T defaultValue) { + if (element != null && element.isJsonPrimitive()) { + JsonPrimitive primitive = element.getAsJsonPrimitive(); + + Type targetType; + + if (primitive.isString()) { + targetType = new TypeToken() {}.getType(); + } else if (primitive.isBoolean()) { + targetType = new TypeToken() {}.getType(); + } else if (primitive.isNumber()) { + targetType = new TypeToken() {}.getType(); + } else { + // Handle the case where the primitive type is not supported + return null; + } + + return GSON.fromJson(primitive, targetType); + } + return defaultValue; + } + + public void loadLegacyProperties(Path legacyConfigFile) throws IOException { Properties properties = new Properties(); // NB: This uses ISO-8859-1 with unicode escapes as the encoding - try (InputStream is = Files.newInputStream(propertiesPath)) { + try (InputStream is = Files.newInputStream(legacyConfigFile)) { properties.load(is); } + checkForUpdates.setValue("true".equals(properties.getProperty("checkForUpdates"))); shaderSolidFix.setValue(!"false".equals(properties.getProperty("shaderSolidFix"))); doChairsFacePlayer.setValue("true".equals(properties.getProperty("chairsFacePlayer"))); @@ -155,14 +216,9 @@ public void load() throws IOException { mobsSitOnChairs.setValue("true".equals(properties.getProperty("mobsSitOnChairs"))); renderImmersivePortalsMirrors.setValue("true".equals(properties.getProperty("renderImmersivePortalsMirrors"))); spawnImmersivePortalsMirror.setValue("true".equals(properties.getProperty("spawnImmersivePortalsMirror"))); - - for (String key : options.keySet()) { - if (!properties.containsKey(key.replace("pfm.option.", ""))){ - PaladinFurnitureMod.GENERAL_LOGGER.warn("Missing Config Option: " + key.replace("pfm.option.", "") + ", resetting to default value."); - options.get(key).setValue(options.get(key).getDefaultValue()); - save(); - } - } + save(); + Files.delete(legacyConfigFile); + PaladinFurnitureMod.GENERAL_LOGGER.info("Successfully migrated to new config"); } /** @@ -171,22 +227,21 @@ public void load() throws IOException { * @throws IOException file exceptions */ public void save() throws IOException { - Properties properties = new Properties(); - properties.setProperty("checkForUpdates", checkForUpdates.getValue() ? "true" : "false"); - properties.setProperty("shaderSolidFix", shaderSolidFix.getValue() ? "true" : "false"); - properties.setProperty("chairsFacePlayer", doChairsFacePlayer.getValue() ? "true" : "false"); - properties.setProperty("countersOfDifferentMaterialsConnect", countersOfDifferentMaterialsConnect.getValue() ? "true" : "false"); - properties.setProperty("foodPopsOffStove", foodPopsOffStove.getValue() ? "true" : "false"); - properties.setProperty("tablesOfDifferentMaterialsConnect",tablesOfDifferentMaterialsConnect.getValue() ? "true" : "false"); - properties.setProperty("enableBook",enableBook.getValue() ? "true" : "false"); - properties.setProperty("differentMirrorsConnect", differentMirrorsConnect.getValue() ? "true" : "false"); - properties.setProperty("mobsSitOnChairs", mobsSitOnChairs.getValue() ? "true" : "false"); - properties.setProperty("renderImmersivePortalsMirrors", renderImmersivePortalsMirrors.getValue() ? "true" : "false"); - properties.setProperty("spawnImmersivePortalsMirror", spawnImmersivePortalsMirror.getValue() ? "true" : "false"); - - // NB: This uses ISO-8859-1 with unicode escapes as the encoding - try (OutputStream os = Files.newOutputStream(propertiesPath)) { - properties.store(os, COMMENT); + JsonObject object = new JsonObject(); + object.addProperty("checkForUpdates", checkForUpdates.getValue()); + object.addProperty("shaderSolidFix", shaderSolidFix.getValue()); + object.addProperty("chairsFacePlayer", doChairsFacePlayer.getValue()); + object.addProperty("countersOfDifferentMaterialsConnect", countersOfDifferentMaterialsConnect.getValue()); + object.addProperty("foodPopsOffStove", foodPopsOffStove.getValue()); + object.addProperty("tablesOfDifferentMaterialsConnect", tablesOfDifferentMaterialsConnect.getValue()); + object.addProperty("enableBook", enableBook.getValue()); + object.addProperty("differentMirrorsConnect", differentMirrorsConnect.getValue()); + object.addProperty("mobsSitOnChairs", mobsSitOnChairs.getValue()); + object.addProperty("renderImmersivePortalsMirrors", renderImmersivePortalsMirrors.getValue()); + object.addProperty("spawnImmersivePortalsMirror", spawnImmersivePortalsMirror.getValue()); + + try (FileWriter writer = new FileWriter(propertiesPath.toString())) { + GSON.toJson(object, writer); } } } diff --git a/fabric/src/main/java/com/unlikepaladin/pfm/fabric/PaladinFurnitureModFabric.java b/fabric/src/main/java/com/unlikepaladin/pfm/fabric/PaladinFurnitureModFabric.java index d1ee6b213..82cf67ac7 100644 --- a/fabric/src/main/java/com/unlikepaladin/pfm/fabric/PaladinFurnitureModFabric.java +++ b/fabric/src/main/java/com/unlikepaladin/pfm/fabric/PaladinFurnitureModFabric.java @@ -41,7 +41,7 @@ public void onInitialize() { // This code runs as soon as Minecraft is in a mod-load-ready state. // However, some things (like resources) may still be uninitialized. // Proceed with mild caution. - pfmConfig = new PaladinFurnitureModConfig(FabricLoader.getInstance().getConfigDir().resolve("pfm.properties")); + pfmConfig = new PaladinFurnitureModConfig(FabricLoader.getInstance().getConfigDir()); try { pfmConfig.initialize(); } catch (IOException e) { diff --git a/forge/src/main/java/com/unlikepaladin/pfm/forge/PaladinFurnitureModForge.java b/forge/src/main/java/com/unlikepaladin/pfm/forge/PaladinFurnitureModForge.java index 6995944cb..41e1ab4a4 100644 --- a/forge/src/main/java/com/unlikepaladin/pfm/forge/PaladinFurnitureModForge.java +++ b/forge/src/main/java/com/unlikepaladin/pfm/forge/PaladinFurnitureModForge.java @@ -33,7 +33,7 @@ public class PaladinFurnitureModForge extends PaladinFurnitureMod { public static PaladinFurnitureModConfig pfmConfig; public PaladinFurnitureModForge() { - pfmConfig = new PaladinFurnitureModConfig(FMLPaths.CONFIGDIR.get().resolve("pfm.properties")); + pfmConfig = new PaladinFurnitureModConfig(FMLPaths.CONFIGDIR.get()); try { pfmConfig.initialize(); } catch (IOException e) { From 317af3125e8c6f21e52aeec3fd78e4222af4d252 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Sat, 17 Feb 2024 22:23:17 -0600 Subject: [PATCH 05/17] wip new config stuff, commented the variant blacklist out --- .../pfm/client/screens/PFMConfigScreen.java | 19 +- .../screens/widget/PFMOptionListWidget.java | 431 +++++++++++++++++- .../pfm/config/PaladinFurnitureModConfig.java | 28 +- .../config/option/AbstractConfigOption.java | 15 +- .../config/option/BooleanConfigOption.java | 18 +- .../pfm/config/option/ConfigIO.java | 3 +- .../pfm/config/option/ConfigOptionType.java | 2 +- .../pfm/config/option/ConfigOptionTypes.java | 2 +- .../pfm/config/option/ListConfigOption.java | 180 ++++++++ .../pfm/config/option/NullConfigOption.java | 2 +- .../option/StringArrayConfigOption.java | 242 ++++++++++ .../pfm/config/option/StringConfigOption.java | 112 +++++ .../pfm/registry/PFMItemGroup.java | 27 ++ 13 files changed, 1038 insertions(+), 43 deletions(-) create mode 100644 common/src/main/java/com/unlikepaladin/pfm/config/option/ListConfigOption.java create mode 100644 common/src/main/java/com/unlikepaladin/pfm/config/option/StringArrayConfigOption.java create mode 100644 common/src/main/java/com/unlikepaladin/pfm/config/option/StringConfigOption.java create mode 100644 common/src/main/java/com/unlikepaladin/pfm/registry/PFMItemGroup.java diff --git a/common/src/main/java/com/unlikepaladin/pfm/client/screens/PFMConfigScreen.java b/common/src/main/java/com/unlikepaladin/pfm/client/screens/PFMConfigScreen.java index ec3597af7..14f4d143d 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/client/screens/PFMConfigScreen.java +++ b/common/src/main/java/com/unlikepaladin/pfm/client/screens/PFMConfigScreen.java @@ -52,7 +52,8 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { MinecraftClient.getInstance().setScreen(parent); }, new TranslatableText("gui.pfm.changesMightNotBeSaved").setStyle(Style.EMPTY.withColor(0xf77f34).withBold(true)), new TranslatableText("gui.pfm.saveChanges"))); return true; - } + } else if (optionListWidget.keyPressed(keyCode, scanCode, modifiers)) + return true; return super.keyPressed(keyCode, scanCode, modifiers); } @@ -80,14 +81,24 @@ protected void init() { if (option.getDefaultValue() != this.optionListWidget.newConfigValues.get(option)) { this.optionListWidget.hasChanges.set(this.optionListWidget.configOptionToIndexForHasChanges.get(option), true); } - this.optionListWidget.newConfigValues.put(option, (Boolean) option.getDefaultValue()); + this.optionListWidget.newConfigValues.put(option, option.getDefaultValue()); + } else if (option.getType() == String.class) { + if (option.getDefaultValue() != this.optionListWidget.newConfigValues.get(option)) { + this.optionListWidget.hasChanges.set(this.optionListWidget.configOptionToIndexForHasChanges.get(option), true); + } + this.optionListWidget.newConfigValues.put(option, option.getDefaultValue()); } } else if (!isOnServer && option.getSide() == Side.SERVER) { if (option.getType() == Boolean.class) { if (option.getDefaultValue() != this.optionListWidget.newConfigValues.get(option)) { this.optionListWidget.hasChanges.set(this.optionListWidget.configOptionToIndexForHasChanges.get(option), true); } - this.optionListWidget.newConfigValues.put(option, (Boolean) option.getDefaultValue()); + this.optionListWidget.newConfigValues.put(option, option.getDefaultValue()); + } else if (option.getType() == String.class) { + if (option.getDefaultValue() != this.optionListWidget.newConfigValues.get(option)) { + this.optionListWidget.hasChanges.set(this.optionListWidget.configOptionToIndexForHasChanges.get(option), true); + } + this.optionListWidget.newConfigValues.put(option, option.getDefaultValue()); } } }); @@ -111,7 +122,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { drawCenteredText(matrices, this.textRenderer, TITLE.setStyle(Style.EMPTY.withColor(0xf77f34).withBold(true)), this.width / 2, 8, 0xFFFFFF); boolean bl = false; - for (Map.Entry optionEntry : optionListWidget.newConfigValues.entrySet()) { + for (Map.Entry optionEntry : optionListWidget.newConfigValues.entrySet()) { if (optionEntry.getValue() == optionEntry.getKey().getDefaultValue()) continue; bl = true; break; diff --git a/common/src/main/java/com/unlikepaladin/pfm/client/screens/widget/PFMOptionListWidget.java b/common/src/main/java/com/unlikepaladin/pfm/client/screens/widget/PFMOptionListWidget.java index 58ba09649..ae0d06b6f 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/client/screens/widget/PFMOptionListWidget.java +++ b/common/src/main/java/com/unlikepaladin/pfm/client/screens/widget/PFMOptionListWidget.java @@ -3,9 +3,7 @@ import com.google.common.collect.ImmutableList; import com.unlikepaladin.pfm.PaladinFurnitureMod; import com.unlikepaladin.pfm.client.screens.PFMConfigScreen; -import com.unlikepaladin.pfm.config.option.AbstractConfigOption; -import com.unlikepaladin.pfm.config.option.BooleanConfigOption; -import com.unlikepaladin.pfm.config.option.Side; +import com.unlikepaladin.pfm.config.option.*; import com.unlikepaladin.pfm.runtime.PFMAssetGenerator; import com.unlikepaladin.pfm.runtime.PFMDataGenerator; import com.unlikepaladin.pfm.runtime.PFMRuntimeResources; @@ -20,8 +18,10 @@ import net.minecraft.client.gui.screen.narration.NarrationPart; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.ElementListWidget; +import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.*; +import org.lwjgl.glfw.GLFW; import java.util.*; import java.util.function.Consumer; @@ -30,13 +30,13 @@ public class PFMOptionListWidget extends ElementListWidget newConfigValues; + public Map newConfigValues; public Map configOptionToIndexForHasChanges; + int index = 0; public PFMOptionListWidget(PFMConfigScreen parent, MinecraftClient client) { super(client, parent.width + 125, parent.height, 43, parent.height - 32, 20); this.parent = parent; String string = null; - int index = 0; hasChanges = new BitSet(PaladinFurnitureMod.getPFMConfig().options.size()); newConfigValues = new HashMap<>(PaladinFurnitureMod.getPFMConfig().options.size()); configOptionToIndexForHasChanges = new HashMap<>(PaladinFurnitureMod.getPFMConfig().options.size()); @@ -52,14 +52,30 @@ public PFMOptionListWidget(PFMConfigScreen parent, MinecraftClient client) { this.maxKeyNameLength = i; } if (configOptionEntry.getValue().getType() == Boolean.class) { - PFMOptionListWidget.this.newConfigValues.put(configOptionEntry.getValue(), (Boolean) configOptionEntry.getValue().getValue()); + PFMOptionListWidget.this.newConfigValues.put(configOptionEntry.getValue(), configOptionEntry.getValue().getValue()); this.addEntry(new BooleanEntry((BooleanConfigOption)configOptionEntry.getValue(), text, index)); - } else { + } else if (configOptionEntry.getValue().getType() == ArrayList.class) { + for (AbstractConfigOption configOption : (ListConfigOption)configOptionEntry.getValue()) { + PFMOptionListWidget.this.newConfigValues.put(configOption, configOption.getValue()); + configOptionToIndexForHasChanges.put(configOption, index); + index++; + } + PFMOptionListWidget.this.newConfigValues.put(configOptionEntry.getValue(), configOptionEntry.getValue().getValue()); + this.addEntry(new ListEntry((ListConfigOption) configOptionEntry.getValue(), text, index)); + } else if (configOptionEntry.getValue().getType() == String.class) { + PFMOptionListWidget.this.newConfigValues.put(configOptionEntry.getValue(), configOptionEntry.getValue().getValue()); + this.addEntry(new StringEntry((StringConfigOption) configOptionEntry.getValue(), text, index)); + } else if (configOptionEntry.getValue().getType() == String[].class) { + PFMOptionListWidget.this.newConfigValues.put(configOptionEntry.getValue(), new ArrayList<>(List.of((String[]) configOptionEntry.getValue().getValue()))); + this.addEntry(new StringArrayEntry((StringArrayConfigOption) configOptionEntry.getValue(), text, index)); + } + else { PaladinFurnitureMod.GENERAL_LOGGER.warn("Unsupported Config Type!"); } configOptionToIndexForHasChanges.put(configOptionEntry.getValue(), index); index++; } + //TODO : implement string here this.addEntry(new CategoryEntry(new LiteralText(""))); this.addEntry(new ButtonEntry(Side.CLIENT, new TranslatableText("pfm.option.regenAssets"), new TranslatableText("pfm.config.regen"), new TranslatableText("pfm.option.regenAssets.tooltip"), button -> { PFMFileUtil.deleteDir(PFMRuntimeResources.getAssetPackDirectory().toFile()); @@ -68,19 +84,27 @@ public PFMOptionListWidget(PFMConfigScreen parent, MinecraftClient client) { PFMRuntimeResources.runAsyncResourceGen(); MinecraftClient.getInstance().reloadResourcesConcurrently(); })); - ButtonEntry entry = new ButtonEntry(Side.SERVER, new TranslatableText("pfm.option.regenData"), new TranslatableText("pfm.config.regen"), new TranslatableText("pfm.option.regenData.tooltip"), button -> { + ButtonEntry dataEntry = new ButtonEntry(Side.SERVER, new TranslatableText("pfm.option.regenData"), new TranslatableText("pfm.config.regen"), new TranslatableText("pfm.option.regenData.tooltip"), button -> { PFMFileUtil.deleteDir(PFMRuntimeResources.getDataPackDirectory().toFile()); PFMDataGenerator.FROZEN = false; PFMRuntimeResources.prepareAsyncDataGen(true); PFMRuntimeResources.runAsyncResourceGen(); }); - entry.button.active = !PFMConfigScreen.isOnServer; - this.addEntry(entry); + dataEntry.button.active = !PFMConfigScreen.isOnServer; + this.addEntry(dataEntry); + } + + @Override + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + if (children().stream().anyMatch(entry -> entry.keyPressed(index, scanCode, modifiers))) + return true; + + return super.keyPressed(keyCode, scanCode, modifiers); } public void save() { - for (Map.Entry entry : newConfigValues.entrySet()) { - if (entry.getKey().getType() == Boolean.class) + for (Map.Entry entry : newConfigValues.entrySet()) { + if (entry.getKey().getType() == Boolean.class || entry.getKey().getType() == String.class) entry.getKey().setValue(entry.getValue()); } } @@ -136,6 +160,10 @@ public void appendNarrations(NarrationMessageBuilder builder) { } }); } + + @Override + public void resetValue() { + } } @Environment(value=EnvType.CLIENT) @@ -170,7 +198,7 @@ public void supply(Consumer consumer) { this.valueButton = new ButtonWidget(0, 0, 75, 20, optionName, button -> { PFMOptionListWidget.this.parent.focusedConfigOption = configOption; - PFMOptionListWidget.this.newConfigValues.put(configOption, !PFMOptionListWidget.this.newConfigValues.get(configOption)); + PFMOptionListWidget.this.newConfigValues.put(configOption, !(Boolean)PFMOptionListWidget.this.newConfigValues.get(configOption)); hasChanges = !hasChanges; PFMOptionListWidget.this.hasChanges.set(index, hasChanges); }, this.supplier); @@ -197,7 +225,7 @@ public void render(MatrixStack matrices, int index, int y, int x, int entryWidth this.resetButton.render(matrices, mouseX, mouseY, tickDelta); this.valueButton.x = x + 105; this.valueButton.y = y; - this.valueButton.setMessage(PFMOptionListWidget.this.newConfigValues.get(configOption) ? ScreenTexts.YES : ScreenTexts.NO); + this.valueButton.setMessage(((Boolean)PFMOptionListWidget.this.newConfigValues.get(configOption)) ? ScreenTexts.YES : ScreenTexts.NO); this.valueButton.active = this.configOption.getSide() != Side.SERVER || !PFMConfigScreen.isOnServer; this.valueButton.render(matrices, mouseX, mouseY, tickDelta); } @@ -224,6 +252,358 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { public boolean mouseReleased(double mouseX, double mouseY, int button) { return this.valueButton.mouseReleased(mouseX, mouseY, button) || this.resetButton.mouseReleased(mouseX, mouseY, button); } + + @Override + public void resetValue() { + PFMOptionListWidget.this.newConfigValues.put(configOption, configOption.getDefaultValue()); + hasChanges = true; + PFMOptionListWidget.this.hasChanges.set(index, true); + } + } + + @Environment(value=EnvType.CLIENT) + public class StringEntry + extends Entry { + private final StringConfigOption configOption; + private final Text optionName; + private final TextFieldWidget stringField; + private final ButtonWidget resetButton; + + private final ButtonWidget.TooltipSupplier supplier; + int index; + boolean hasChanges = false; + StringEntry(final StringConfigOption configOption, final Text optionName, int index) { + this.configOption = configOption; + this.optionName = optionName; + this.index = index; + this.supplier = new ButtonWidget.TooltipSupplier() { + final MutableText sideText = configOption.getSide() == Side.CLIENT ? new TranslatableText("pfm.option.client").setStyle(Style.EMPTY.withItalic(false).withBold(true).withColor(0xf77f34)) : new TranslatableText("pfm.option.server").setStyle((Style.EMPTY.withItalic(false).withBold(true).withColor(0xf77f34))); + final MutableText styledTooltip = ((MutableText)configOption.getToolTip()).setStyle(Style.EMPTY.withItalic(true)); + final MutableText combinedText = new LiteralText("").append(sideText).append(new LiteralText("\n")).append(styledTooltip); + @Override + public void onTooltip(ButtonWidget button, MatrixStack matrices, int mouseX, int mouseY) { + PFMOptionListWidget.this.parent.renderOrderedTooltip(matrices, PFMOptionListWidget.this.client.textRenderer.wrapLines(combinedText, Math.max(PFMOptionListWidget.this.width / 2 - 43, 170)), mouseX, mouseY); + } + @Override + public void supply(Consumer consumer) { + consumer.accept(combinedText); + ButtonWidget.TooltipSupplier.super.supply(consumer); + } + }; + + this.stringField = new TextFieldWidget(PFMOptionListWidget.this.client.textRenderer, 0, 0, 85, 20, new LiteralText(configOption.getValue())); + + this.stringField.setChangedListener(newValue -> { + if (newValue.isEmpty()) { + return; + } + PFMOptionListWidget.this.newConfigValues.put(configOption, newValue); + }); + this.resetButton = new ButtonWidget(0, 0, 50, 20, new TranslatableText("controls.reset"), button -> { + this.stringField.setText(configOption.getDefaultValue()); + PFMOptionListWidget.this.newConfigValues.put(configOption, configOption.getDefaultValue()); + hasChanges = true; + PFMOptionListWidget.this.hasChanges.set(index, true); + }){ + + @Override + protected MutableText getNarrationMessage() { + return new TranslatableText("narrator.controls.reset", optionName); + } + }; + } + + @Override + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + if (this.stringField.keyPressed(keyCode, scanCode, modifiers) || this.stringField.isActive()) { + return true; + } + return super.keyPressed(keyCode, scanCode, modifiers); + } + + @Override + public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + PFMOptionListWidget.this.client.textRenderer.draw(matrices, this.optionName, (float)(x + 90 - PFMOptionListWidget.this.maxKeyNameLength), (float)(y + entryHeight / 2 - PFMOptionListWidget.this.client.textRenderer.fontHeight / 2), 0xFFFFFF); + this.resetButton.x = x + 190; + this.resetButton.y = y; + this.resetButton.active = this.configOption.getSide() == Side.SERVER ? !PFMConfigScreen.isOnServer && !(this.configOption.getDefaultValue() == PFMOptionListWidget.this.newConfigValues.get(configOption)) : !(this.configOption.getDefaultValue() == PFMOptionListWidget.this.newConfigValues.get(configOption));; + this.resetButton.render(matrices, mouseX, mouseY, tickDelta); + this.stringField.x = x + 95; + this.stringField.y = y; + this.stringField.active = this.configOption.getSide() != Side.SERVER || !PFMConfigScreen.isOnServer; + this.stringField.render(matrices, mouseX, mouseY, tickDelta); + } + + @Override + public List children() { + return ImmutableList.of(this.stringField, this.resetButton); + } + + @Override + public List selectableChildren() { + return ImmutableList.of(this.stringField, this.resetButton); + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (this.stringField.mouseClicked(mouseX, mouseY, button)) { + return true; + } + return this.resetButton.mouseClicked(mouseX, mouseY, button); + } + + @Override + public boolean mouseReleased(double mouseX, double mouseY, int button) { + return this.stringField.mouseReleased(mouseX, mouseY, button) || this.resetButton.mouseReleased(mouseX, mouseY, button); + } + + @Override + public void resetValue() { + PFMOptionListWidget.this.newConfigValues.put(configOption, configOption.getDefaultValue()); + hasChanges = true; + PFMOptionListWidget.this.hasChanges.set(index, true); + } + } + + @Environment(value=EnvType.CLIENT) + public class StringArrayEntry + extends Entry { + private final StringArrayConfigOption configOption; + private final Text optionName; + private final List stringFields; + private final ButtonWidget resetButton; + private final ButtonWidget addButton; + + private final ButtonWidget.TooltipSupplier supplier; + int index; + boolean hasChanges = false; + int currentFieldIndx = 0; + StringArrayEntry(final StringArrayConfigOption configOption, final Text optionName, int index) { + this.configOption = configOption; + this.optionName = optionName; + this.index = index; + this.supplier = new ButtonWidget.TooltipSupplier() { + final MutableText sideText = configOption.getSide() == Side.CLIENT ? new TranslatableText("pfm.option.client").setStyle(Style.EMPTY.withItalic(false).withBold(true).withColor(0xf77f34)) : new TranslatableText("pfm.option.server").setStyle((Style.EMPTY.withItalic(false).withBold(true).withColor(0xf77f34))); + final MutableText styledTooltip = ((MutableText)configOption.getToolTip()).setStyle(Style.EMPTY.withItalic(true)); + final MutableText combinedText = new LiteralText("").append(sideText).append(new LiteralText("\n")).append(styledTooltip); + @Override + public void onTooltip(ButtonWidget button, MatrixStack matrices, int mouseX, int mouseY) { + PFMOptionListWidget.this.parent.renderOrderedTooltip(matrices, PFMOptionListWidget.this.client.textRenderer.wrapLines(combinedText, Math.max(PFMOptionListWidget.this.width / 2 - 43, 170)), mouseX, mouseY); + } + @Override + public void supply(Consumer consumer) { + consumer.accept(combinedText); + ButtonWidget.TooltipSupplier.super.supply(consumer); + } + }; + stringFields = new ArrayList<>(configOption.size()); + configOption.forEach(currentValue -> { + TextFieldWidget widget = new TextFieldWidget(PFMOptionListWidget.this.client.textRenderer, 0, 20*currentFieldIndx, 85, 20, new LiteralText(currentValue)); + widget.setChangedListener(newValue -> { + List stringList = PFMOptionListWidget.this.newConfigValues.get(configOption) == null ? new ArrayList<>() : (List) PFMOptionListWidget.this.newConfigValues.get(configOption); + if (stringList.contains(widget.getText())) + stringList.set(stringList.indexOf(widget.getText()), newValue); + else + stringList.add(newValue); + }); + stringFields.add(widget); + addEntry(new CategoryEntry(new LiteralText(""))); + currentFieldIndx++; + }); + this.resetButton = new ButtonWidget(0, 0, 50, 20, new TranslatableText("controls.reset"), button -> { + stringFields.clear(); + PFMOptionListWidget.this.newConfigValues.put(configOption, new ArrayList<>()); + hasChanges = true; + PFMOptionListWidget.this.hasChanges.set(index, true); + }){ + + @Override + protected MutableText getNarrationMessage() { + return new TranslatableText("narrator.controls.reset", optionName); + } + }; + this.addButton = new ButtonWidget(0, 0, 20, 20, new LiteralText("+"), button -> { + TextFieldWidget widget = new TextFieldWidget(PFMOptionListWidget.this.client.textRenderer, 0, 20*currentFieldIndx, 85, 20, new LiteralText("")); + widget.setChangedListener(newValue -> { + List stringList = PFMOptionListWidget.this.newConfigValues.get(configOption) == null ? new ArrayList<>() : (List) PFMOptionListWidget.this.newConfigValues.get(configOption); + if (stringList.contains(widget.getText())) + stringList.set(stringList.indexOf(widget.getText()), newValue); + else + stringList.add(newValue); + }); + stringFields.add(widget); + addEntry(new CategoryEntry(new LiteralText(""))); + currentFieldIndx++; + }){ + + @Override + protected MutableText getNarrationMessage() { + return new LiteralText("+"); + } + }; + } + + @Override + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + if (this.stringFields.stream().anyMatch(textFieldWidget -> textFieldWidget.keyPressed(keyCode, scanCode, modifiers)) || this.stringFields.stream().anyMatch(TextFieldWidget::isActive)) { + return true; + } + return super.keyPressed(keyCode, scanCode, modifiers); + } + + @Override + public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + PFMOptionListWidget.this.client.textRenderer.draw(matrices, this.optionName, (float)(x + 90 - PFMOptionListWidget.this.maxKeyNameLength), (float)(y + entryHeight / 2 - PFMOptionListWidget.this.client.textRenderer.fontHeight / 2), 0xFFFFFF); + this.resetButton.x = x + 190; + this.resetButton.y = y; + this.resetButton.active = this.configOption.getSide() == Side.SERVER ? !PFMConfigScreen.isOnServer && !(this.configOption.getDefaultValue() == PFMOptionListWidget.this.newConfigValues.get(configOption)) : !(this.configOption.getDefaultValue() == PFMOptionListWidget.this.newConfigValues.get(configOption));; + this.resetButton.render(matrices, mouseX, mouseY, tickDelta); + + this.addButton.x = x + 120; + this.addButton.y = y; + this.addButton.active = this.configOption.getSide() == Side.SERVER; + this.addButton.render(matrices, mouseX, mouseY, tickDelta); + int indx = 0; + for (TextFieldWidget widget : stringFields) { + widget.x = x; + widget.y = y + (20*indx); + widget.render(matrices, mouseX, mouseY, tickDelta); + widget.active = this.configOption.getSide() != Side.SERVER || !PFMConfigScreen.isOnServer; + indx++; + } + } + + @Override + public List children() { + List children = new ArrayList<>(this.stringFields.size()+1); + children.addAll(stringFields); + children.add(this.resetButton); + children.add(this.addButton); + return children; + } + + @Override + public List selectableChildren() { + List children = new ArrayList<>(this.stringFields.size()+1); + children.addAll(stringFields); + children.add(this.resetButton); + children.add(this.addButton); + return children; + } + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (this.stringFields.stream().anyMatch(textFieldWidget -> textFieldWidget.mouseClicked(mouseX, mouseY, button))) { + return true; + } + return this.resetButton.mouseClicked(mouseX, mouseY, button) || this.addButton.mouseClicked(mouseX, mouseY, button); + } + + @Override + public boolean mouseReleased(double mouseX, double mouseY, int button) { + return this.stringFields.stream().anyMatch(textFieldWidget -> textFieldWidget.mouseReleased(mouseX, mouseY, button)) || this.resetButton.mouseReleased(mouseX, mouseY, button) || this.addButton.mouseClicked(mouseX, mouseY, button); + } + + @Override + public void resetValue() { + PFMOptionListWidget.this.newConfigValues.put(configOption, new ArrayList<>()); + hasChanges = true; + PFMOptionListWidget.this.hasChanges.set(index, true); + } + } + + @Environment(value=EnvType.CLIENT) + public class ListEntry + extends Entry { + private final ListConfigOption configOption; + private final Text optionName; + private final ButtonWidget resetButton; + int index; + private final List entryList; + boolean hasChanges = false; + ListEntry(final ListConfigOption configOptions, final Text optionName, int index) { + this.configOption = configOptions; + this.optionName = optionName; + this.index = index; + this.entryList = new ArrayList<>(configOptions.size()); + for (AbstractConfigOption option : configOptions) { + if (option.getType() == Boolean.class) { + entryList.add(new BooleanEntry((BooleanConfigOption) option, option.getTitle(), PFMOptionListWidget.this.configOptionToIndexForHasChanges.get(option))); + } + else if (option.getType() == String.class) { + entryList.add(new StringEntry((StringConfigOption) option, option.getTitle(), PFMOptionListWidget.this.configOptionToIndexForHasChanges.get(option))); + } + else if (option.getType() == String[].class) { + entryList.add(new StringArrayEntry((StringArrayConfigOption) option, option.getTitle(), PFMOptionListWidget.this.configOptionToIndexForHasChanges.get(option))); + } + } + this.resetButton = new ButtonWidget(0, 0, 50, 20, new TranslatableText("controls.reset"), button -> { + + hasChanges = true; + PFMOptionListWidget.this.hasChanges.set(index, true); + }){ + @Override + protected MutableText getNarrationMessage() { + return new TranslatableText("narrator.controls.reset", optionName); + } + }; + } + + @Override + public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + PFMOptionListWidget.this.client.textRenderer.draw(matrices, this.optionName, (float)(x + 90 - PFMOptionListWidget.this.maxKeyNameLength), (float)(y + entryHeight / 2 - PFMOptionListWidget.this.client.textRenderer.fontHeight / 2), 0xFFFFFF); + this.resetButton.x = x + 190; + this.resetButton.y = y; + this.resetButton.active = this.configOption.getSide() == Side.SERVER ? !PFMConfigScreen.isOnServer && !(this.configOption.getDefaultValue() == PFMOptionListWidget.this.newConfigValues.get(configOption)) : !(this.configOption.getDefaultValue() == PFMOptionListWidget.this.newConfigValues.get(configOption));; + this.resetButton.render(matrices, mouseX, mouseY, tickDelta); + for (Entry entry : entryList) { + entry.render(matrices, index, y, x, entryWidth, entryHeight, mouseX, mouseY, hovered, tickDelta); + } + } + + @Override + public List children() { + List children = new ArrayList<>(this.entryList.size()); + for (Entry entry : entryList) { + children.addAll(entry.children()); + } + children.add(this.resetButton); + return children; + } + + @Override + public List selectableChildren() { + List children = new ArrayList<>(this.entryList.size()); + for (Entry entry : entryList) { + children.addAll(entry.selectableChildren()); + } + children.add(this.resetButton); + return children; + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + for (Entry entry : entryList) { + if (entry.mouseClicked(mouseX, mouseY, button)) + return true; + } + return this.resetButton.mouseClicked(mouseX, mouseY, button); + } + + @Override + public boolean mouseReleased(double mouseX, double mouseY, int button) { + for (Entry entry : entryList) { + if (entry.mouseReleased(mouseX, mouseY, button)) + return true; + } + return this.resetButton.mouseReleased(mouseX, mouseY, button); + } + + @Override + public void resetValue() { + for (Entry entry : entryList) { + entry.resetValue(); + } + } } @Environment(value=EnvType.CLIENT) @@ -287,10 +667,31 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { public boolean mouseReleased(double mouseX, double mouseY, int button) { return this.button.mouseReleased(mouseX, mouseY, button); } + + @Override + public void resetValue() { + } } @Environment(value=EnvType.CLIENT) - public static abstract class Entry extends ElementListWidget.Entry { + public static abstract class Entry extends ElementListWidget.Entry implements Selectable { + public abstract void resetValue(); + @Override + public SelectionType getType() { + return SelectionType.NONE; + } + + public abstract List selectableChildren(); + + @Override + public void appendNarrations(NarrationMessageBuilder narrationMessageBuilder) { + + } + + @Override + public boolean isNarratable() { + return false; + } } } diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/PaladinFurnitureModConfig.java b/common/src/main/java/com/unlikepaladin/pfm/config/PaladinFurnitureModConfig.java index 42f11b5ba..fa33c92b6 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/config/PaladinFurnitureModConfig.java +++ b/common/src/main/java/com/unlikepaladin/pfm/config/PaladinFurnitureModConfig.java @@ -3,9 +3,7 @@ import com.google.gson.*; import com.google.gson.reflect.TypeToken; import com.unlikepaladin.pfm.PaladinFurnitureMod; -import com.unlikepaladin.pfm.config.option.AbstractConfigOption; -import com.unlikepaladin.pfm.config.option.BooleanConfigOption; -import com.unlikepaladin.pfm.config.option.Side; +import com.unlikepaladin.pfm.config.option.*; import net.minecraft.text.TranslatableText; import java.io.*; @@ -42,6 +40,7 @@ public PaladinFurnitureModConfig(Path propertiesPath) { mobsSitOnChairs = new BooleanConfigOption(new TranslatableText("pfm.option.mobsSitOnChairs"), new TranslatableText("pfm.option.mobsSitOnChairs.tooltip"), GAMEPLAY_OPTIONS, true, Side.SERVER), renderImmersivePortalsMirrors = new BooleanConfigOption(new TranslatableText("pfm.option.renderImmersivePortalsMirrors"), new TranslatableText("pfm.option.renderImmersivePortalsMirrors.tooltip"), GAMEPLAY_OPTIONS, true, Side.CLIENT), spawnImmersivePortalsMirror = new BooleanConfigOption(new TranslatableText("pfm.option.spawnImmersivePortalsMirror"), new TranslatableText("pfm.option.spawnImmersivePortalsMirror.tooltip"), GAMEPLAY_OPTIONS, true, Side.SERVER) + // variantBlacklist = new StringArrayConfigOption(new TranslatableText("pfm.option.variantBlacklist"), new TranslatableText("pfm.option.variantBlacklist.tooltip"), GAMEPLAY_OPTIONS, new ArrayList<>(), Side.SERVER) alas it is not ready yet ); this.propertiesPath = propertiesPath.resolve("pfm.json"); this.directoryPath = propertiesPath; @@ -127,6 +126,7 @@ public boolean doImmersivePortalsMirrorsSpawn() { private BooleanConfigOption mobsSitOnChairs; private BooleanConfigOption renderImmersivePortalsMirrors; private BooleanConfigOption spawnImmersivePortalsMirror; +// private StringArrayConfigOption variantBlacklist; public Path getPath() { @@ -165,7 +165,17 @@ public void load() throws IOException { mobsSitOnChairs.setValue(getFromJsonElement(config.get("mobsSitOnChairs"), false)); renderImmersivePortalsMirrors.setValue(getFromJsonElement(config.get("renderImmersivePortalsMirrors"), true)); spawnImmersivePortalsMirror.setValue(getFromJsonElement(config.get("spawnImmersivePortalsMirror"), true)); - + /* JsonObject object = getFromJsonElement(config.get("variantBlacklist"), new JsonObject()); + if (object != null && object.isJsonArray()) { + JsonArray variantBlackListArray = object.getAsJsonArray(); + + // Extract strings from the array + List stringList = new ArrayList<>(); + for (JsonElement arrayElement : variantBlackListArray) { + stringList.add(arrayElement.getAsString()); + } + variantBlacklist.addAll(stringList); + }*/ for (String key : options.keySet()) { if (!config.has(key.replace("pfm.option.", ""))){ PaladinFurnitureMod.GENERAL_LOGGER.warn("Missing Config Option: " + key.replace("pfm.option.", "") + ", resetting to default value."); @@ -239,9 +249,17 @@ public void save() throws IOException { object.addProperty("mobsSitOnChairs", mobsSitOnChairs.getValue()); object.addProperty("renderImmersivePortalsMirrors", renderImmersivePortalsMirrors.getValue()); object.addProperty("spawnImmersivePortalsMirror", spawnImmersivePortalsMirror.getValue()); - + // object.add("variantBlacklist", toJsonElement(variantBlacklist.getValue())); try (FileWriter writer = new FileWriter(propertiesPath.toString())) { GSON.toJson(object, writer); } } + + public JsonElement toJsonElement(String[] stringArray) { + JsonArray jsonArray = new JsonArray(); + for (String value : stringArray) { + jsonArray.add(new JsonPrimitive(value)); + } + return jsonArray; + } } diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/option/AbstractConfigOption.java b/common/src/main/java/com/unlikepaladin/pfm/config/option/AbstractConfigOption.java index 400c82cac..1d4f9d240 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/config/option/AbstractConfigOption.java +++ b/common/src/main/java/com/unlikepaladin/pfm/config/option/AbstractConfigOption.java @@ -15,9 +15,12 @@ import java.io.IOException; import java.util.Objects; -public abstract class AbstractConfigOption implements Comparable { +public interface AbstractConfigOption extends Comparable { public static final byte NULL_TYPE = 0; public static final byte BOOL_TYPE = 1; + public static final byte STRING_TYPE = 2; + public static final byte STRING_ARRAY_TYPE = 3; + public static final byte LIST_TYPE = 4; public abstract Text getTitle(); @@ -47,10 +50,6 @@ public static Side getSide(String string) { } return null; } - @Override - public String toString() { - return "{Type: " + getType() + ", Title: " + ((TranslatableText)getTitle()).getKey() + ", Category: " + getCategory() + ", Value: " + getValue() + ", Side:" + getSide() + "}"; - } public abstract void write(DataOutput output) throws IOException; @@ -87,8 +86,12 @@ public static AbstractConfigOption readConfigOption(PacketByteBuf packetByteBuf, } } + public default String asString() { + return "{Type: " + getType() + ", Title: " + ((TranslatableText)getTitle()).getKey() + ", Category: " + getCategory() + ", Value: " + getValue() + ", Side:" + getSide() + "}"; + } + @Override - public int compareTo(@NotNull String o) { + public default int compareTo(@NotNull String o) { return this.getCategory().compareTo(o); } } diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/option/BooleanConfigOption.java b/common/src/main/java/com/unlikepaladin/pfm/config/option/BooleanConfigOption.java index 16c3ea68c..cb305d404 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/config/option/BooleanConfigOption.java +++ b/common/src/main/java/com/unlikepaladin/pfm/config/option/BooleanConfigOption.java @@ -11,25 +11,25 @@ import java.io.DataOutput; import java.io.IOException; -public class BooleanConfigOption extends AbstractConfigOption{ +public class BooleanConfigOption implements AbstractConfigOption{ public static final ConfigOptionType TYPE = new ConfigOptionType<>() { - public BooleanConfigOption read(DataInput dataInput, int i, ConfigSizeTracker nbtTagSizeTracker) throws IOException { - nbtTagSizeTracker.add(2400L); + public BooleanConfigOption read(DataInput dataInput, int i, ConfigSizeTracker sizeTracker) throws IOException { + sizeTracker.add(2400L); String title = dataInput.readUTF(); String tooltip = dataInput.readUTF(); String category = dataInput.readUTF(); boolean value = dataInput.readBoolean(); - Side side = getSide(dataInput.readUTF()); - nbtTagSizeTracker.add(224L + 16L * title.length()); - nbtTagSizeTracker.add(224L + 16L * tooltip.length()); - nbtTagSizeTracker.add(224L + 16L * category.length()); - nbtTagSizeTracker.add(64L); + Side side = AbstractConfigOption.getSide(dataInput.readUTF()); + sizeTracker.add(224L + 16L * title.length()); + sizeTracker.add(224L + 16L * tooltip.length()); + sizeTracker.add(224L + 16L * category.length()); + sizeTracker.add(64L); BooleanConfigOption booleanConfigOption = new BooleanConfigOption(new TranslatableText(title), new TranslatableText(tooltip), category, value, side); return booleanConfigOption; } public String getCrashReportName() { - return "END"; + return "BOOL-OPTION"; } public boolean isImmutable() { diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigIO.java b/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigIO.java index 379d14b6c..d01b483fd 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigIO.java +++ b/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigIO.java @@ -8,6 +8,7 @@ import org.jetbrains.annotations.Nullable; import java.io.*; +import java.util.ArrayList; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; @@ -73,7 +74,7 @@ public static AbstractConfigOption read(DataInput input, ConfigSizeTracker track protected static void write(AbstractConfigOption element, DataOutput output) throws IOException { output.writeByte(element.getConfigType()); - if (element.getType() != Boolean.class) { + if (element.getType() != Boolean.class && element.getType() != ArrayList.class && element.getType() != String.class && element.getType() != String[].class) { PaladinFurnitureMod.GENERAL_LOGGER.warn("Unsupported Type: " + element.getType()); return; } diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigOptionType.java b/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigOptionType.java index b5d940c0b..24a205920 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigOptionType.java +++ b/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigOptionType.java @@ -28,7 +28,7 @@ public String getCrashReportName() { } @Override - public /* synthetic */ NullConfigOption read(DataInput input, int depth, ConfigSizeTracker tracker) throws IOException { + public NullConfigOption read(DataInput input, int depth, ConfigSizeTracker tracker) throws IOException { throw new IllegalArgumentException("Invalid Config id: " + type); } }; diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigOptionTypes.java b/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigOptionTypes.java index a80d04868..86332d701 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigOptionTypes.java +++ b/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigOptionTypes.java @@ -5,7 +5,7 @@ public class ConfigOptionTypes { // - private static final ConfigOptionType[] VALUES = new ConfigOptionType[]{NullConfigOption.TYPE, BooleanConfigOption.TYPE}; + private static final ConfigOptionType[] VALUES = new ConfigOptionType[]{NullConfigOption.TYPE, BooleanConfigOption.TYPE, StringConfigOption.TYPE, StringArrayConfigOption.TYPE, ListConfigOption.TYPE}; public static ConfigOptionType byId(int id) { if (id < 0 || id >= VALUES.length) { diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/option/ListConfigOption.java b/common/src/main/java/com/unlikepaladin/pfm/config/option/ListConfigOption.java new file mode 100644 index 000000000..b1b11e493 --- /dev/null +++ b/common/src/main/java/com/unlikepaladin/pfm/config/option/ListConfigOption.java @@ -0,0 +1,180 @@ +package com.unlikepaladin.pfm.config.option; + +import com.google.common.collect.Lists; +import net.minecraft.nbt.NbtElement; +import net.minecraft.text.Text; +import net.minecraft.text.TranslatableText; +import org.jetbrains.annotations.NotNull; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.AbstractList; +import java.util.ArrayList; + +public class ListConfigOption extends AbstractList> implements AbstractConfigOption { + public static final ConfigOptionType TYPE = new ConfigOptionType(){ + + @Override + public ListConfigOption read(DataInput dataInput, int i, ConfigSizeTracker sizeTracker) throws IOException { + String title = dataInput.readUTF(); + String tooltip = dataInput.readUTF(); + String category = dataInput.readUTF(); + sizeTracker.add(224L + 16L * title.length()); + sizeTracker.add(224L + 16L * tooltip.length()); + sizeTracker.add(224L + 16L * category.length()); + sizeTracker.add(64L); + sizeTracker.add(296L); + if (i > 512) { + throw new RuntimeException("Tried to read option with too high complexity, depth > 512"); + } + byte type = dataInput.readByte(); + int size = dataInput.readInt(); + if (type == 0 && size > 0) { + throw new RuntimeException("Missing type on Option List"); + } + sizeTracker.add(32L * (long)size); + ConfigOptionType optionType = ConfigOptionTypes.byId(type); + ArrayList> list = Lists.newArrayListWithCapacity(size); + for (int index = 0; index < size; ++index) { + list.add(optionType.read(dataInput, i + 1, sizeTracker)); + } + Side side = AbstractConfigOption.getSide(dataInput.readUTF()); + return new ListConfigOption(new TranslatableText(title), new TranslatableText(tooltip), category, list, type, side); + } + + @Override + public String getCrashReportName() { + return "LIST-OPTION"; + } + }; + + private final Text title; + private final Text tooltip; + private final String category; + private ArrayList> value; + private byte type; + private final Side side; + public ListConfigOption(Text title, Text tooltip, String category, ArrayList> value, byte type, Side side) { + this.title = title; + this.category = category; + this.tooltip = tooltip; + this.value = value; + this.type = type; + this.side = side; + } + + @Override + public Text getTitle() { + return title; + } + + @Override + public String getCategory() { + return category; + } + + @Override + public Object getValue() { + return value; + } + + @Override + public Object getDefaultValue() { + return value; + } + + @Override + public Text getToolTip() { + return tooltip; + } + + @Override + public void setValue(Object value) { + if (value instanceof ArrayList && !((ArrayList) value).isEmpty() && ((ArrayList) value).get(0) instanceof AbstractConfigOption) + this.value = (ArrayList>) value; + } + + @Override + public Class getType() { + return ArrayList.class; + } + + @Override + public boolean isDefault() { + return value.stream().allMatch(AbstractConfigOption::isDefault); + } + + @Override + public Side getSide() { + return side; + } + + @Override + public byte getConfigType() { + return LIST_TYPE; + } + + @Override + public void write(DataOutput output) throws IOException { + output.writeUTF(((TranslatableText)title).getKey()); + output.writeUTF(((TranslatableText)tooltip).getKey()); + output.writeUTF(category); + this.type = this.value.isEmpty() ? (byte)0 : this.value.get(0).getConfigType(); + output.writeByte(this.type); + output.writeInt(this.value.size()); + for (AbstractConfigOption configOption : this.value) { + configOption.write(output); + } + output.writeUTF(side.asString()); + } + + @Override + public AbstractConfigOption get(int index) { + return value.get(index); + } + + @Override + public int size() { + return value.size(); + } + + @Override + public AbstractConfigOption set(int index, AbstractConfigOption element) { + if (index < value.size() && index >= 0 && value.get(index).getConfigType() == element.getConfigType()) { + return value.set(index, element); + } + return null; + } + + public void setElementValue(int index, Object v) { + if (index < value.size() && index >= 0 && value.get(index).getClass() == v.getClass()) { + ((AbstractConfigOption)value.get(index)).setValue(v); + } + } + + public Object getElementValue(int index) { + if (index < value.size() && index >= 0) { + return ((AbstractConfigOption)value.get(index)).getValue(); + } + return NullConfigOption.INSTANCE.getValue(); + } + + @NotNull + @Override + public T @NotNull [] toArray(T @NotNull [] a) { + return value.toArray(a); + } + + @Override + public AbstractConfigOption remove(int index) { + return value.remove(index); + } + + @Override + public int compareTo(@NotNull Object o) { + if (o instanceof String) + return compareTo((String) o); + return 0; + } +} diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/option/NullConfigOption.java b/common/src/main/java/com/unlikepaladin/pfm/config/option/NullConfigOption.java index b8fe5ed9e..977e645e0 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/config/option/NullConfigOption.java +++ b/common/src/main/java/com/unlikepaladin/pfm/config/option/NullConfigOption.java @@ -8,7 +8,7 @@ import java.io.DataOutput; import java.io.IOException; -public class NullConfigOption extends AbstractConfigOption{ +public class NullConfigOption implements AbstractConfigOption{ public static final ConfigOptionType TYPE = new ConfigOptionType(){ public NullConfigOption read(DataInput dataInput, int i, ConfigSizeTracker nbtTagSizeTracker, byte n) { diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/option/StringArrayConfigOption.java b/common/src/main/java/com/unlikepaladin/pfm/config/option/StringArrayConfigOption.java new file mode 100644 index 000000000..94aba03bf --- /dev/null +++ b/common/src/main/java/com/unlikepaladin/pfm/config/option/StringArrayConfigOption.java @@ -0,0 +1,242 @@ +package com.unlikepaladin.pfm.config.option; + + +import net.minecraft.text.Text; +import net.minecraft.text.TranslatableText; +import org.jetbrains.annotations.NotNull; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.*; +import java.util.function.Consumer; +import java.util.function.IntFunction; +import java.util.function.Predicate; +import java.util.function.UnaryOperator; +import java.util.stream.Stream; + +public class StringArrayConfigOption extends AbstractList implements AbstractConfigOption { + public static final ConfigOptionType TYPE = new ConfigOptionType<>() { + public StringArrayConfigOption read(DataInput dataInput, int i, ConfigSizeTracker sizeTracker) throws IOException { + sizeTracker.add(2400L); + String title = dataInput.readUTF(); + String tooltip = dataInput.readUTF(); + String category = dataInput.readUTF(); + int size = dataInput.readInt(); + sizeTracker.add(32L * (long)size); + List strings = new ArrayList<>(size); + for (int index = 0; index < size; ++index) { + strings.set(index, dataInput.readUTF()); + } + Side side = AbstractConfigOption.getSide(dataInput.readUTF()); + sizeTracker.add(224L + 16L * title.length()); + sizeTracker.add(224L + 16L * tooltip.length()); + sizeTracker.add(224L + 16L * category.length()); + sizeTracker.add(64L); + return new StringArrayConfigOption(new TranslatableText(title), new TranslatableText(tooltip), category, strings, side); + } + + public String getCrashReportName() { + return "STRING-OPTION"; + } + + public boolean isImmutable() { + return true; + } + }; + private final Text title; + private final Text tooltip; + private final String category; + private List value; + private final String[] defaultValue; + + private final Side side; + private int size; + public StringArrayConfigOption(Text title, Text tooltip, String category, List value, Side side) { + this.title = title; + this.category = category; + this.tooltip = tooltip; + this.value = value; + this.defaultValue = new String[1]; + this.side = side; + } + + @Override + public Text getTitle() { + return title; + } + + @Override + public String getCategory() { + return category; + } + + @Override + public String[] getValue() { + return value.toArray(new String[0]); + } + + @Override + public String[] getDefaultValue() { + return defaultValue; + } + + @Override + public Text getToolTip() { + return tooltip; + } + + @Override + public void setValue(String[] value) { + this.value = List.of(value); + } + + @Override + public Class getType() { + return String[].class; + } + + @Override + public boolean isDefault() { + return value.equals(List.of(defaultValue)); + } + + @Override + public Side getSide() { + return side; + } + + @Override + public byte getConfigType() { + return STRING_ARRAY_TYPE; + } + + @Override + public void write(DataOutput output) throws IOException { + output.writeUTF(((TranslatableText)title).getKey()); + output.writeUTF(((TranslatableText)tooltip).getKey()); + output.writeUTF(category); + output.writeInt(this.value.size()); + for (String i : this.value) { + output.writeUTF(i); + } + output.writeUTF(side.asString()); + } + + @Override + public String get(int index) { + if (index < value.size() && index >= 0) + return value.get(index); + return ""; + } + + @Override + public String set(int index, String element) { + if (index < value.size() && index >= 0) { + return value.set(index, element); + } + return ""; + } + + + @Override + public int size() { + return size; + } + + @Override + public boolean add(String element) { + return value.add(element); + } + + @Override + public boolean remove(Object o) { + return value.remove(o); + } + + @Override + public String remove(int index) { + return value.remove(index); + } + + @Override + public boolean removeAll(@NotNull Collection c) { + return value.removeAll(c); + } + + @Override + public boolean removeIf(Predicate filter) { + return value.removeIf(filter); + } + + @Override + public void replaceAll(UnaryOperator operator) { + value.replaceAll(operator); + } + + @Override + public Stream stream() { + return value.stream(); + } + + @NotNull + @Override + public T[] toArray(@NotNull T[] a) { + return value.toArray(a); + } + + @Override + public void forEach(Consumer action) { + value.forEach(action); + } + + @Override + public void sort(Comparator c) { + value.sort(c); + } + + @Override + public Stream parallelStream() { + return value.parallelStream(); + } + + @Override + public Iterator iterator() { + return value.iterator(); + } + + @Override + public int hashCode() { + return value.hashCode(); + } + + @Override + public int lastIndexOf(Object o) { + return value.lastIndexOf(o); + } + + @Override + public boolean addAll(@NotNull Collection c) { + return value.addAll(c); + } + + @Override + public boolean addAll(int index, Collection c) { + return value.addAll(index, c); + } + + @Override + public int indexOf(Object o) { + return value.indexOf(o); + } + + @Override + public boolean contains(Object o) { + return value.contains(o); + } + + @Override + public T[] toArray(IntFunction generator) { + return value.toArray(generator); + } +} diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/option/StringConfigOption.java b/common/src/main/java/com/unlikepaladin/pfm/config/option/StringConfigOption.java new file mode 100644 index 000000000..86414f91c --- /dev/null +++ b/common/src/main/java/com/unlikepaladin/pfm/config/option/StringConfigOption.java @@ -0,0 +1,112 @@ +package com.unlikepaladin.pfm.config.option; + + +import net.minecraft.text.Text; +import net.minecraft.text.TranslatableText; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.Objects; + +public class StringConfigOption implements AbstractConfigOption { + public static final ConfigOptionType TYPE = new ConfigOptionType<>() { + public StringConfigOption read(DataInput dataInput, int i, ConfigSizeTracker sizeTracker) throws IOException { + sizeTracker.add(2400L); + String title = dataInput.readUTF(); + String tooltip = dataInput.readUTF(); + String category = dataInput.readUTF(); + String value = dataInput.readUTF(); + Side side = AbstractConfigOption.getSide(dataInput.readUTF()); + sizeTracker.add(224L + 16L * title.length()); + sizeTracker.add(224L + 16L * tooltip.length()); + sizeTracker.add(224L + 16L * category.length()); + sizeTracker.add(224L + 16L * value.length()); + sizeTracker.add(64L); + StringConfigOption booleanConfigOption = new StringConfigOption(new TranslatableText(title), new TranslatableText(tooltip), category, value, side); + return booleanConfigOption; + } + + public String getCrashReportName() { + return "STRING-OPTION"; + } + + public boolean isImmutable() { + return true; + } + }; + private final Text title; + private final Text tooltip; + private final String category; + private String value; + private final String defaultValue; + + private final Side side; + public StringConfigOption(Text title, Text tooltip, String category, String value, Side side) { + this.title = title; + this.category = category; + this.tooltip = tooltip; + this.value = value; + this.defaultValue = value; + this.side = side; + } + + @Override + public Text getTitle() { + return title; + } + + @Override + public String getCategory() { + return category; + } + + @Override + public String getValue() { + return value; + } + + @Override + public String getDefaultValue() { + return defaultValue; + } + + @Override + public Text getToolTip() { + return tooltip; + } + + @Override + public void setValue(String value) { + this.value = value; + } + + @Override + public Class getType() { + return String.class; + } + + @Override + public boolean isDefault() { + return Objects.equals(value, defaultValue); + } + + @Override + public Side getSide() { + return side; + } + + @Override + public byte getConfigType() { + return STRING_TYPE; + } + + @Override + public void write(DataOutput output) throws IOException { + output.writeUTF(((TranslatableText)title).getKey()); + output.writeUTF(((TranslatableText)tooltip).getKey()); + output.writeUTF(category); + output.writeUTF(value); + output.writeUTF(side.asString()); + } +} diff --git a/common/src/main/java/com/unlikepaladin/pfm/registry/PFMItemGroup.java b/common/src/main/java/com/unlikepaladin/pfm/registry/PFMItemGroup.java new file mode 100644 index 000000000..fa33a7936 --- /dev/null +++ b/common/src/main/java/com/unlikepaladin/pfm/registry/PFMItemGroup.java @@ -0,0 +1,27 @@ +package com.unlikepaladin.pfm.registry; + +import com.unlikepaladin.pfm.blocks.BasicChairBlock; +import com.unlikepaladin.pfm.data.materials.WoodVariantRegistry; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemStack; +import net.minecraft.util.collection.DefaultedList; +import net.minecraft.util.registry.Registry; + +public abstract class PFMItemGroup extends ItemGroup { + public PFMItemGroup(int index, String id) { + super(index, id); + } + + @Override + public ItemStack createIcon() { + return PaladinFurnitureModBlocksItems.furnitureEntryMap.get(BasicChairBlock.class).getVariantToBlockMap().get(WoodVariantRegistry.OAK).asItem().getDefaultStack(); + } + + @Override + public void appendStacks(DefaultedList stacks) { + for (Item item : Registry.ITEM) { + item.appendStacks(this, stacks); + } + } +} From aa862ec44c4179f53f8fea5b09437949b494b8c9 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Sat, 17 Feb 2024 23:19:17 -0600 Subject: [PATCH 06/17] Added a tag to all furniture blocks, fixed freezer input/outputs not working correctly on Forge --- .../com/unlikepaladin/pfm/data/PFMTags.java | 1 + .../pfm/runtime/data/PFMTagProvider.java | 3 ++ .../forge/FreezerBlockEntityImpl.java | 46 ++++++++++++++++++- .../forge/MicrowaveBlockEntityImpl.java | 2 +- .../forge/FreezerBlockEntityBalm.java | 3 +- 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/unlikepaladin/pfm/data/PFMTags.java b/common/src/main/java/com/unlikepaladin/pfm/data/PFMTags.java index 02b1fa22b..9b96daf03 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/data/PFMTags.java +++ b/common/src/main/java/com/unlikepaladin/pfm/data/PFMTags.java @@ -7,6 +7,7 @@ public class PFMTags { public static Tag.Identified TUCKABLE_BLOCKS = createTag(new Identifier("pfm", "tuckable_blocks")); + public static Tag.Identified FURNITURE = createTag(new Identifier("pfm", "furniture")); @ExpectPlatform public static Tag.Identified createTag(Identifier identifier) { diff --git a/common/src/main/java/com/unlikepaladin/pfm/runtime/data/PFMTagProvider.java b/common/src/main/java/com/unlikepaladin/pfm/runtime/data/PFMTagProvider.java index 1af42f7ae..bbaaa1739 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/runtime/data/PFMTagProvider.java +++ b/common/src/main/java/com/unlikepaladin/pfm/runtime/data/PFMTagProvider.java @@ -221,6 +221,9 @@ protected void generateTags() { .add(stoneNaturalTables) .add(logTables); + getOrCreateTagBuilder(PFMTags.FURNITURE) + .add(PaladinFurnitureModBlocksItems.BLOCKS.toArray(Block[]::new)); + PaladinFurnitureMod.pfmModCompatibilities.forEach(PFMModCompatibility::generateTags); } diff --git a/forge/src/main/java/com/unlikepaladin/pfm/blocks/blockentities/forge/FreezerBlockEntityImpl.java b/forge/src/main/java/com/unlikepaladin/pfm/blocks/blockentities/forge/FreezerBlockEntityImpl.java index 9f84fb0b6..830976aa4 100644 --- a/forge/src/main/java/com/unlikepaladin/pfm/blocks/blockentities/forge/FreezerBlockEntityImpl.java +++ b/forge/src/main/java/com/unlikepaladin/pfm/blocks/blockentities/forge/FreezerBlockEntityImpl.java @@ -3,10 +3,52 @@ import com.unlikepaladin.pfm.PaladinFurnitureMod; import com.unlikepaladin.pfm.blocks.blockentities.FreezerBlockEntity; import com.unlikepaladin.pfm.compat.cookingforblockheads.forge.FreezerBlockEntityBalm; +import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.CapabilityManager; +import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.items.CapabilityItemHandler; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.IItemHandlerModifiable; +import net.minecraftforge.items.wrapper.SidedInvWrapper; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class FreezerBlockEntityImpl extends FreezerBlockEntity { + + private final LazyOptional[] handlers; + + public FreezerBlockEntityImpl(BlockPos pos, BlockState state) { + super(pos, state); + this.handlers = SidedInvWrapper.create(this, Direction.UP, Direction.DOWN, Direction.NORTH); + } -public class FreezerBlockEntityImpl { public static BlockEntityType.BlockEntityFactory getFactory() { - return PaladinFurnitureMod.getModList().contains("cookingforblockheads") ? FreezerBlockEntityBalm::new : FreezerBlockEntity::new; + return PaladinFurnitureMod.getModList().contains("cookingforblockheads") ? FreezerBlockEntityBalm::new : FreezerBlockEntityImpl::new; + } + + @Override + public @NotNull LazyOptional getCapability(Capability cap, @Nullable Direction side) { + if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { + if (side == Direction.UP) + return handlers[0].cast(); + else if (side == Direction.DOWN) { + return handlers[1].cast(); + } else { + return handlers[2].cast(); + } + } + return LazyOptional.empty(); + } + + @Override + public void invalidateCaps() { + super.invalidateCaps(); + for (LazyOptional handler : this.handlers) { + handler.invalidate(); + } } } diff --git a/forge/src/main/java/com/unlikepaladin/pfm/blocks/blockentities/forge/MicrowaveBlockEntityImpl.java b/forge/src/main/java/com/unlikepaladin/pfm/blocks/blockentities/forge/MicrowaveBlockEntityImpl.java index ec5881916..84d7fc0a6 100644 --- a/forge/src/main/java/com/unlikepaladin/pfm/blocks/blockentities/forge/MicrowaveBlockEntityImpl.java +++ b/forge/src/main/java/com/unlikepaladin/pfm/blocks/blockentities/forge/MicrowaveBlockEntityImpl.java @@ -19,7 +19,7 @@ import java.util.Objects; -public class MicrowaveBlockEntityImpl extends MicrowaveBlockEntity { +public class MicrowaveBlockEntityImpl extends MicrowaveBlockEntity { public MicrowaveBlockEntityImpl(BlockPos pos, BlockState state) { super(pos, state); } diff --git a/forge/src/main/java/com/unlikepaladin/pfm/compat/cookingforblockheads/forge/FreezerBlockEntityBalm.java b/forge/src/main/java/com/unlikepaladin/pfm/compat/cookingforblockheads/forge/FreezerBlockEntityBalm.java index c66d69169..89e1f8854 100644 --- a/forge/src/main/java/com/unlikepaladin/pfm/compat/cookingforblockheads/forge/FreezerBlockEntityBalm.java +++ b/forge/src/main/java/com/unlikepaladin/pfm/compat/cookingforblockheads/forge/FreezerBlockEntityBalm.java @@ -5,6 +5,7 @@ import com.google.common.collect.Table; import com.mojang.datafixers.util.Pair; import com.unlikepaladin.pfm.blocks.blockentities.FreezerBlockEntity; +import com.unlikepaladin.pfm.blocks.blockentities.forge.FreezerBlockEntityImpl; import net.blay09.mods.balm.api.Balm; import net.blay09.mods.balm.api.block.BalmBlockEntityContract; import net.blay09.mods.balm.api.container.BalmContainerProvider; @@ -40,7 +41,7 @@ import java.util.*; -public class FreezerBlockEntityBalm extends FreezerBlockEntity implements BalmContainerProvider, BalmProviderHolder, BalmBlockEntityContract { +public class FreezerBlockEntityBalm extends FreezerBlockEntityImpl implements BalmContainerProvider, BalmProviderHolder, BalmBlockEntityContract { private final DefaultKitchenItemProvider itemProvider; public FreezerBlockEntityBalm(BlockPos pos, BlockState state) { From d00ed31645622159add8ff530756c4ad44e945ae Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Sat, 17 Feb 2024 23:34:29 -0600 Subject: [PATCH 07/17] fix a crash when the registry was frozen --- .../data/materials/ExtraCounterVariant.java | 20 ++++++++++--------- .../pfm/data/materials/ExtraStoolVariant.java | 13 ++++++------ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/common/src/main/java/com/unlikepaladin/pfm/data/materials/ExtraCounterVariant.java b/common/src/main/java/com/unlikepaladin/pfm/data/materials/ExtraCounterVariant.java index e8e49f43a..55950f665 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/data/materials/ExtraCounterVariant.java +++ b/common/src/main/java/com/unlikepaladin/pfm/data/materials/ExtraCounterVariant.java @@ -16,23 +16,22 @@ public class ExtraCounterVariant extends VariantBase { public static ExtraCounterVariant DARK_CONCRETE = new ExtraCounterVariant(Blocks.GRAY_CONCRETE, Blocks.WHITE_CONCRETE, "dark_concrete"); - public static ExtraCounterVariant CONCRETE = new ExtraCounterVariant(Blocks.WHITE_CONCRETE, PaladinFurnitureModBlocksItems.RAW_CONCRETE, "concrete"); + public static ExtraCounterVariant CONCRETE = new ExtraCounterVariant(Blocks.WHITE_CONCRETE, null, "concrete"); public static ExtraCounterVariant SMOOTH_STONE = new ExtraCounterVariant(Blocks.WHITE_CONCRETE, Blocks.SMOOTH_STONE,"smooth_stone"); public static ExtraCounterVariant DEEPSLATE_TILE = new ExtraCounterVariant(Blocks.QUARTZ_BLOCK, Blocks.DEEPSLATE_TILES,"deepslate_tile"); private final String name; private final Block baseBlock; static final List DEFAULT_VARIANTS = new ArrayList<>(); - static { - DEFAULT_VARIANTS.add(DARK_CONCRETE); - DEFAULT_VARIANTS.add(CONCRETE); - DEFAULT_VARIANTS.add(SMOOTH_STONE); - DEFAULT_VARIANTS.add(DEEPSLATE_TILE); - } - private final Block secondaryBlock; public static List values() { + if (DEFAULT_VARIANTS.isEmpty()) { + DEFAULT_VARIANTS.add(DARK_CONCRETE); + DEFAULT_VARIANTS.add(CONCRETE); + DEFAULT_VARIANTS.add(SMOOTH_STONE); + DEFAULT_VARIANTS.add(DEEPSLATE_TILE); + } return DEFAULT_VARIANTS; } @@ -58,6 +57,9 @@ public Block getBaseBlock() { @Override public Block getSecondaryBlock() { + if (secondaryBlock == null) + return PaladinFurnitureModBlocksItems.RAW_CONCRETE; + return secondaryBlock; } @@ -100,7 +102,7 @@ public Block mainChild() { @Override public Identifier getTexture(BlockType type) { if (type == BlockType.SECONDARY) - return ModelHelper.getTextureId(secondaryBlock); + return ModelHelper.getTextureId(getSecondaryBlock()); return ModelHelper.getTextureId(baseBlock); } diff --git a/common/src/main/java/com/unlikepaladin/pfm/data/materials/ExtraStoolVariant.java b/common/src/main/java/com/unlikepaladin/pfm/data/materials/ExtraStoolVariant.java index 4bc8dc9c0..404e02a69 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/data/materials/ExtraStoolVariant.java +++ b/common/src/main/java/com/unlikepaladin/pfm/data/materials/ExtraStoolVariant.java @@ -25,14 +25,13 @@ public class ExtraStoolVariant extends VariantBase { private final Block secondaryBlock; static final List DEFAULT_VARIANTS = new ArrayList<>(); - static { - DEFAULT_VARIANTS.add(GRAY_DARK_OAK); - DEFAULT_VARIANTS.add(WHITE); - DEFAULT_VARIANTS.add(GRAY); - DEFAULT_VARIANTS.add(LIGHT_GRAY_DARK_OAK); - } - public static List values() { + if (DEFAULT_VARIANTS.isEmpty()) { + DEFAULT_VARIANTS.add(GRAY_DARK_OAK); + DEFAULT_VARIANTS.add(WHITE); + DEFAULT_VARIANTS.add(GRAY); + DEFAULT_VARIANTS.add(LIGHT_GRAY_DARK_OAK); + } return DEFAULT_VARIANTS; } From f34e6d14b25e1f970a0deeabed3a6cbf94099fa4 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Sat, 17 Feb 2024 23:36:40 -0600 Subject: [PATCH 08/17] Fix missing tag on the bathtub and cooking for blockheads cooking table --- .../unlikepaladin/pfm/runtime/data/PFMTagProvider.java | 3 ++- .../forge/PFMCookingForBlockheadsImpl.java | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/unlikepaladin/pfm/runtime/data/PFMTagProvider.java b/common/src/main/java/com/unlikepaladin/pfm/runtime/data/PFMTagProvider.java index bbaaa1739..b0b0e5c16 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/runtime/data/PFMTagProvider.java +++ b/common/src/main/java/com/unlikepaladin/pfm/runtime/data/PFMTagProvider.java @@ -125,7 +125,8 @@ protected void generateTags() { .add(PaladinFurnitureModBlocksItems.IRON_CHAIN) .add(sinkBlocks) .add(PaladinFurnitureModBlocksItems.BASIC_SHOWER_HANDLE) - .add(PaladinFurnitureModBlocksItems.BASIC_SHOWER_HEAD); + .add(PaladinFurnitureModBlocksItems.BASIC_SHOWER_HEAD) + .add(PaladinFurnitureModBlocksItems.BASIC_BATHTUB); KitchenCounterBlock[] woodCounters = KitchenCounterBlock.streamWoodCounters().map(FurnitureBlock::getBlock).toArray(KitchenCounterBlock[]::new); KitchenWallCounterBlock[] woodWallCounters = KitchenWallCounterBlock.streamWallWoodCounters().map(FurnitureBlock::getBlock).toArray(KitchenWallCounterBlock[]::new); diff --git a/forge/src/main/java/com/unlikepaladin/pfm/compat/cookingforblockheads/forge/PFMCookingForBlockheadsImpl.java b/forge/src/main/java/com/unlikepaladin/pfm/compat/cookingforblockheads/forge/PFMCookingForBlockheadsImpl.java index 1b168b1ed..73379fc9a 100644 --- a/forge/src/main/java/com/unlikepaladin/pfm/compat/cookingforblockheads/forge/PFMCookingForBlockheadsImpl.java +++ b/forge/src/main/java/com/unlikepaladin/pfm/compat/cookingforblockheads/forge/PFMCookingForBlockheadsImpl.java @@ -7,10 +7,12 @@ import com.unlikepaladin.pfm.registry.dynamic.LateBlockRegistry; import com.unlikepaladin.pfm.runtime.data.FurnitureRecipeJsonFactory; import com.unlikepaladin.pfm.runtime.data.PFMRecipeProvider; +import com.unlikepaladin.pfm.runtime.data.PFMTagProvider; import net.blay09.mods.cookingforblockheads.CookingForBlockheads; import net.blay09.mods.cookingforblockheads.item.ModItems; import net.minecraft.block.Blocks; import net.minecraft.data.server.recipe.RecipeJsonProvider; +import net.minecraft.tag.BlockTags; import net.minecraft.util.Identifier; import java.util.Optional; @@ -22,6 +24,14 @@ public class PFMCookingForBlockheadsImpl extends PFMCookingForBlockheads { public PFMCookingForBlockheadsImpl() { } + @Override + public void generateTags() { + super.generateTags(); + + PFMTagProvider.getOrCreateTagBuilder(BlockTags.PICKAXE_MINEABLE) + .add(PFMCookingForBlockHeadsCompat.COOKING_TABLE_BLOCK); + } + @Override public void generateRecipes(Consumer exporter) { FurnitureRecipeJsonFactory.create(PFMCookingForBlockHeadsCompat.COOKING_TABLE_BLOCK, 4).group("kitchen").criterion(PFMRecipeProvider.getCriterionNameFromOutput(PFMCookingForBlockHeadsCompat.COOKING_TABLE_BLOCK), PFMRecipeProvider.conditionsFromItem(ModItems.recipeBook)).input(ModItems.recipeBook).input(Blocks.WHITE_CONCRETE, 2).input(Blocks.GRAY_CONCRETE).offerTo(exporter, new Identifier("pfm", PFMCookingForBlockHeadsCompat.COOKING_TABLE_BLOCK.asItem().getTranslationKey().replace("block.pfm.", ""))); From a9d5d60a2d2b4798de5df4d323aa4c93c6ae910b Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Sun, 18 Feb 2024 00:18:35 -0600 Subject: [PATCH 09/17] Fix mod urls being broken on Fabric --- fabric/src/main/resources/fabric.mod.json | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 56b4092d4..e7dbe21f1 100755 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -48,11 +48,13 @@ "suggests": { "patchouli": "*" }, - "modmenu": { - "links": { - "modmenu.discord": "https://discord.gg/zbMDUPB", - "modmenu.kofi": "https://ko-fi.com/unlikepaladin", - "modmenu.modrinth": "https://modrinth.com/mod/paladins-furniture/" + "custom": { + "modmenu": { + "links": { + "modmenu.discord": "https://discord.gg/zbMDUPB", + "modmenu.kofi": "https://ko-fi.com/unlikepaladin", + "modmenu.modrinth": "https://modrinth.com/mod/paladins-furniture/" + } } } } \ No newline at end of file From b76e495e6fb1c7dd9ba48ee7072244e2097c421e Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Sun, 18 Feb 2024 00:31:25 -0600 Subject: [PATCH 10/17] Bump to rc.3 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 83e7e8d10..1c69d2b38 100755 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ minecraft_version=1.17.1 enabled_platforms=fabric,forge archives_base_name=paladin-furniture-mod -mod_version=1.2.1-rc2 +mod_version=1.2.1-rc.3 maven_group=com.unlikepaladin architectury_version=2.10.12 From 6029059a4929e7bb8e4c58a7a51b67af6469ce76 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Sun, 18 Feb 2024 20:49:42 -0600 Subject: [PATCH 11/17] Create FUNDING.yml --- .github/FUNDING.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 000000000..f35ab6fef --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +ko_fi: unlikepaladin From 6df0045920c5e5ee734c24a8740e3cc89c0c149c Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Sun, 18 Feb 2024 20:51:00 -0600 Subject: [PATCH 12/17] Add issue templates --- .github/ISSUE_TEMPLATE/bug_report.yml | 58 ++++++++++++++++++++++ .github/ISSUE_TEMPLATE/config.yml | 7 +++ .github/ISSUE_TEMPLATE/feature_request.yml | 26 ++++++++++ 3 files changed, 91 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 000000000..b5a11f77d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,58 @@ +name: Bug Report +description: "For reporting bugs and other defects" +labels: + - bug +body: + - type: markdown + attributes: + value: >- + **Note: This issue tracker is not intended for support requests!** If you need help with crashes or other issues, then + you should [ask on our Discord server](https://discord.gg/zbMDUPB) instead. +

+ Additionally, please make sure you have done the following: + + - **Have you ensured that all of your mods are up-to-date?** The latest version of Paladin's Furniture Mod + can always be found [on Modrinth](https://modrinth.com/mod/paladins-furniture) or [on CurseForge](https://www.curseforge.com/minecraft/mc-mods/paladins-furniture). + + - **Have you used the [search tool](https://github.com/UnlikePaladin/paladins-furniture/issues) to check whether your issue + has already been reported?** If it has been, then consider adding more information to the existing issue instead. + + - **Have you determined the minimum set of instructions to reproduce the issue?** If your problem only occurs + with other mods installed, then you should narrow down exactly which mods are causing the issue. Please do not + provide your entire list of mods to us and expect that we will be able to figure out the problem. +

+ + This issue template was based [off of Sodium's](https://github.com/CaffeineMC/sodium-fabric/blob/dev/.github/ISSUE_TEMPLATE/bug_report.yml) + - type: textarea + id: description + attributes: + label: Bug Description + description: >- + Use this section to describe the issue you are experiencing in as much depth as possible. The description should + explain what behavior you were expecting, and why you believe the issue to be a bug. If the issue you are reporting + only occurs with specific mods installed, then provide the name and version of each mod. + + **Hint:** If you have any screenshots, videos, or other information that you feel is necessary to + explain the issue, you can attach them here. + - type: textarea + id: description-reproduction-steps + attributes: + label: Reproduction Steps + description: >- + Provide as much information as possible on how to reproduce this bug. Make sure your instructions are as clear and + concise as possible, because other people will need to be able to follow your guide in order to re-create the issue. + + **Hint:** A common way to fill this section out is to write a step-by-step guide. + validations: + required: true + - type: textarea + id: log-file + attributes: + label: Log File + description: >- + **Hint:** You can usually find the log files within the folder `.minecraft/logs`. Most often, you will want the `latest.log` + file, since that file belongs to the last played session of the game. + placeholder: >- + Drag-and-drop the log file here. + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 000000000..4fdf39b79 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,7 @@ +blank_issues_enabled: true +contact_links: + - name: For help with other issues, join the Discord community + url: https://discord.gg/zbMDUPB + about: This is the best option for getting help with mod installation, performance issues, and any other support inquiries + # Copied from https://github.com/CaffeineMC/sodium-fabric#community + # Copied from https://github.com/CaffeineMC/sodium-fabric/blob/dev/.github/ISSUE_TEMPLATE/config.yml \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 000000000..7de897952 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,26 @@ +name: Feature Request +description: "For requesting new features or improvements" +labels: + - enhancement +body: + - type: markdown + attributes: + value: >- + This form is for requesting new features or improvements, and should not be used for bug reports or other issues. + - type: markdown + attributes: + value: >- + Make sure you have used the [search tool](https://github.com/UnlikePaladin/paladins-furniture/issues) to see if a similar + request already exists. If we have previously closed a feature request, then please do not create another request. + - type: markdown + attributes: + value: >- + This template was based [off of Sodium's](https://github.com/CaffeineMC/sodium-fabric/blob/dev/.github/ISSUE_TEMPLATE/feature_request.yml) + - type: textarea + id: description + attributes: + label: Request Description + description: >- + Use this section to describe the feature or improvement that you are looking for. The description should explain + what you would like to see added, and a clear and concise description + of what you would like changed. \ No newline at end of file From c157df5009787ced0e2abf6b77faa88674e54441 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Sun, 18 Feb 2024 20:51:54 -0600 Subject: [PATCH 13/17] Update bug_report.yml --- .github/ISSUE_TEMPLATE/bug_report.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index b5a11f77d..2b185361b 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -20,7 +20,7 @@ body: - **Have you determined the minimum set of instructions to reproduce the issue?** If your problem only occurs with other mods installed, then you should narrow down exactly which mods are causing the issue. Please do not provide your entire list of mods to us and expect that we will be able to figure out the problem. -

+
This issue template was based [off of Sodium's](https://github.com/CaffeineMC/sodium-fabric/blob/dev/.github/ISSUE_TEMPLATE/bug_report.yml) - type: textarea From dda094b61ac3e902693e03a13c2453311c2625e2 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Mon, 19 Feb 2024 00:38:37 -0600 Subject: [PATCH 14/17] improve the code around texture replacement on forge and disable caching if optifine exists fix the accesswidener --- .../unlikepaladin/pfm/PaladinFurnitureMod.java | 8 ++++++++ common/src/main/resources/pfm.accesswidener | 2 +- .../blocks/models/forge/PFMForgeBakedModel.java | 17 ++++++++++++----- .../forge/PaladinFurnitureModClientImpl.java | 2 +- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/com/unlikepaladin/pfm/PaladinFurnitureMod.java b/common/src/main/java/com/unlikepaladin/pfm/PaladinFurnitureMod.java index 63004b23c..44235746f 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/PaladinFurnitureMod.java +++ b/common/src/main/java/com/unlikepaladin/pfm/PaladinFurnitureMod.java @@ -106,6 +106,14 @@ public static Loader getLoader() { throw new AssertionError(); } + public static boolean isOptifineLoaded() { + try { + Class.forName("net.optifine.shaders.Shaders"); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } public enum Loader implements StringIdentifiable { FORGE("forge"), FABRIC_LIKE("fabric_like"); diff --git a/common/src/main/resources/pfm.accesswidener b/common/src/main/resources/pfm.accesswidener index 0c0f749cd..5f4a67e8e 100644 --- a/common/src/main/resources/pfm.accesswidener +++ b/common/src/main/resources/pfm.accesswidener @@ -6,5 +6,5 @@ accessible method net/minecraft/data/server/BlockLootTableGenerator drops (Lnet/ accessible method net/minecraft/data/server/BlockLootTableGenerator dropsWithProperty (Lnet/minecraft/block/Block;Lnet/minecraft/state/property/Property;Ljava/lang/Comparable;)Lnet/minecraft/loot/LootTable$Builder; accessible class net/minecraft/data/server/AbstractTagProvider$ObjectBuilder accessible method net/minecraft/client/render/item/ItemRenderer renderBakedItemModel (Lnet/minecraft/client/render/model/BakedModel;Lnet/minecraft/item/ItemStack;IILnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;)V -accessible field net/minecraft/client/resource/language/LanguageManager field_25291 Lnet/minecraft/client/resource/language/LanguageDefinition; +accessible field net/minecraft/client/resource/language/LanguageManager language Lnet/minecraft/client/resource/language/LanguageDefinition; accessible field net/minecraft/block/AbstractBlock$Settings material Lnet/minecraft/block/Material; diff --git a/forge/src/main/java/com/unlikepaladin/pfm/blocks/models/forge/PFMForgeBakedModel.java b/forge/src/main/java/com/unlikepaladin/pfm/blocks/models/forge/PFMForgeBakedModel.java index 43cd1a489..196b58cb6 100644 --- a/forge/src/main/java/com/unlikepaladin/pfm/blocks/models/forge/PFMForgeBakedModel.java +++ b/forge/src/main/java/com/unlikepaladin/pfm/blocks/models/forge/PFMForgeBakedModel.java @@ -1,5 +1,6 @@ package com.unlikepaladin.pfm.blocks.models.forge; +import com.google.common.collect.Iterables; import com.mojang.datafixers.util.Pair; import com.unlikepaladin.pfm.PaladinFurnitureMod; import com.unlikepaladin.pfm.blocks.models.AbstractBakedModel; @@ -50,8 +51,13 @@ public List getQuadsWithTexture(List quads, List t if (quads == null) return Collections.emptyList(); - if (replacements == null || toReplace == null || toReplace.size() != replacements.size()) { - PaladinFurnitureMod.GENERAL_LOGGER.warn("Replacement list is not the same size or was null, skipping transformation"); + if (replacements == null || toReplace == null) { + PaladinFurnitureMod.GENERAL_LOGGER.warn("Replacement list was null, skipping transformation"); + return quads; + } else if (toReplace.size() != replacements.size()) { + PaladinFurnitureMod.GENERAL_LOGGER.warn("Replacement list was not the same size, skipping transformation, expected {} sprites, got {}", toReplace.size(), replacements.size()); + PaladinFurnitureMod.GENERAL_LOGGER.debug(toReplace); + PaladinFurnitureMod.GENERAL_LOGGER.debug(replacements); return quads; } if (toReplace.equals(replacements)) @@ -81,7 +87,7 @@ public List getQuadsWithTexture(List quads, List t .orElse(-1); if (index != -1) { - Sprite replacement = replacements.get(index); + Sprite replacement = Iterables.get(replacements, index, toReplace.get(index)); transformedQuads.addAll(getQuadsWithTexture(entry.getValue().stream().filter(quads::contains).toList(), replacement)); } else { transformedQuads.addAll(entry.getValue().stream().filter(quads::contains).toList()); @@ -97,13 +103,14 @@ public List getQuadsWithTexture(List quads, Sprite sprite) // UV Element index int uvVertexIndx = findVertexElement(VertexFormatElement.Type.UV, 0); + // I basically have to disable caching if Optifine is present, otherwise it breaks uvs quads.forEach(quad -> { Pair quadKey = new Pair<>(sprite.getId(), quad); - if (quad.getSprite().getId() == sprite.getId() && !quadToTransformedQuad.containsKey(quadKey)) { + if (quad.getSprite().getId() == sprite.getId() && !quadToTransformedQuad.containsKey(quadKey) && !PaladinFurnitureMod.isOptifineLoaded()) { quadToTransformedQuad.put(quadKey, quad); transformedQuads.add(quad); } - else if (quadToTransformedQuad.containsKey(quadKey)) { + else if (quadToTransformedQuad.containsKey(quadKey) && !PaladinFurnitureMod.isOptifineLoaded()) { transformedQuads.add(quadToTransformedQuad.get(quadKey)); } else { diff --git a/forge/src/main/java/com/unlikepaladin/pfm/client/forge/PaladinFurnitureModClientImpl.java b/forge/src/main/java/com/unlikepaladin/pfm/client/forge/PaladinFurnitureModClientImpl.java index 2253ed1f5..d90e50d64 100644 --- a/forge/src/main/java/com/unlikepaladin/pfm/client/forge/PaladinFurnitureModClientImpl.java +++ b/forge/src/main/java/com/unlikepaladin/pfm/client/forge/PaladinFurnitureModClientImpl.java @@ -7,7 +7,7 @@ public class PaladinFurnitureModClientImpl { public static boolean areShadersOn() { - if (PaladinFurnitureMod.getModList().contains("oculus")) + if (PaladinFurnitureMod.getModList().contains("oculus") || PaladinFurnitureMod.getModList().contains("iris")) return IrisApi.getInstance().isShaderPackInUse(); try { From 10114fbe202fec106fc4f5935776854016cceed3 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Mon, 19 Feb 2024 00:38:59 -0600 Subject: [PATCH 15/17] migrate to Loom 1.4 --- build.gradle | 2 +- common/build.gradle | 2 +- fabric/build.gradle | 28 ++++++------------------ forge/build.gradle | 4 +++- gradle.properties | 6 ++--- gradle/wrapper/gradle-wrapper.properties | 2 +- 6 files changed, 15 insertions(+), 29 deletions(-) diff --git a/build.gradle b/build.gradle index 73f736c02..dc51e893c 100755 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "1.2-SNAPSHOT" apply false + id "dev.architectury.loom" version "1.4-SNAPSHOT" apply false } architectury { diff --git a/common/build.gradle b/common/build.gradle index 4ac3a6f4b..14c83b5f4 100755 --- a/common/build.gradle +++ b/common/build.gradle @@ -21,7 +21,7 @@ dependencies { // Do NOT use other classes from fabric loader modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" // Remove the next line if you don't want to depend on the API - modCompileOnly "me.shedaniel:RoughlyEnoughItems-api:${rootProject.rei_version}" + modCompileOnly("me.shedaniel:RoughlyEnoughItems-api:${rootProject.rei_version}") modCompileOnly("com.github.qouteall.ImmersivePortalsMod:imm_ptl_core:${rootProject.immersive_portals_version_fabric}"){ exclude(group: "net.fabricmc.fabric-api") diff --git a/fabric/build.gradle b/fabric/build.gradle index d39a0c8e2..e70a8c0ea 100755 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -85,9 +85,6 @@ else { modCompileOnly("maven.modrinth:sandwichable:${rootProject.sandwichable_version}"){ exclude(group: "net.fabricmc.fabric-api") } - modCompileOnly("dev.lambdaurora:spruceui:${rootProject.spruceui_version}"){ - exclude(group: "net.fabricmc.fabric-api") - } } } @@ -114,21 +111,6 @@ else { } } -if (rootProject.arrp_compatibility == "true") { - dependencies { - modImplementation("curse.maven:arrp-463113:${rootProject.arrp_version}"){ - exclude(group: "net.fabricmc.fabric-api") - } - } -} -else { - dependencies { - modCompileOnly("curse.maven:arrp-463113:${rootProject.arrp_version}") { - exclude(group: "net.fabricmc.fabric-api") - } - } -} - if (rootProject.immersive_portals_compatibility_fabric == "true"){ dependencies { modImplementation ("com.github.qouteall.ImmersivePortalsMod:imm_ptl_core:${rootProject.immersive_portals_version_fabric}"){ @@ -156,14 +138,18 @@ dependencies { modImplementation("com.terraformersmc:modmenu:${rootProject.modmenu_version}") { exclude(group: "net.fabricmc.fabric-api") - transitive = false + transitive(false) } // modRuntimeOnly("com.terraformersmc:terrestria:${rootProject.terrestria}") - modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:${rootProject.rei_version}" + modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-fabric:${rootProject.rei_version}") { + transitive(false) + } modCompileOnly("maven.modrinth:iris:${rootProject.iris_version}") - modCompileOnly("maven.modrinth:farmers-delight-fabric:${rootProject.farmers_delight_version_fabric}") + modCompileOnly("maven.modrinth:farmers-delight-fabric:${rootProject.farmers_delight_version_fabric}"){ + transitive(false) + } //modImplementation "curse.maven:balm-fabric-500525:${rootProject.balm_version_fabric}" //modImplementation "curse.maven:cooking-for-blockheads-fabric-634546:${rootProject.cookingforblockheads_version_fabric}" diff --git a/forge/build.gradle b/forge/build.gradle index 9b3495457..78c758e75 100755 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -67,7 +67,9 @@ dependencies { modImplementation("vazkii.patchouli:Patchouli:${rootProject.patchouli_version_forge}") modCompileOnly(("mezz.jei:jei-${rootProject.minecraft_version}:${rootProject.jei_version}:api")) - modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-forge:${rootProject.rei_version}" + modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-forge:${rootProject.rei_version}") { + transitive(false) + } //modRuntimeOnly("curse.maven:biomesop-220318:3562256") modCompileOnly ("maven.modrinth:oculus:${rootProject.oculus_version}") diff --git a/gradle.properties b/gradle.properties index 1c69d2b38..ad85d2b15 100755 --- a/gradle.properties +++ b/gradle.properties @@ -20,11 +20,9 @@ rei_version=6.5.433 patchouli_version_fabric=1.17.1-59-FABRIC-SNAPSHOT sandwichable_version=1.2+1.17 spruceui_version=3.3.2+1.17 -sandwichable_compatibility=true -rei_compatibility=true +sandwichable_compatibility=false +rei_compatibility=false patchouli_compatibility=true -arrp_version=3529149 -arrp_compatibility=true modmenu_version=2.0.6 jei_version=8.3.1.62 patchouli_version_forge=1.17.1-58-SNAPSHOT diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 59bc51a20..db9a6b825 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From bae54a5ac6660c985bf87bc370eb8e7e9893beb2 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Mon, 19 Feb 2024 01:20:27 -0600 Subject: [PATCH 16/17] Force cloth config 5.3.63 --- common/build.gradle | 8 +++++++- fabric/build.gradle | 3 +++ forge/build.gradle | 3 +++ gradle.properties | 3 ++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/common/build.gradle b/common/build.gradle index 14c83b5f4..e5abce636 100755 --- a/common/build.gradle +++ b/common/build.gradle @@ -21,7 +21,13 @@ dependencies { // Do NOT use other classes from fabric loader modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" // Remove the next line if you don't want to depend on the API - modCompileOnly("me.shedaniel:RoughlyEnoughItems-api:${rootProject.rei_version}") + modCompileOnly("me.shedaniel:RoughlyEnoughItems-api:${rootProject.rei_version}"){ + exclude(group: "net.fabricmc.fabric-api") + exclude(group: "me.shedaniel.cloth") + } + modCompileOnly("me.shedaniel.cloth:cloth-config-fabric:${rootProject.cloth_config_version}") { + exclude(group: "net.fabricmc.fabric-api") + } modCompileOnly("com.github.qouteall.ImmersivePortalsMod:imm_ptl_core:${rootProject.immersive_portals_version_fabric}"){ exclude(group: "net.fabricmc.fabric-api") diff --git a/fabric/build.gradle b/fabric/build.gradle index e70a8c0ea..ffc5d7978 100755 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -91,6 +91,9 @@ else { if (rootProject.rei_compatibility == "true"){ dependencies { modRuntimeOnly("me.shedaniel:RoughlyEnoughItems-fabric:${rootProject.rei_version}"){ + transitive(false) + } + modRuntimeOnly("me.shedaniel.cloth:cloth-config-api:${rootProject.cloth_config_version}") { exclude(group: "net.fabricmc.fabric-api") } } diff --git a/forge/build.gradle b/forge/build.gradle index 78c758e75..6234679fa 100755 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -99,6 +99,9 @@ if (rootProject.lazy_dfu_enabled == "true"){ if (rootProject.rei_compatibility == "true"){ dependencies { modRuntimeOnly("me.shedaniel:RoughlyEnoughItems-forge:${rootProject.rei_version}") + modRuntimeOnly("me.shedaniel.cloth:cloth-config-forge:${rootProject.cloth_config_version}") { + transitive(false) + } } } diff --git a/gradle.properties b/gradle.properties index ad85d2b15..c99970b00 100755 --- a/gradle.properties +++ b/gradle.properties @@ -42,4 +42,5 @@ balm_version_fabric=3539926 balm_version_forge=3555365 cookingforblockheads_version_forge=3493691 farmers_delight_version_fabric=0.1.3 -farmers_delight_version_forge=3608552 \ No newline at end of file +farmers_delight_version_forge=3608552 +cloth_config_version=5.3.63 \ No newline at end of file From 9d468fde8840efadb2c2354b3aa8257546b7dbf1 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Mon, 19 Feb 2024 01:46:50 -0600 Subject: [PATCH 17/17] Revert "wip new config stuff, commented the variant blacklist out" This reverts commit 317af3125e8c6f21e52aeec3fd78e4222af4d252. Had to be done because the build script would have an aneurysm with this for some reason --- .../pfm/client/screens/PFMConfigScreen.java | 19 +- .../screens/widget/PFMOptionListWidget.java | 431 +----------------- .../pfm/config/PaladinFurnitureModConfig.java | 28 +- .../config/option/AbstractConfigOption.java | 15 +- .../config/option/BooleanConfigOption.java | 18 +- .../pfm/config/option/ConfigIO.java | 3 +- .../pfm/config/option/ConfigOptionType.java | 2 +- .../pfm/config/option/ConfigOptionTypes.java | 2 +- .../pfm/config/option/ListConfigOption.java | 180 -------- .../pfm/config/option/NullConfigOption.java | 2 +- .../option/StringArrayConfigOption.java | 242 ---------- .../pfm/config/option/StringConfigOption.java | 112 ----- .../pfm/registry/PFMItemGroup.java | 27 -- common/src/main/resources/pfm.accesswidener | 1 - 14 files changed, 43 insertions(+), 1039 deletions(-) delete mode 100644 common/src/main/java/com/unlikepaladin/pfm/config/option/ListConfigOption.java delete mode 100644 common/src/main/java/com/unlikepaladin/pfm/config/option/StringArrayConfigOption.java delete mode 100644 common/src/main/java/com/unlikepaladin/pfm/config/option/StringConfigOption.java delete mode 100644 common/src/main/java/com/unlikepaladin/pfm/registry/PFMItemGroup.java diff --git a/common/src/main/java/com/unlikepaladin/pfm/client/screens/PFMConfigScreen.java b/common/src/main/java/com/unlikepaladin/pfm/client/screens/PFMConfigScreen.java index 14f4d143d..ec3597af7 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/client/screens/PFMConfigScreen.java +++ b/common/src/main/java/com/unlikepaladin/pfm/client/screens/PFMConfigScreen.java @@ -52,8 +52,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { MinecraftClient.getInstance().setScreen(parent); }, new TranslatableText("gui.pfm.changesMightNotBeSaved").setStyle(Style.EMPTY.withColor(0xf77f34).withBold(true)), new TranslatableText("gui.pfm.saveChanges"))); return true; - } else if (optionListWidget.keyPressed(keyCode, scanCode, modifiers)) - return true; + } return super.keyPressed(keyCode, scanCode, modifiers); } @@ -81,24 +80,14 @@ protected void init() { if (option.getDefaultValue() != this.optionListWidget.newConfigValues.get(option)) { this.optionListWidget.hasChanges.set(this.optionListWidget.configOptionToIndexForHasChanges.get(option), true); } - this.optionListWidget.newConfigValues.put(option, option.getDefaultValue()); - } else if (option.getType() == String.class) { - if (option.getDefaultValue() != this.optionListWidget.newConfigValues.get(option)) { - this.optionListWidget.hasChanges.set(this.optionListWidget.configOptionToIndexForHasChanges.get(option), true); - } - this.optionListWidget.newConfigValues.put(option, option.getDefaultValue()); + this.optionListWidget.newConfigValues.put(option, (Boolean) option.getDefaultValue()); } } else if (!isOnServer && option.getSide() == Side.SERVER) { if (option.getType() == Boolean.class) { if (option.getDefaultValue() != this.optionListWidget.newConfigValues.get(option)) { this.optionListWidget.hasChanges.set(this.optionListWidget.configOptionToIndexForHasChanges.get(option), true); } - this.optionListWidget.newConfigValues.put(option, option.getDefaultValue()); - } else if (option.getType() == String.class) { - if (option.getDefaultValue() != this.optionListWidget.newConfigValues.get(option)) { - this.optionListWidget.hasChanges.set(this.optionListWidget.configOptionToIndexForHasChanges.get(option), true); - } - this.optionListWidget.newConfigValues.put(option, option.getDefaultValue()); + this.optionListWidget.newConfigValues.put(option, (Boolean) option.getDefaultValue()); } } }); @@ -122,7 +111,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { drawCenteredText(matrices, this.textRenderer, TITLE.setStyle(Style.EMPTY.withColor(0xf77f34).withBold(true)), this.width / 2, 8, 0xFFFFFF); boolean bl = false; - for (Map.Entry optionEntry : optionListWidget.newConfigValues.entrySet()) { + for (Map.Entry optionEntry : optionListWidget.newConfigValues.entrySet()) { if (optionEntry.getValue() == optionEntry.getKey().getDefaultValue()) continue; bl = true; break; diff --git a/common/src/main/java/com/unlikepaladin/pfm/client/screens/widget/PFMOptionListWidget.java b/common/src/main/java/com/unlikepaladin/pfm/client/screens/widget/PFMOptionListWidget.java index ae0d06b6f..58ba09649 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/client/screens/widget/PFMOptionListWidget.java +++ b/common/src/main/java/com/unlikepaladin/pfm/client/screens/widget/PFMOptionListWidget.java @@ -3,7 +3,9 @@ import com.google.common.collect.ImmutableList; import com.unlikepaladin.pfm.PaladinFurnitureMod; import com.unlikepaladin.pfm.client.screens.PFMConfigScreen; -import com.unlikepaladin.pfm.config.option.*; +import com.unlikepaladin.pfm.config.option.AbstractConfigOption; +import com.unlikepaladin.pfm.config.option.BooleanConfigOption; +import com.unlikepaladin.pfm.config.option.Side; import com.unlikepaladin.pfm.runtime.PFMAssetGenerator; import com.unlikepaladin.pfm.runtime.PFMDataGenerator; import com.unlikepaladin.pfm.runtime.PFMRuntimeResources; @@ -18,10 +20,8 @@ import net.minecraft.client.gui.screen.narration.NarrationPart; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.ElementListWidget; -import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.*; -import org.lwjgl.glfw.GLFW; import java.util.*; import java.util.function.Consumer; @@ -30,13 +30,13 @@ public class PFMOptionListWidget extends ElementListWidget newConfigValues; + public Map newConfigValues; public Map configOptionToIndexForHasChanges; - int index = 0; public PFMOptionListWidget(PFMConfigScreen parent, MinecraftClient client) { super(client, parent.width + 125, parent.height, 43, parent.height - 32, 20); this.parent = parent; String string = null; + int index = 0; hasChanges = new BitSet(PaladinFurnitureMod.getPFMConfig().options.size()); newConfigValues = new HashMap<>(PaladinFurnitureMod.getPFMConfig().options.size()); configOptionToIndexForHasChanges = new HashMap<>(PaladinFurnitureMod.getPFMConfig().options.size()); @@ -52,30 +52,14 @@ public PFMOptionListWidget(PFMConfigScreen parent, MinecraftClient client) { this.maxKeyNameLength = i; } if (configOptionEntry.getValue().getType() == Boolean.class) { - PFMOptionListWidget.this.newConfigValues.put(configOptionEntry.getValue(), configOptionEntry.getValue().getValue()); + PFMOptionListWidget.this.newConfigValues.put(configOptionEntry.getValue(), (Boolean) configOptionEntry.getValue().getValue()); this.addEntry(new BooleanEntry((BooleanConfigOption)configOptionEntry.getValue(), text, index)); - } else if (configOptionEntry.getValue().getType() == ArrayList.class) { - for (AbstractConfigOption configOption : (ListConfigOption)configOptionEntry.getValue()) { - PFMOptionListWidget.this.newConfigValues.put(configOption, configOption.getValue()); - configOptionToIndexForHasChanges.put(configOption, index); - index++; - } - PFMOptionListWidget.this.newConfigValues.put(configOptionEntry.getValue(), configOptionEntry.getValue().getValue()); - this.addEntry(new ListEntry((ListConfigOption) configOptionEntry.getValue(), text, index)); - } else if (configOptionEntry.getValue().getType() == String.class) { - PFMOptionListWidget.this.newConfigValues.put(configOptionEntry.getValue(), configOptionEntry.getValue().getValue()); - this.addEntry(new StringEntry((StringConfigOption) configOptionEntry.getValue(), text, index)); - } else if (configOptionEntry.getValue().getType() == String[].class) { - PFMOptionListWidget.this.newConfigValues.put(configOptionEntry.getValue(), new ArrayList<>(List.of((String[]) configOptionEntry.getValue().getValue()))); - this.addEntry(new StringArrayEntry((StringArrayConfigOption) configOptionEntry.getValue(), text, index)); - } - else { + } else { PaladinFurnitureMod.GENERAL_LOGGER.warn("Unsupported Config Type!"); } configOptionToIndexForHasChanges.put(configOptionEntry.getValue(), index); index++; } - //TODO : implement string here this.addEntry(new CategoryEntry(new LiteralText(""))); this.addEntry(new ButtonEntry(Side.CLIENT, new TranslatableText("pfm.option.regenAssets"), new TranslatableText("pfm.config.regen"), new TranslatableText("pfm.option.regenAssets.tooltip"), button -> { PFMFileUtil.deleteDir(PFMRuntimeResources.getAssetPackDirectory().toFile()); @@ -84,27 +68,19 @@ public PFMOptionListWidget(PFMConfigScreen parent, MinecraftClient client) { PFMRuntimeResources.runAsyncResourceGen(); MinecraftClient.getInstance().reloadResourcesConcurrently(); })); - ButtonEntry dataEntry = new ButtonEntry(Side.SERVER, new TranslatableText("pfm.option.regenData"), new TranslatableText("pfm.config.regen"), new TranslatableText("pfm.option.regenData.tooltip"), button -> { + ButtonEntry entry = new ButtonEntry(Side.SERVER, new TranslatableText("pfm.option.regenData"), new TranslatableText("pfm.config.regen"), new TranslatableText("pfm.option.regenData.tooltip"), button -> { PFMFileUtil.deleteDir(PFMRuntimeResources.getDataPackDirectory().toFile()); PFMDataGenerator.FROZEN = false; PFMRuntimeResources.prepareAsyncDataGen(true); PFMRuntimeResources.runAsyncResourceGen(); }); - dataEntry.button.active = !PFMConfigScreen.isOnServer; - this.addEntry(dataEntry); - } - - @Override - public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - if (children().stream().anyMatch(entry -> entry.keyPressed(index, scanCode, modifiers))) - return true; - - return super.keyPressed(keyCode, scanCode, modifiers); + entry.button.active = !PFMConfigScreen.isOnServer; + this.addEntry(entry); } public void save() { - for (Map.Entry entry : newConfigValues.entrySet()) { - if (entry.getKey().getType() == Boolean.class || entry.getKey().getType() == String.class) + for (Map.Entry entry : newConfigValues.entrySet()) { + if (entry.getKey().getType() == Boolean.class) entry.getKey().setValue(entry.getValue()); } } @@ -160,10 +136,6 @@ public void appendNarrations(NarrationMessageBuilder builder) { } }); } - - @Override - public void resetValue() { - } } @Environment(value=EnvType.CLIENT) @@ -198,7 +170,7 @@ public void supply(Consumer consumer) { this.valueButton = new ButtonWidget(0, 0, 75, 20, optionName, button -> { PFMOptionListWidget.this.parent.focusedConfigOption = configOption; - PFMOptionListWidget.this.newConfigValues.put(configOption, !(Boolean)PFMOptionListWidget.this.newConfigValues.get(configOption)); + PFMOptionListWidget.this.newConfigValues.put(configOption, !PFMOptionListWidget.this.newConfigValues.get(configOption)); hasChanges = !hasChanges; PFMOptionListWidget.this.hasChanges.set(index, hasChanges); }, this.supplier); @@ -225,7 +197,7 @@ public void render(MatrixStack matrices, int index, int y, int x, int entryWidth this.resetButton.render(matrices, mouseX, mouseY, tickDelta); this.valueButton.x = x + 105; this.valueButton.y = y; - this.valueButton.setMessage(((Boolean)PFMOptionListWidget.this.newConfigValues.get(configOption)) ? ScreenTexts.YES : ScreenTexts.NO); + this.valueButton.setMessage(PFMOptionListWidget.this.newConfigValues.get(configOption) ? ScreenTexts.YES : ScreenTexts.NO); this.valueButton.active = this.configOption.getSide() != Side.SERVER || !PFMConfigScreen.isOnServer; this.valueButton.render(matrices, mouseX, mouseY, tickDelta); } @@ -252,358 +224,6 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { public boolean mouseReleased(double mouseX, double mouseY, int button) { return this.valueButton.mouseReleased(mouseX, mouseY, button) || this.resetButton.mouseReleased(mouseX, mouseY, button); } - - @Override - public void resetValue() { - PFMOptionListWidget.this.newConfigValues.put(configOption, configOption.getDefaultValue()); - hasChanges = true; - PFMOptionListWidget.this.hasChanges.set(index, true); - } - } - - @Environment(value=EnvType.CLIENT) - public class StringEntry - extends Entry { - private final StringConfigOption configOption; - private final Text optionName; - private final TextFieldWidget stringField; - private final ButtonWidget resetButton; - - private final ButtonWidget.TooltipSupplier supplier; - int index; - boolean hasChanges = false; - StringEntry(final StringConfigOption configOption, final Text optionName, int index) { - this.configOption = configOption; - this.optionName = optionName; - this.index = index; - this.supplier = new ButtonWidget.TooltipSupplier() { - final MutableText sideText = configOption.getSide() == Side.CLIENT ? new TranslatableText("pfm.option.client").setStyle(Style.EMPTY.withItalic(false).withBold(true).withColor(0xf77f34)) : new TranslatableText("pfm.option.server").setStyle((Style.EMPTY.withItalic(false).withBold(true).withColor(0xf77f34))); - final MutableText styledTooltip = ((MutableText)configOption.getToolTip()).setStyle(Style.EMPTY.withItalic(true)); - final MutableText combinedText = new LiteralText("").append(sideText).append(new LiteralText("\n")).append(styledTooltip); - @Override - public void onTooltip(ButtonWidget button, MatrixStack matrices, int mouseX, int mouseY) { - PFMOptionListWidget.this.parent.renderOrderedTooltip(matrices, PFMOptionListWidget.this.client.textRenderer.wrapLines(combinedText, Math.max(PFMOptionListWidget.this.width / 2 - 43, 170)), mouseX, mouseY); - } - @Override - public void supply(Consumer consumer) { - consumer.accept(combinedText); - ButtonWidget.TooltipSupplier.super.supply(consumer); - } - }; - - this.stringField = new TextFieldWidget(PFMOptionListWidget.this.client.textRenderer, 0, 0, 85, 20, new LiteralText(configOption.getValue())); - - this.stringField.setChangedListener(newValue -> { - if (newValue.isEmpty()) { - return; - } - PFMOptionListWidget.this.newConfigValues.put(configOption, newValue); - }); - this.resetButton = new ButtonWidget(0, 0, 50, 20, new TranslatableText("controls.reset"), button -> { - this.stringField.setText(configOption.getDefaultValue()); - PFMOptionListWidget.this.newConfigValues.put(configOption, configOption.getDefaultValue()); - hasChanges = true; - PFMOptionListWidget.this.hasChanges.set(index, true); - }){ - - @Override - protected MutableText getNarrationMessage() { - return new TranslatableText("narrator.controls.reset", optionName); - } - }; - } - - @Override - public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - if (this.stringField.keyPressed(keyCode, scanCode, modifiers) || this.stringField.isActive()) { - return true; - } - return super.keyPressed(keyCode, scanCode, modifiers); - } - - @Override - public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { - PFMOptionListWidget.this.client.textRenderer.draw(matrices, this.optionName, (float)(x + 90 - PFMOptionListWidget.this.maxKeyNameLength), (float)(y + entryHeight / 2 - PFMOptionListWidget.this.client.textRenderer.fontHeight / 2), 0xFFFFFF); - this.resetButton.x = x + 190; - this.resetButton.y = y; - this.resetButton.active = this.configOption.getSide() == Side.SERVER ? !PFMConfigScreen.isOnServer && !(this.configOption.getDefaultValue() == PFMOptionListWidget.this.newConfigValues.get(configOption)) : !(this.configOption.getDefaultValue() == PFMOptionListWidget.this.newConfigValues.get(configOption));; - this.resetButton.render(matrices, mouseX, mouseY, tickDelta); - this.stringField.x = x + 95; - this.stringField.y = y; - this.stringField.active = this.configOption.getSide() != Side.SERVER || !PFMConfigScreen.isOnServer; - this.stringField.render(matrices, mouseX, mouseY, tickDelta); - } - - @Override - public List children() { - return ImmutableList.of(this.stringField, this.resetButton); - } - - @Override - public List selectableChildren() { - return ImmutableList.of(this.stringField, this.resetButton); - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (this.stringField.mouseClicked(mouseX, mouseY, button)) { - return true; - } - return this.resetButton.mouseClicked(mouseX, mouseY, button); - } - - @Override - public boolean mouseReleased(double mouseX, double mouseY, int button) { - return this.stringField.mouseReleased(mouseX, mouseY, button) || this.resetButton.mouseReleased(mouseX, mouseY, button); - } - - @Override - public void resetValue() { - PFMOptionListWidget.this.newConfigValues.put(configOption, configOption.getDefaultValue()); - hasChanges = true; - PFMOptionListWidget.this.hasChanges.set(index, true); - } - } - - @Environment(value=EnvType.CLIENT) - public class StringArrayEntry - extends Entry { - private final StringArrayConfigOption configOption; - private final Text optionName; - private final List stringFields; - private final ButtonWidget resetButton; - private final ButtonWidget addButton; - - private final ButtonWidget.TooltipSupplier supplier; - int index; - boolean hasChanges = false; - int currentFieldIndx = 0; - StringArrayEntry(final StringArrayConfigOption configOption, final Text optionName, int index) { - this.configOption = configOption; - this.optionName = optionName; - this.index = index; - this.supplier = new ButtonWidget.TooltipSupplier() { - final MutableText sideText = configOption.getSide() == Side.CLIENT ? new TranslatableText("pfm.option.client").setStyle(Style.EMPTY.withItalic(false).withBold(true).withColor(0xf77f34)) : new TranslatableText("pfm.option.server").setStyle((Style.EMPTY.withItalic(false).withBold(true).withColor(0xf77f34))); - final MutableText styledTooltip = ((MutableText)configOption.getToolTip()).setStyle(Style.EMPTY.withItalic(true)); - final MutableText combinedText = new LiteralText("").append(sideText).append(new LiteralText("\n")).append(styledTooltip); - @Override - public void onTooltip(ButtonWidget button, MatrixStack matrices, int mouseX, int mouseY) { - PFMOptionListWidget.this.parent.renderOrderedTooltip(matrices, PFMOptionListWidget.this.client.textRenderer.wrapLines(combinedText, Math.max(PFMOptionListWidget.this.width / 2 - 43, 170)), mouseX, mouseY); - } - @Override - public void supply(Consumer consumer) { - consumer.accept(combinedText); - ButtonWidget.TooltipSupplier.super.supply(consumer); - } - }; - stringFields = new ArrayList<>(configOption.size()); - configOption.forEach(currentValue -> { - TextFieldWidget widget = new TextFieldWidget(PFMOptionListWidget.this.client.textRenderer, 0, 20*currentFieldIndx, 85, 20, new LiteralText(currentValue)); - widget.setChangedListener(newValue -> { - List stringList = PFMOptionListWidget.this.newConfigValues.get(configOption) == null ? new ArrayList<>() : (List) PFMOptionListWidget.this.newConfigValues.get(configOption); - if (stringList.contains(widget.getText())) - stringList.set(stringList.indexOf(widget.getText()), newValue); - else - stringList.add(newValue); - }); - stringFields.add(widget); - addEntry(new CategoryEntry(new LiteralText(""))); - currentFieldIndx++; - }); - this.resetButton = new ButtonWidget(0, 0, 50, 20, new TranslatableText("controls.reset"), button -> { - stringFields.clear(); - PFMOptionListWidget.this.newConfigValues.put(configOption, new ArrayList<>()); - hasChanges = true; - PFMOptionListWidget.this.hasChanges.set(index, true); - }){ - - @Override - protected MutableText getNarrationMessage() { - return new TranslatableText("narrator.controls.reset", optionName); - } - }; - this.addButton = new ButtonWidget(0, 0, 20, 20, new LiteralText("+"), button -> { - TextFieldWidget widget = new TextFieldWidget(PFMOptionListWidget.this.client.textRenderer, 0, 20*currentFieldIndx, 85, 20, new LiteralText("")); - widget.setChangedListener(newValue -> { - List stringList = PFMOptionListWidget.this.newConfigValues.get(configOption) == null ? new ArrayList<>() : (List) PFMOptionListWidget.this.newConfigValues.get(configOption); - if (stringList.contains(widget.getText())) - stringList.set(stringList.indexOf(widget.getText()), newValue); - else - stringList.add(newValue); - }); - stringFields.add(widget); - addEntry(new CategoryEntry(new LiteralText(""))); - currentFieldIndx++; - }){ - - @Override - protected MutableText getNarrationMessage() { - return new LiteralText("+"); - } - }; - } - - @Override - public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - if (this.stringFields.stream().anyMatch(textFieldWidget -> textFieldWidget.keyPressed(keyCode, scanCode, modifiers)) || this.stringFields.stream().anyMatch(TextFieldWidget::isActive)) { - return true; - } - return super.keyPressed(keyCode, scanCode, modifiers); - } - - @Override - public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { - PFMOptionListWidget.this.client.textRenderer.draw(matrices, this.optionName, (float)(x + 90 - PFMOptionListWidget.this.maxKeyNameLength), (float)(y + entryHeight / 2 - PFMOptionListWidget.this.client.textRenderer.fontHeight / 2), 0xFFFFFF); - this.resetButton.x = x + 190; - this.resetButton.y = y; - this.resetButton.active = this.configOption.getSide() == Side.SERVER ? !PFMConfigScreen.isOnServer && !(this.configOption.getDefaultValue() == PFMOptionListWidget.this.newConfigValues.get(configOption)) : !(this.configOption.getDefaultValue() == PFMOptionListWidget.this.newConfigValues.get(configOption));; - this.resetButton.render(matrices, mouseX, mouseY, tickDelta); - - this.addButton.x = x + 120; - this.addButton.y = y; - this.addButton.active = this.configOption.getSide() == Side.SERVER; - this.addButton.render(matrices, mouseX, mouseY, tickDelta); - int indx = 0; - for (TextFieldWidget widget : stringFields) { - widget.x = x; - widget.y = y + (20*indx); - widget.render(matrices, mouseX, mouseY, tickDelta); - widget.active = this.configOption.getSide() != Side.SERVER || !PFMConfigScreen.isOnServer; - indx++; - } - } - - @Override - public List children() { - List children = new ArrayList<>(this.stringFields.size()+1); - children.addAll(stringFields); - children.add(this.resetButton); - children.add(this.addButton); - return children; - } - - @Override - public List selectableChildren() { - List children = new ArrayList<>(this.stringFields.size()+1); - children.addAll(stringFields); - children.add(this.resetButton); - children.add(this.addButton); - return children; - } - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (this.stringFields.stream().anyMatch(textFieldWidget -> textFieldWidget.mouseClicked(mouseX, mouseY, button))) { - return true; - } - return this.resetButton.mouseClicked(mouseX, mouseY, button) || this.addButton.mouseClicked(mouseX, mouseY, button); - } - - @Override - public boolean mouseReleased(double mouseX, double mouseY, int button) { - return this.stringFields.stream().anyMatch(textFieldWidget -> textFieldWidget.mouseReleased(mouseX, mouseY, button)) || this.resetButton.mouseReleased(mouseX, mouseY, button) || this.addButton.mouseClicked(mouseX, mouseY, button); - } - - @Override - public void resetValue() { - PFMOptionListWidget.this.newConfigValues.put(configOption, new ArrayList<>()); - hasChanges = true; - PFMOptionListWidget.this.hasChanges.set(index, true); - } - } - - @Environment(value=EnvType.CLIENT) - public class ListEntry - extends Entry { - private final ListConfigOption configOption; - private final Text optionName; - private final ButtonWidget resetButton; - int index; - private final List entryList; - boolean hasChanges = false; - ListEntry(final ListConfigOption configOptions, final Text optionName, int index) { - this.configOption = configOptions; - this.optionName = optionName; - this.index = index; - this.entryList = new ArrayList<>(configOptions.size()); - for (AbstractConfigOption option : configOptions) { - if (option.getType() == Boolean.class) { - entryList.add(new BooleanEntry((BooleanConfigOption) option, option.getTitle(), PFMOptionListWidget.this.configOptionToIndexForHasChanges.get(option))); - } - else if (option.getType() == String.class) { - entryList.add(new StringEntry((StringConfigOption) option, option.getTitle(), PFMOptionListWidget.this.configOptionToIndexForHasChanges.get(option))); - } - else if (option.getType() == String[].class) { - entryList.add(new StringArrayEntry((StringArrayConfigOption) option, option.getTitle(), PFMOptionListWidget.this.configOptionToIndexForHasChanges.get(option))); - } - } - this.resetButton = new ButtonWidget(0, 0, 50, 20, new TranslatableText("controls.reset"), button -> { - - hasChanges = true; - PFMOptionListWidget.this.hasChanges.set(index, true); - }){ - @Override - protected MutableText getNarrationMessage() { - return new TranslatableText("narrator.controls.reset", optionName); - } - }; - } - - @Override - public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { - PFMOptionListWidget.this.client.textRenderer.draw(matrices, this.optionName, (float)(x + 90 - PFMOptionListWidget.this.maxKeyNameLength), (float)(y + entryHeight / 2 - PFMOptionListWidget.this.client.textRenderer.fontHeight / 2), 0xFFFFFF); - this.resetButton.x = x + 190; - this.resetButton.y = y; - this.resetButton.active = this.configOption.getSide() == Side.SERVER ? !PFMConfigScreen.isOnServer && !(this.configOption.getDefaultValue() == PFMOptionListWidget.this.newConfigValues.get(configOption)) : !(this.configOption.getDefaultValue() == PFMOptionListWidget.this.newConfigValues.get(configOption));; - this.resetButton.render(matrices, mouseX, mouseY, tickDelta); - for (Entry entry : entryList) { - entry.render(matrices, index, y, x, entryWidth, entryHeight, mouseX, mouseY, hovered, tickDelta); - } - } - - @Override - public List children() { - List children = new ArrayList<>(this.entryList.size()); - for (Entry entry : entryList) { - children.addAll(entry.children()); - } - children.add(this.resetButton); - return children; - } - - @Override - public List selectableChildren() { - List children = new ArrayList<>(this.entryList.size()); - for (Entry entry : entryList) { - children.addAll(entry.selectableChildren()); - } - children.add(this.resetButton); - return children; - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - for (Entry entry : entryList) { - if (entry.mouseClicked(mouseX, mouseY, button)) - return true; - } - return this.resetButton.mouseClicked(mouseX, mouseY, button); - } - - @Override - public boolean mouseReleased(double mouseX, double mouseY, int button) { - for (Entry entry : entryList) { - if (entry.mouseReleased(mouseX, mouseY, button)) - return true; - } - return this.resetButton.mouseReleased(mouseX, mouseY, button); - } - - @Override - public void resetValue() { - for (Entry entry : entryList) { - entry.resetValue(); - } - } } @Environment(value=EnvType.CLIENT) @@ -667,31 +287,10 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { public boolean mouseReleased(double mouseX, double mouseY, int button) { return this.button.mouseReleased(mouseX, mouseY, button); } - - @Override - public void resetValue() { - } } @Environment(value=EnvType.CLIENT) - public static abstract class Entry extends ElementListWidget.Entry implements Selectable { - public abstract void resetValue(); - @Override - public SelectionType getType() { - return SelectionType.NONE; - } - - public abstract List selectableChildren(); - - @Override - public void appendNarrations(NarrationMessageBuilder narrationMessageBuilder) { - - } - - @Override - public boolean isNarratable() { - return false; - } + public static abstract class Entry extends ElementListWidget.Entry { } } diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/PaladinFurnitureModConfig.java b/common/src/main/java/com/unlikepaladin/pfm/config/PaladinFurnitureModConfig.java index fa33c92b6..42f11b5ba 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/config/PaladinFurnitureModConfig.java +++ b/common/src/main/java/com/unlikepaladin/pfm/config/PaladinFurnitureModConfig.java @@ -3,7 +3,9 @@ import com.google.gson.*; import com.google.gson.reflect.TypeToken; import com.unlikepaladin.pfm.PaladinFurnitureMod; -import com.unlikepaladin.pfm.config.option.*; +import com.unlikepaladin.pfm.config.option.AbstractConfigOption; +import com.unlikepaladin.pfm.config.option.BooleanConfigOption; +import com.unlikepaladin.pfm.config.option.Side; import net.minecraft.text.TranslatableText; import java.io.*; @@ -40,7 +42,6 @@ public PaladinFurnitureModConfig(Path propertiesPath) { mobsSitOnChairs = new BooleanConfigOption(new TranslatableText("pfm.option.mobsSitOnChairs"), new TranslatableText("pfm.option.mobsSitOnChairs.tooltip"), GAMEPLAY_OPTIONS, true, Side.SERVER), renderImmersivePortalsMirrors = new BooleanConfigOption(new TranslatableText("pfm.option.renderImmersivePortalsMirrors"), new TranslatableText("pfm.option.renderImmersivePortalsMirrors.tooltip"), GAMEPLAY_OPTIONS, true, Side.CLIENT), spawnImmersivePortalsMirror = new BooleanConfigOption(new TranslatableText("pfm.option.spawnImmersivePortalsMirror"), new TranslatableText("pfm.option.spawnImmersivePortalsMirror.tooltip"), GAMEPLAY_OPTIONS, true, Side.SERVER) - // variantBlacklist = new StringArrayConfigOption(new TranslatableText("pfm.option.variantBlacklist"), new TranslatableText("pfm.option.variantBlacklist.tooltip"), GAMEPLAY_OPTIONS, new ArrayList<>(), Side.SERVER) alas it is not ready yet ); this.propertiesPath = propertiesPath.resolve("pfm.json"); this.directoryPath = propertiesPath; @@ -126,7 +127,6 @@ public boolean doImmersivePortalsMirrorsSpawn() { private BooleanConfigOption mobsSitOnChairs; private BooleanConfigOption renderImmersivePortalsMirrors; private BooleanConfigOption spawnImmersivePortalsMirror; -// private StringArrayConfigOption variantBlacklist; public Path getPath() { @@ -165,17 +165,7 @@ public void load() throws IOException { mobsSitOnChairs.setValue(getFromJsonElement(config.get("mobsSitOnChairs"), false)); renderImmersivePortalsMirrors.setValue(getFromJsonElement(config.get("renderImmersivePortalsMirrors"), true)); spawnImmersivePortalsMirror.setValue(getFromJsonElement(config.get("spawnImmersivePortalsMirror"), true)); - /* JsonObject object = getFromJsonElement(config.get("variantBlacklist"), new JsonObject()); - if (object != null && object.isJsonArray()) { - JsonArray variantBlackListArray = object.getAsJsonArray(); - - // Extract strings from the array - List stringList = new ArrayList<>(); - for (JsonElement arrayElement : variantBlackListArray) { - stringList.add(arrayElement.getAsString()); - } - variantBlacklist.addAll(stringList); - }*/ + for (String key : options.keySet()) { if (!config.has(key.replace("pfm.option.", ""))){ PaladinFurnitureMod.GENERAL_LOGGER.warn("Missing Config Option: " + key.replace("pfm.option.", "") + ", resetting to default value."); @@ -249,17 +239,9 @@ public void save() throws IOException { object.addProperty("mobsSitOnChairs", mobsSitOnChairs.getValue()); object.addProperty("renderImmersivePortalsMirrors", renderImmersivePortalsMirrors.getValue()); object.addProperty("spawnImmersivePortalsMirror", spawnImmersivePortalsMirror.getValue()); - // object.add("variantBlacklist", toJsonElement(variantBlacklist.getValue())); + try (FileWriter writer = new FileWriter(propertiesPath.toString())) { GSON.toJson(object, writer); } } - - public JsonElement toJsonElement(String[] stringArray) { - JsonArray jsonArray = new JsonArray(); - for (String value : stringArray) { - jsonArray.add(new JsonPrimitive(value)); - } - return jsonArray; - } } diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/option/AbstractConfigOption.java b/common/src/main/java/com/unlikepaladin/pfm/config/option/AbstractConfigOption.java index 1d4f9d240..400c82cac 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/config/option/AbstractConfigOption.java +++ b/common/src/main/java/com/unlikepaladin/pfm/config/option/AbstractConfigOption.java @@ -15,12 +15,9 @@ import java.io.IOException; import java.util.Objects; -public interface AbstractConfigOption extends Comparable { +public abstract class AbstractConfigOption implements Comparable { public static final byte NULL_TYPE = 0; public static final byte BOOL_TYPE = 1; - public static final byte STRING_TYPE = 2; - public static final byte STRING_ARRAY_TYPE = 3; - public static final byte LIST_TYPE = 4; public abstract Text getTitle(); @@ -50,6 +47,10 @@ public static Side getSide(String string) { } return null; } + @Override + public String toString() { + return "{Type: " + getType() + ", Title: " + ((TranslatableText)getTitle()).getKey() + ", Category: " + getCategory() + ", Value: " + getValue() + ", Side:" + getSide() + "}"; + } public abstract void write(DataOutput output) throws IOException; @@ -86,12 +87,8 @@ public static AbstractConfigOption readConfigOption(PacketByteBuf packetByteBuf, } } - public default String asString() { - return "{Type: " + getType() + ", Title: " + ((TranslatableText)getTitle()).getKey() + ", Category: " + getCategory() + ", Value: " + getValue() + ", Side:" + getSide() + "}"; - } - @Override - public default int compareTo(@NotNull String o) { + public int compareTo(@NotNull String o) { return this.getCategory().compareTo(o); } } diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/option/BooleanConfigOption.java b/common/src/main/java/com/unlikepaladin/pfm/config/option/BooleanConfigOption.java index cb305d404..16c3ea68c 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/config/option/BooleanConfigOption.java +++ b/common/src/main/java/com/unlikepaladin/pfm/config/option/BooleanConfigOption.java @@ -11,25 +11,25 @@ import java.io.DataOutput; import java.io.IOException; -public class BooleanConfigOption implements AbstractConfigOption{ +public class BooleanConfigOption extends AbstractConfigOption{ public static final ConfigOptionType TYPE = new ConfigOptionType<>() { - public BooleanConfigOption read(DataInput dataInput, int i, ConfigSizeTracker sizeTracker) throws IOException { - sizeTracker.add(2400L); + public BooleanConfigOption read(DataInput dataInput, int i, ConfigSizeTracker nbtTagSizeTracker) throws IOException { + nbtTagSizeTracker.add(2400L); String title = dataInput.readUTF(); String tooltip = dataInput.readUTF(); String category = dataInput.readUTF(); boolean value = dataInput.readBoolean(); - Side side = AbstractConfigOption.getSide(dataInput.readUTF()); - sizeTracker.add(224L + 16L * title.length()); - sizeTracker.add(224L + 16L * tooltip.length()); - sizeTracker.add(224L + 16L * category.length()); - sizeTracker.add(64L); + Side side = getSide(dataInput.readUTF()); + nbtTagSizeTracker.add(224L + 16L * title.length()); + nbtTagSizeTracker.add(224L + 16L * tooltip.length()); + nbtTagSizeTracker.add(224L + 16L * category.length()); + nbtTagSizeTracker.add(64L); BooleanConfigOption booleanConfigOption = new BooleanConfigOption(new TranslatableText(title), new TranslatableText(tooltip), category, value, side); return booleanConfigOption; } public String getCrashReportName() { - return "BOOL-OPTION"; + return "END"; } public boolean isImmutable() { diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigIO.java b/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigIO.java index d01b483fd..379d14b6c 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigIO.java +++ b/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigIO.java @@ -8,7 +8,6 @@ import org.jetbrains.annotations.Nullable; import java.io.*; -import java.util.ArrayList; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; @@ -74,7 +73,7 @@ public static AbstractConfigOption read(DataInput input, ConfigSizeTracker track protected static void write(AbstractConfigOption element, DataOutput output) throws IOException { output.writeByte(element.getConfigType()); - if (element.getType() != Boolean.class && element.getType() != ArrayList.class && element.getType() != String.class && element.getType() != String[].class) { + if (element.getType() != Boolean.class) { PaladinFurnitureMod.GENERAL_LOGGER.warn("Unsupported Type: " + element.getType()); return; } diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigOptionType.java b/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigOptionType.java index 24a205920..b5d940c0b 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigOptionType.java +++ b/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigOptionType.java @@ -28,7 +28,7 @@ public String getCrashReportName() { } @Override - public NullConfigOption read(DataInput input, int depth, ConfigSizeTracker tracker) throws IOException { + public /* synthetic */ NullConfigOption read(DataInput input, int depth, ConfigSizeTracker tracker) throws IOException { throw new IllegalArgumentException("Invalid Config id: " + type); } }; diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigOptionTypes.java b/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigOptionTypes.java index 86332d701..a80d04868 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigOptionTypes.java +++ b/common/src/main/java/com/unlikepaladin/pfm/config/option/ConfigOptionTypes.java @@ -5,7 +5,7 @@ public class ConfigOptionTypes { // - private static final ConfigOptionType[] VALUES = new ConfigOptionType[]{NullConfigOption.TYPE, BooleanConfigOption.TYPE, StringConfigOption.TYPE, StringArrayConfigOption.TYPE, ListConfigOption.TYPE}; + private static final ConfigOptionType[] VALUES = new ConfigOptionType[]{NullConfigOption.TYPE, BooleanConfigOption.TYPE}; public static ConfigOptionType byId(int id) { if (id < 0 || id >= VALUES.length) { diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/option/ListConfigOption.java b/common/src/main/java/com/unlikepaladin/pfm/config/option/ListConfigOption.java deleted file mode 100644 index b1b11e493..000000000 --- a/common/src/main/java/com/unlikepaladin/pfm/config/option/ListConfigOption.java +++ /dev/null @@ -1,180 +0,0 @@ -package com.unlikepaladin.pfm.config.option; - -import com.google.common.collect.Lists; -import net.minecraft.nbt.NbtElement; -import net.minecraft.text.Text; -import net.minecraft.text.TranslatableText; -import org.jetbrains.annotations.NotNull; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.util.AbstractList; -import java.util.ArrayList; - -public class ListConfigOption extends AbstractList> implements AbstractConfigOption { - public static final ConfigOptionType TYPE = new ConfigOptionType(){ - - @Override - public ListConfigOption read(DataInput dataInput, int i, ConfigSizeTracker sizeTracker) throws IOException { - String title = dataInput.readUTF(); - String tooltip = dataInput.readUTF(); - String category = dataInput.readUTF(); - sizeTracker.add(224L + 16L * title.length()); - sizeTracker.add(224L + 16L * tooltip.length()); - sizeTracker.add(224L + 16L * category.length()); - sizeTracker.add(64L); - sizeTracker.add(296L); - if (i > 512) { - throw new RuntimeException("Tried to read option with too high complexity, depth > 512"); - } - byte type = dataInput.readByte(); - int size = dataInput.readInt(); - if (type == 0 && size > 0) { - throw new RuntimeException("Missing type on Option List"); - } - sizeTracker.add(32L * (long)size); - ConfigOptionType optionType = ConfigOptionTypes.byId(type); - ArrayList> list = Lists.newArrayListWithCapacity(size); - for (int index = 0; index < size; ++index) { - list.add(optionType.read(dataInput, i + 1, sizeTracker)); - } - Side side = AbstractConfigOption.getSide(dataInput.readUTF()); - return new ListConfigOption(new TranslatableText(title), new TranslatableText(tooltip), category, list, type, side); - } - - @Override - public String getCrashReportName() { - return "LIST-OPTION"; - } - }; - - private final Text title; - private final Text tooltip; - private final String category; - private ArrayList> value; - private byte type; - private final Side side; - public ListConfigOption(Text title, Text tooltip, String category, ArrayList> value, byte type, Side side) { - this.title = title; - this.category = category; - this.tooltip = tooltip; - this.value = value; - this.type = type; - this.side = side; - } - - @Override - public Text getTitle() { - return title; - } - - @Override - public String getCategory() { - return category; - } - - @Override - public Object getValue() { - return value; - } - - @Override - public Object getDefaultValue() { - return value; - } - - @Override - public Text getToolTip() { - return tooltip; - } - - @Override - public void setValue(Object value) { - if (value instanceof ArrayList && !((ArrayList) value).isEmpty() && ((ArrayList) value).get(0) instanceof AbstractConfigOption) - this.value = (ArrayList>) value; - } - - @Override - public Class getType() { - return ArrayList.class; - } - - @Override - public boolean isDefault() { - return value.stream().allMatch(AbstractConfigOption::isDefault); - } - - @Override - public Side getSide() { - return side; - } - - @Override - public byte getConfigType() { - return LIST_TYPE; - } - - @Override - public void write(DataOutput output) throws IOException { - output.writeUTF(((TranslatableText)title).getKey()); - output.writeUTF(((TranslatableText)tooltip).getKey()); - output.writeUTF(category); - this.type = this.value.isEmpty() ? (byte)0 : this.value.get(0).getConfigType(); - output.writeByte(this.type); - output.writeInt(this.value.size()); - for (AbstractConfigOption configOption : this.value) { - configOption.write(output); - } - output.writeUTF(side.asString()); - } - - @Override - public AbstractConfigOption get(int index) { - return value.get(index); - } - - @Override - public int size() { - return value.size(); - } - - @Override - public AbstractConfigOption set(int index, AbstractConfigOption element) { - if (index < value.size() && index >= 0 && value.get(index).getConfigType() == element.getConfigType()) { - return value.set(index, element); - } - return null; - } - - public void setElementValue(int index, Object v) { - if (index < value.size() && index >= 0 && value.get(index).getClass() == v.getClass()) { - ((AbstractConfigOption)value.get(index)).setValue(v); - } - } - - public Object getElementValue(int index) { - if (index < value.size() && index >= 0) { - return ((AbstractConfigOption)value.get(index)).getValue(); - } - return NullConfigOption.INSTANCE.getValue(); - } - - @NotNull - @Override - public T @NotNull [] toArray(T @NotNull [] a) { - return value.toArray(a); - } - - @Override - public AbstractConfigOption remove(int index) { - return value.remove(index); - } - - @Override - public int compareTo(@NotNull Object o) { - if (o instanceof String) - return compareTo((String) o); - return 0; - } -} diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/option/NullConfigOption.java b/common/src/main/java/com/unlikepaladin/pfm/config/option/NullConfigOption.java index 977e645e0..b8fe5ed9e 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/config/option/NullConfigOption.java +++ b/common/src/main/java/com/unlikepaladin/pfm/config/option/NullConfigOption.java @@ -8,7 +8,7 @@ import java.io.DataOutput; import java.io.IOException; -public class NullConfigOption implements AbstractConfigOption{ +public class NullConfigOption extends AbstractConfigOption{ public static final ConfigOptionType TYPE = new ConfigOptionType(){ public NullConfigOption read(DataInput dataInput, int i, ConfigSizeTracker nbtTagSizeTracker, byte n) { diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/option/StringArrayConfigOption.java b/common/src/main/java/com/unlikepaladin/pfm/config/option/StringArrayConfigOption.java deleted file mode 100644 index 94aba03bf..000000000 --- a/common/src/main/java/com/unlikepaladin/pfm/config/option/StringArrayConfigOption.java +++ /dev/null @@ -1,242 +0,0 @@ -package com.unlikepaladin.pfm.config.option; - - -import net.minecraft.text.Text; -import net.minecraft.text.TranslatableText; -import org.jetbrains.annotations.NotNull; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.util.*; -import java.util.function.Consumer; -import java.util.function.IntFunction; -import java.util.function.Predicate; -import java.util.function.UnaryOperator; -import java.util.stream.Stream; - -public class StringArrayConfigOption extends AbstractList implements AbstractConfigOption { - public static final ConfigOptionType TYPE = new ConfigOptionType<>() { - public StringArrayConfigOption read(DataInput dataInput, int i, ConfigSizeTracker sizeTracker) throws IOException { - sizeTracker.add(2400L); - String title = dataInput.readUTF(); - String tooltip = dataInput.readUTF(); - String category = dataInput.readUTF(); - int size = dataInput.readInt(); - sizeTracker.add(32L * (long)size); - List strings = new ArrayList<>(size); - for (int index = 0; index < size; ++index) { - strings.set(index, dataInput.readUTF()); - } - Side side = AbstractConfigOption.getSide(dataInput.readUTF()); - sizeTracker.add(224L + 16L * title.length()); - sizeTracker.add(224L + 16L * tooltip.length()); - sizeTracker.add(224L + 16L * category.length()); - sizeTracker.add(64L); - return new StringArrayConfigOption(new TranslatableText(title), new TranslatableText(tooltip), category, strings, side); - } - - public String getCrashReportName() { - return "STRING-OPTION"; - } - - public boolean isImmutable() { - return true; - } - }; - private final Text title; - private final Text tooltip; - private final String category; - private List value; - private final String[] defaultValue; - - private final Side side; - private int size; - public StringArrayConfigOption(Text title, Text tooltip, String category, List value, Side side) { - this.title = title; - this.category = category; - this.tooltip = tooltip; - this.value = value; - this.defaultValue = new String[1]; - this.side = side; - } - - @Override - public Text getTitle() { - return title; - } - - @Override - public String getCategory() { - return category; - } - - @Override - public String[] getValue() { - return value.toArray(new String[0]); - } - - @Override - public String[] getDefaultValue() { - return defaultValue; - } - - @Override - public Text getToolTip() { - return tooltip; - } - - @Override - public void setValue(String[] value) { - this.value = List.of(value); - } - - @Override - public Class getType() { - return String[].class; - } - - @Override - public boolean isDefault() { - return value.equals(List.of(defaultValue)); - } - - @Override - public Side getSide() { - return side; - } - - @Override - public byte getConfigType() { - return STRING_ARRAY_TYPE; - } - - @Override - public void write(DataOutput output) throws IOException { - output.writeUTF(((TranslatableText)title).getKey()); - output.writeUTF(((TranslatableText)tooltip).getKey()); - output.writeUTF(category); - output.writeInt(this.value.size()); - for (String i : this.value) { - output.writeUTF(i); - } - output.writeUTF(side.asString()); - } - - @Override - public String get(int index) { - if (index < value.size() && index >= 0) - return value.get(index); - return ""; - } - - @Override - public String set(int index, String element) { - if (index < value.size() && index >= 0) { - return value.set(index, element); - } - return ""; - } - - - @Override - public int size() { - return size; - } - - @Override - public boolean add(String element) { - return value.add(element); - } - - @Override - public boolean remove(Object o) { - return value.remove(o); - } - - @Override - public String remove(int index) { - return value.remove(index); - } - - @Override - public boolean removeAll(@NotNull Collection c) { - return value.removeAll(c); - } - - @Override - public boolean removeIf(Predicate filter) { - return value.removeIf(filter); - } - - @Override - public void replaceAll(UnaryOperator operator) { - value.replaceAll(operator); - } - - @Override - public Stream stream() { - return value.stream(); - } - - @NotNull - @Override - public T[] toArray(@NotNull T[] a) { - return value.toArray(a); - } - - @Override - public void forEach(Consumer action) { - value.forEach(action); - } - - @Override - public void sort(Comparator c) { - value.sort(c); - } - - @Override - public Stream parallelStream() { - return value.parallelStream(); - } - - @Override - public Iterator iterator() { - return value.iterator(); - } - - @Override - public int hashCode() { - return value.hashCode(); - } - - @Override - public int lastIndexOf(Object o) { - return value.lastIndexOf(o); - } - - @Override - public boolean addAll(@NotNull Collection c) { - return value.addAll(c); - } - - @Override - public boolean addAll(int index, Collection c) { - return value.addAll(index, c); - } - - @Override - public int indexOf(Object o) { - return value.indexOf(o); - } - - @Override - public boolean contains(Object o) { - return value.contains(o); - } - - @Override - public T[] toArray(IntFunction generator) { - return value.toArray(generator); - } -} diff --git a/common/src/main/java/com/unlikepaladin/pfm/config/option/StringConfigOption.java b/common/src/main/java/com/unlikepaladin/pfm/config/option/StringConfigOption.java deleted file mode 100644 index 86414f91c..000000000 --- a/common/src/main/java/com/unlikepaladin/pfm/config/option/StringConfigOption.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.unlikepaladin.pfm.config.option; - - -import net.minecraft.text.Text; -import net.minecraft.text.TranslatableText; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.util.Objects; - -public class StringConfigOption implements AbstractConfigOption { - public static final ConfigOptionType TYPE = new ConfigOptionType<>() { - public StringConfigOption read(DataInput dataInput, int i, ConfigSizeTracker sizeTracker) throws IOException { - sizeTracker.add(2400L); - String title = dataInput.readUTF(); - String tooltip = dataInput.readUTF(); - String category = dataInput.readUTF(); - String value = dataInput.readUTF(); - Side side = AbstractConfigOption.getSide(dataInput.readUTF()); - sizeTracker.add(224L + 16L * title.length()); - sizeTracker.add(224L + 16L * tooltip.length()); - sizeTracker.add(224L + 16L * category.length()); - sizeTracker.add(224L + 16L * value.length()); - sizeTracker.add(64L); - StringConfigOption booleanConfigOption = new StringConfigOption(new TranslatableText(title), new TranslatableText(tooltip), category, value, side); - return booleanConfigOption; - } - - public String getCrashReportName() { - return "STRING-OPTION"; - } - - public boolean isImmutable() { - return true; - } - }; - private final Text title; - private final Text tooltip; - private final String category; - private String value; - private final String defaultValue; - - private final Side side; - public StringConfigOption(Text title, Text tooltip, String category, String value, Side side) { - this.title = title; - this.category = category; - this.tooltip = tooltip; - this.value = value; - this.defaultValue = value; - this.side = side; - } - - @Override - public Text getTitle() { - return title; - } - - @Override - public String getCategory() { - return category; - } - - @Override - public String getValue() { - return value; - } - - @Override - public String getDefaultValue() { - return defaultValue; - } - - @Override - public Text getToolTip() { - return tooltip; - } - - @Override - public void setValue(String value) { - this.value = value; - } - - @Override - public Class getType() { - return String.class; - } - - @Override - public boolean isDefault() { - return Objects.equals(value, defaultValue); - } - - @Override - public Side getSide() { - return side; - } - - @Override - public byte getConfigType() { - return STRING_TYPE; - } - - @Override - public void write(DataOutput output) throws IOException { - output.writeUTF(((TranslatableText)title).getKey()); - output.writeUTF(((TranslatableText)tooltip).getKey()); - output.writeUTF(category); - output.writeUTF(value); - output.writeUTF(side.asString()); - } -} diff --git a/common/src/main/java/com/unlikepaladin/pfm/registry/PFMItemGroup.java b/common/src/main/java/com/unlikepaladin/pfm/registry/PFMItemGroup.java deleted file mode 100644 index fa33a7936..000000000 --- a/common/src/main/java/com/unlikepaladin/pfm/registry/PFMItemGroup.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.unlikepaladin.pfm.registry; - -import com.unlikepaladin.pfm.blocks.BasicChairBlock; -import com.unlikepaladin.pfm.data.materials.WoodVariantRegistry; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; -import net.minecraft.util.collection.DefaultedList; -import net.minecraft.util.registry.Registry; - -public abstract class PFMItemGroup extends ItemGroup { - public PFMItemGroup(int index, String id) { - super(index, id); - } - - @Override - public ItemStack createIcon() { - return PaladinFurnitureModBlocksItems.furnitureEntryMap.get(BasicChairBlock.class).getVariantToBlockMap().get(WoodVariantRegistry.OAK).asItem().getDefaultStack(); - } - - @Override - public void appendStacks(DefaultedList stacks) { - for (Item item : Registry.ITEM) { - item.appendStacks(this, stacks); - } - } -} diff --git a/common/src/main/resources/pfm.accesswidener b/common/src/main/resources/pfm.accesswidener index 5f4a67e8e..bc6e469e2 100644 --- a/common/src/main/resources/pfm.accesswidener +++ b/common/src/main/resources/pfm.accesswidener @@ -6,5 +6,4 @@ accessible method net/minecraft/data/server/BlockLootTableGenerator drops (Lnet/ accessible method net/minecraft/data/server/BlockLootTableGenerator dropsWithProperty (Lnet/minecraft/block/Block;Lnet/minecraft/state/property/Property;Ljava/lang/Comparable;)Lnet/minecraft/loot/LootTable$Builder; accessible class net/minecraft/data/server/AbstractTagProvider$ObjectBuilder accessible method net/minecraft/client/render/item/ItemRenderer renderBakedItemModel (Lnet/minecraft/client/render/model/BakedModel;Lnet/minecraft/item/ItemStack;IILnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;)V -accessible field net/minecraft/client/resource/language/LanguageManager language Lnet/minecraft/client/resource/language/LanguageDefinition; accessible field net/minecraft/block/AbstractBlock$Settings material Lnet/minecraft/block/Material;