From 9f0f26eb834b75d6de3c300c2b59d0bc2f2bf266 Mon Sep 17 00:00:00 2001 From: Tschipp <11649893+Tschipp@users.noreply.github.com> Date: Mon, 24 Apr 2023 22:24:54 +0200 Subject: [PATCH] Fixed Bugs --- .../tschipp/carryon/CarryOnCommonClient.java | 10 +- .../client/render/CarriedObjectRender.java | 29 +- .../client/render/CarryRenderHelper.java | 2 - .../carryon/common/carry/CarryOnData.java | 10 +- .../carryon/common/carry/PickupHandler.java | 3 + .../common/carry/PlacementHandler.java | 27 +- .../carryon/common/config/CarryConfig.java | 534 +++++++++--------- .../carryon/common/config/ListHandler.java | 3 +- .../carryon/common/scripting/Matchables.java | 12 +- .../config/fabric/ConfigLoaderImpl.java | 5 + .../java/tschipp/carryon/CarryOnForge.java | 1 - .../config/forge/ConfigLoaderImpl.java | 14 +- .../tschipp/carryon/events/ModBusEvents.java | 4 +- 13 files changed, 355 insertions(+), 299 deletions(-) diff --git a/Common/src/main/java/tschipp/carryon/CarryOnCommonClient.java b/Common/src/main/java/tschipp/carryon/CarryOnCommonClient.java index 4b26ff7..f33262c 100644 --- a/Common/src/main/java/tschipp/carryon/CarryOnCommonClient.java +++ b/Common/src/main/java/tschipp/carryon/CarryOnCommonClient.java @@ -14,11 +14,11 @@ public class CarryOnCommonClient Player player = mc.player; if(player != null) { CarryOnData carry = CarryOnDataManager.getCarryData(player); - if ((CarryOnKeybinds.carryKey.isUnbound() ? player.isShiftKeyDown() : CarryOnKeybinds.carryKey.isDown()) && !carry.isKeyPressed()) { + if ((CarryOnKeybinds.carryKey.isUnbound() ? player.isShiftKeyDown() : (CarryOnKeybinds.carryKey.isDown() || checkMouse())) && !carry.isKeyPressed()) { CarryOnKeybinds.onCarryKey(true); carry.setKeyPressed(true); CarryOnDataManager.setCarryData(player, carry); - } else if (!(CarryOnKeybinds.carryKey.isUnbound() ? player.isShiftKeyDown() : CarryOnKeybinds.carryKey.isDown()) && carry.isKeyPressed()) { + } else if (!(CarryOnKeybinds.carryKey.isUnbound() ? player.isShiftKeyDown() : (CarryOnKeybinds.carryKey.isDown() || checkMouse()) ) && carry.isKeyPressed()) { CarryOnKeybinds.onCarryKey(false); carry.setKeyPressed(false); CarryOnDataManager.setCarryData(player, carry); @@ -26,6 +26,12 @@ public class CarryOnCommonClient } } + private static boolean checkMouse() + { + Minecraft mc = Minecraft.getInstance(); + return (CarryOnKeybinds.carryKey.matchesMouse(0) && mc.mouseHandler.isLeftPressed()) || (CarryOnKeybinds.carryKey.matchesMouse(1) && mc.mouseHandler.isRightPressed()) || (CarryOnKeybinds.carryKey.matchesMouse(3) && mc.mouseHandler.isMiddlePressed()); + } + public static void onCarryClientTick() { Player player = Minecraft.getInstance().player; diff --git a/Common/src/main/java/tschipp/carryon/client/render/CarriedObjectRender.java b/Common/src/main/java/tschipp/carryon/client/render/CarriedObjectRender.java index 41f5b0e..b94f477 100644 --- a/Common/src/main/java/tschipp/carryon/client/render/CarriedObjectRender.java +++ b/Common/src/main/java/tschipp/carryon/client/render/CarriedObjectRender.java @@ -1,13 +1,16 @@ package tschipp.carryon.client.render; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.math.Vector3f; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.MultiBufferSource.BufferSource; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.EntityRenderDispatcher; +import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.HumanoidArm; @@ -26,6 +29,7 @@ import tschipp.carryon.common.scripting.CarryOnScript; import tschipp.carryon.common.scripting.CarryOnScript.ScriptRender; import tschipp.carryon.platform.Services; +import java.util.Map; import java.util.Optional; public class CarriedObjectRender @@ -133,10 +137,11 @@ public class CarriedObjectRender { } manager.setRenderShadow(true); + matrix.popPose(); + } // RenderSystem.disableAlphaTest(); - matrix.popPose(); } /** @@ -147,7 +152,6 @@ public class CarriedObjectRender public static void drawThirdPerson(float partialticks, PoseStack matrix) { Minecraft mc = Minecraft.getInstance(); Level level = mc.level; - BufferSource buffer = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder()); int light = 0; int perspective = CarryRenderHelper.getPerspective(); EntityRenderDispatcher manager = mc.getEntityRenderDispatcher(); @@ -155,10 +159,19 @@ public class CarriedObjectRender RenderSystem.enableBlend(); RenderSystem.disableCull(); RenderSystem.disableDepthTest(); + Map builders = Map.of( + RenderType.glint(), new BufferBuilder(RenderType.glint().bufferSize()), + RenderType.glintDirect(), new BufferBuilder(RenderType.glintDirect().bufferSize()), + RenderType.glintTranslucent(), new BufferBuilder(RenderType.glintTranslucent().bufferSize()), + RenderType.entityGlint(), new BufferBuilder(RenderType.entityGlint().bufferSize()), + RenderType.entityGlintDirect(), new BufferBuilder(RenderType.entityGlintDirect().bufferSize()) + ); + BufferSource buffer = MultiBufferSource.immediateWithBuffers(builders, Tesselator.getInstance().getBuilder()); for (Player player : level.players()) { try { + CarryOnData carry = CarryOnDataManager.getCarryData(player); if (perspective == 0 && player == mc.player && !(Services.PLATFORM.isModLoaded("firstperson") || Services.PLATFORM.isModLoaded("firstpersonmod"))) @@ -193,7 +206,6 @@ public class CarriedObjectRender RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); CarryRenderHelper.renderBakedModel(tileItem, copy, buffer, light, model); - buffer.endBatch(); matrix.popPose(); } else if (carry.isCarrying(CarryType.ENTITY)) { @@ -216,19 +228,26 @@ public class CarriedObjectRender RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); manager.render(entity, 0, 0, 0, 0f, 0, matrix, buffer, light); - buffer.endBatch(); - matrix.popPose(); manager.setRenderShadow(true); matrix.popPose(); } } + + } catch (Exception e) { } } + buffer.endLastBatch(); + + buffer.endBatch(RenderType.entitySolid(TextureAtlas.LOCATION_BLOCKS)); + buffer.endBatch(RenderType.entityCutout(TextureAtlas.LOCATION_BLOCKS)); + buffer.endBatch(RenderType.entityCutoutNoCull(TextureAtlas.LOCATION_BLOCKS)); + buffer.endBatch(RenderType.entitySmoothCutout(TextureAtlas.LOCATION_BLOCKS)); + RenderSystem.enableDepthTest(); RenderSystem.enableCull(); RenderSystem.disableBlend(); diff --git a/Common/src/main/java/tschipp/carryon/client/render/CarryRenderHelper.java b/Common/src/main/java/tschipp/carryon/client/render/CarryRenderHelper.java index 2c49577..5ad255d 100644 --- a/Common/src/main/java/tschipp/carryon/client/render/CarryRenderHelper.java +++ b/Common/src/main/java/tschipp/carryon/client/render/CarryRenderHelper.java @@ -1,12 +1,10 @@ package tschipp.carryon.client.render; -import com.mojang.authlib.minecraft.client.MinecraftClient; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Quaternion; import com.mojang.math.Vector3f; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType; import net.minecraft.client.renderer.entity.ItemRenderer; import net.minecraft.client.renderer.texture.OverlayTexture; diff --git a/Common/src/main/java/tschipp/carryon/common/carry/CarryOnData.java b/Common/src/main/java/tschipp/carryon/common/carry/CarryOnData.java index 62e7c52..d722a44 100644 --- a/Common/src/main/java/tschipp/carryon/common/carry/CarryOnData.java +++ b/Common/src/main/java/tschipp/carryon/common/carry/CarryOnData.java @@ -6,12 +6,14 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtOps; import net.minecraft.nbt.NbtUtils; import net.minecraft.nbt.Tag; +import net.minecraft.world.entity.AreaEffectCloud; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import tschipp.carryon.Constants; import tschipp.carryon.common.scripting.CarryOnScript; import javax.annotation.Nullable; @@ -121,7 +123,13 @@ public class CarryOnData { if(this.type != CarryType.ENTITY) throw new IllegalStateException("Called getEntity on data that contained " + this.type); - return EntityType.create(nbt.getCompound("entity"), level).orElseThrow(() -> new IllegalStateException("Called EntityType#create even though no entity data was present. Data: " + nbt.toString())); + var optionalEntity = EntityType.create(nbt.getCompound("entity"), level); + if(optionalEntity.isPresent()) + return optionalEntity.get(); + + Constants.LOG.error("Called EntityType#create even though no entity data was present. Data: " + nbt.toString()); + this.clear(); + return new AreaEffectCloud(level, 0, 0, 0); } public Optional getActiveScript() diff --git a/Common/src/main/java/tschipp/carryon/common/carry/PickupHandler.java b/Common/src/main/java/tschipp/carryon/common/carry/PickupHandler.java index 7a6077b..35bd2ca 100644 --- a/Common/src/main/java/tschipp/carryon/common/carry/PickupHandler.java +++ b/Common/src/main/java/tschipp/carryon/common/carry/PickupHandler.java @@ -137,6 +137,9 @@ public class PickupHandler { if (entity.invulnerableTime != 0) return false; + if(entity.isRemoved()) + return false; + if (entity instanceof TamableAnimal tame) { UUID owner = tame.getOwnerUUID(); diff --git a/Common/src/main/java/tschipp/carryon/common/carry/PlacementHandler.java b/Common/src/main/java/tschipp/carryon/common/carry/PlacementHandler.java index e8ff37b..c690490 100644 --- a/Common/src/main/java/tschipp/carryon/common/carry/PlacementHandler.java +++ b/Common/src/main/java/tschipp/carryon/common/carry/PlacementHandler.java @@ -1,7 +1,6 @@ package tschipp.carryon.common.carry; import net.minecraft.core.BlockPos; -import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvents; @@ -29,6 +28,8 @@ import tschipp.carryon.common.config.ListHandler; import tschipp.carryon.common.scripting.CarryOnScript.ScriptEffects; import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.function.BiFunction; @@ -284,30 +285,34 @@ public class PlacementHandler private static BlockPos getDeathPlacementPos(BlockState state, ServerPlayer player) { - MutableBlockPos pos = new MutableBlockPos(); BlockPos p = player.blockPosition(); int DISTANCE = 15; + List potentialPositions = new ArrayList<>(); + for (int j = 0; j < DISTANCE * 2; j++) { for (int i = 0; i < DISTANCE * 2; i++) { for (int k = 0; k < DISTANCE * 2; k++) { int x = i % 2 == 0 ? i / 2 : -(i / 2); int y = j % 2 == 0 ? j / 2 : -(j / 2); int z = k % 2 == 0 ? k / 2 : -(k / 2); - - pos.set(p.getX() + x, p.getY() + y, p.getZ() + z); - - BlockPlaceContext context = new BlockPlaceContext(player, InteractionHand.MAIN_HAND, ItemStack.EMPTY, BlockHitResult.miss(Vec3.atCenterOf(pos), Direction.DOWN, pos)); - - boolean canPlace = state.canSurvive(player.level, pos) && player.level.getBlockState(pos).canBeReplaced(context) && player.level.isUnobstructed(state, pos, CollisionContext.of(player)); - - if (canPlace) - return pos; + potentialPositions.add(new BlockPos(p.getX() + x, p.getY() + y, p.getZ() + z)); } } } + potentialPositions.sort(Comparator.comparingDouble(posA -> posA.distToCenterSqr(player.position()))); + + for(BlockPos potential : potentialPositions) + { + BlockPlaceContext context = new BlockPlaceContext(player, InteractionHand.MAIN_HAND, ItemStack.EMPTY, BlockHitResult.miss(Vec3.atCenterOf(potential), Direction.DOWN, potential)); + boolean canPlace = state.canSurvive(player.level, potential) && player.level.getBlockState(potential).canBeReplaced(context) && player.level.isUnobstructed(state, potential, CollisionContext.of(player)); + + if (canPlace) + return potential; + } + return p; } diff --git a/Common/src/main/java/tschipp/carryon/common/config/CarryConfig.java b/Common/src/main/java/tschipp/carryon/common/config/CarryConfig.java index abb406a..342baf0 100644 --- a/Common/src/main/java/tschipp/carryon/common/config/CarryConfig.java +++ b/Common/src/main/java/tschipp/carryon/common/config/CarryConfig.java @@ -5,302 +5,314 @@ import tschipp.carryon.config.annotations.Category; import tschipp.carryon.config.annotations.Config; import tschipp.carryon.config.annotations.Property; -public class CarryConfig { +public class CarryConfig +{ - @Config("carryon-common") - public static class Common { - //Settings - @Property( - type = PropertyType.CATEGORY, - description = "General Settings" - ) - public Settings settings = new Settings(); + @Config("carryon-common") + public static class Common + { + //Settings + @Property( + type = PropertyType.CATEGORY, + description = "General Settings" + ) + public Settings settings = new Settings(); - @Category("settings") - public static class Settings { - @Property( - type = PropertyType.DOUBLE, - description = "Maximum distance from where Blocks and Entities can be picked up", - minD = 0 - ) - public double maxDistance = 2.5; + @Category("settings") + public static class Settings + { + @Property( + type = PropertyType.DOUBLE, + description = "Maximum distance from where Blocks and Entities can be picked up", + minD = 0 + ) + public double maxDistance = 2.5; - @Property( - type = PropertyType.DOUBLE, - description = "Max width of entities that can be picked up in survival mode", - minD = 0, - maxD = 10 - ) - public double maxEntityWidth = 1.5; + @Property( + type = PropertyType.DOUBLE, + description = "Max width of entities that can be picked up in survival mode", + minD = 0, + maxD = 10 + ) + public double maxEntityWidth = 1.5; - @Property( - type = PropertyType.DOUBLE, - description = "Max height of entities that can be picked up in survival mode", - minD = 0, - maxD = 10 - ) - public double maxEntityHeight = 2.5; + @Property( + type = PropertyType.DOUBLE, + description = "Max height of entities that can be picked up in survival mode", + minD = 0, + maxD = 10 + ) + public double maxEntityHeight = 2.5; - @Property( - type = PropertyType.DOUBLE, - description = "Slowness multiplier for blocks", - minD = 0 - ) - public double blockSlownessMultiplier = 1; + @Property( + type = PropertyType.DOUBLE, + description = "Slowness multiplier for blocks", + minD = 0 + ) + public double blockSlownessMultiplier = 1; - @Property( - type = PropertyType.DOUBLE, - description = "Slowness multiplier for entities", - minD = 0 - ) - public double entitySlownessMultiplier = 1; + @Property( + type = PropertyType.DOUBLE, + description = "Slowness multiplier for entities", + minD = 0 + ) + public double entitySlownessMultiplier = 1; - @Property( - type = PropertyType.INT, - description = "Maximum stack limit for entities", - min = 1 - ) - public int maxEntityStackLimit = 10; + @Property( + type = PropertyType.INT, + description = "Maximum stack limit for entities", + min = 1 + ) + public int maxEntityStackLimit = 10; - @Property( - type = PropertyType.BOOLEAN, - description = "More complex Tile Entities slow down the player more" - ) - public boolean heavyTiles = true; + @Property( + type = PropertyType.BOOLEAN, + description = "More complex Tile Entities slow down the player more" + ) + public boolean heavyTiles = true; - @Property( - type = PropertyType.BOOLEAN, - description = "Allow all blocks to be picked up, not just Tile Entites. White/Blacklist will still be respected." - ) - public boolean pickupAllBlocks = false; + @Property( + type = PropertyType.BOOLEAN, + description = "Allow all blocks to be picked up, not just Tile Entites. White/Blacklist will still be respected." + ) + public boolean pickupAllBlocks = false; - @Property( - type = PropertyType.BOOLEAN, - description = "Whether Blocks and Entities slow the creative player down when carried" - ) - public boolean slownessInCreative = true; + @Property( + type = PropertyType.BOOLEAN, + description = "Whether Blocks and Entities slow the creative player down when carried" + ) + public boolean slownessInCreative = true; - @Property( - type = PropertyType.BOOLEAN, - description = "Whether hostile mobs should be able to picked up in survival mode" - ) - public boolean pickupHostileMobs = false; + @Property( + type = PropertyType.BOOLEAN, + description = "Whether hostile mobs should be able to picked up in survival mode" + ) + public boolean pickupHostileMobs = false; - @Property( - type = PropertyType.BOOLEAN, - description = "Larger Entities slow down the player more" - ) - public boolean heavyEntities = true; + @Property( + type = PropertyType.BOOLEAN, + description = "Larger Entities slow down the player more" + ) + public boolean heavyEntities = true; - @Property( - type = PropertyType.BOOLEAN, - description = "Allow babies to be carried even when adult mob is blacklisted (or not whitelisted)" - ) - public boolean allowBabies = false; + @Property( + type = PropertyType.BOOLEAN, + description = "Allow babies to be carried even when adult mob is blacklisted (or not whitelisted)" + ) + public boolean allowBabies = false; - @Property( - type = PropertyType.BOOLEAN, - description = "Use Whitelist instead of Blacklist for Blocks" - ) - public boolean useWhitelistBlocks = false; + @Property( + type = PropertyType.BOOLEAN, + description = "Use Whitelist instead of Blacklist for Blocks" + ) + public boolean useWhitelistBlocks = false; - @Property( - type = PropertyType.BOOLEAN, - description = "Use Whitelist instead of Blacklist for Entities" - ) - public boolean useWhitelistEntities = false; + @Property( + type = PropertyType.BOOLEAN, + description = "Use Whitelist instead of Blacklist for Entities" + ) + public boolean useWhitelistEntities = false; - @Property( - type = PropertyType.BOOLEAN, - description = "Use Whitelist instead of Blacklist for Stacking" - ) - public boolean useWhitelistStacking = false; + @Property( + type = PropertyType.BOOLEAN, + description = "Use Whitelist instead of Blacklist for Stacking" + ) + public boolean useWhitelistStacking = false; - @Property( - type = PropertyType.BOOLEAN, - description = "Whether the player can hit blocks and entities while carrying or not" - ) - public boolean hitWhileCarrying = false; + @Property( + type = PropertyType.BOOLEAN, + description = "Whether the player can hit blocks and entities while carrying or not" + ) + public boolean hitWhileCarrying = false; - @Property( - type = PropertyType.BOOLEAN, - description = "Whether the player drops the carried object when hit or not" - ) - public boolean dropCarriedWhenHit = false; + @Property( + type = PropertyType.BOOLEAN, + description = "Whether the player drops the carried object when hit or not" + ) + public boolean dropCarriedWhenHit = false; - @Property( - type = PropertyType.BOOLEAN, - description = "Use custom Pickup Scripts. Having this set to false, will not allow you to run scripts, but will increase your performance" - ) - public boolean useScripts = false; + @Property( + type = PropertyType.BOOLEAN, + description = "Use custom Pickup Scripts. Having this set to false, will not allow you to run scripts, but will increase your performance" + ) + public boolean useScripts = false; - @Property( - type = PropertyType.BOOLEAN, - description = "Allows entities to be stacked on top of each other" - ) - public boolean stackableEntities = true; + @Property( + type = PropertyType.BOOLEAN, + description = "Allows entities to be stacked on top of each other" + ) + public boolean stackableEntities = true; - @Property( - type = PropertyType.BOOLEAN, - description = "Whether entities' size matters when stacking or not. This means that larger entities cannot be stacked on smaller ones" - ) - public boolean entitySizeMattersStacking = true; + @Property( + type = PropertyType.BOOLEAN, + description = "Whether entities' size matters when stacking or not. This means that larger entities cannot be stacked on smaller ones" + ) + public boolean entitySizeMattersStacking = true; - @Property( - type = PropertyType.STRING_ARRAY, - description = "Usually all the block state information is retained when placing a block that was picked up. But some information is changed to a modified property, like rotation or orientation. In this list, add additional properties that should NOT be saved and instead be updated when placed. Format: modid:block[propertyname]. Note: You don't need to add an entry for every subtype of a same block. For example, we only add an entry for one type of slab, but the change is applied to all slabs." - ) - public String[] placementStateExceptions = { - "minecraft:chest[type]", - "minecraft:stone_button[face]", - "minecraft:vine[north,east,south,west,up]", - "minecraft:creeper_head[rotation]", - "minecraft:glow_lichen[north,east,south,west,up,down]", - "minecraft:oak_sign[rotation]", - "minecraft:oak_trapdoor[half]", - }; + @Property( + type = PropertyType.STRING_ARRAY, + description = "Usually all the block state information is retained when placing a block that was picked up. But some information is changed to a modified property, like rotation or orientation. In this list, add additional properties that should NOT be saved and instead be updated when placed. Format: modid:block[propertyname]. Note: You don't need to add an entry for every subtype of a same block. For example, we only add an entry for one type of slab, but the change is applied to all slabs." + ) + public String[] placementStateExceptions = { + "minecraft:chest[type]", + "minecraft:stone_button[face]", + "minecraft:vine[north,east,south,west,up]", + "minecraft:creeper_head[rotation]", + "minecraft:glow_lichen[north,east,south,west,up,down]", + "minecraft:oak_sign[rotation]", + "minecraft:oak_trapdoor[half]", + }; - @Property( - type = PropertyType.BOOLEAN, - description = "Whether Players can be picked up. Creative players can't be picked up in Survival Mode" - ) - public boolean pickupPlayers = true; - } + @Property( + type = PropertyType.BOOLEAN, + description = "Whether Players can be picked up. Creative players can't be picked up in Survival Mode" + ) + public boolean pickupPlayers = true; + } - @Property( - type = PropertyType.CATEGORY, - description = "Whitelist. Read about the format here: https://github.com/Tschipp/CarryOn/wiki/Black---and-Whitelist-Config" - ) + @Property( + type = PropertyType.CATEGORY, + description = "Whitelist. Read about the format here: https://github.com/Tschipp/CarryOn/wiki/Black---and-Whitelist-Config" + ) - //Whitelist - public Whitelist whitelist = new Whitelist(); - @Category("whitelist") - public static class Whitelist { - @Property( - type = PropertyType.STRING_ARRAY, - description = "Entities that CAN be picked up (useWhitelistEntities must be true)" - ) - public String[] allowedEntities = {}; + //Whitelist + public Whitelist whitelist = new Whitelist(); - @Property( - type = PropertyType.STRING_ARRAY, - description = "Blocks that CAN be picked up (useWhitelistBlocks must be true)" - ) - public String[] allowedBlocks = {}; + @Category("whitelist") + public static class Whitelist + { + @Property( + type = PropertyType.STRING_ARRAY, + description = "Entities that CAN be picked up (useWhitelistEntities must be true)" + ) + public String[] allowedEntities = {}; - @Property( - type = PropertyType.STRING_ARRAY, - description = "Entities that CAN have other entities stacked on top of them (useWhitelistStacking must be true)" - ) - public String[] allowedStacking = {}; - } + @Property( + type = PropertyType.STRING_ARRAY, + description = "Blocks that CAN be picked up (useWhitelistBlocks must be true)" + ) + public String[] allowedBlocks = {}; - //Blacklist - @Property( - type = PropertyType.CATEGORY, - description = "Blacklist. Read about the format here: https://github.com/Tschipp/CarryOn/wiki/Black---and-Whitelist-Config" - ) - public Blacklist blacklist = new Blacklist(); - @Category("blacklist") - public static class Blacklist { - @Property( - type = PropertyType.STRING_ARRAY, - description = "Blocks that cannot be picked up" - ) - public String[] forbiddenTiles = { - "#forge:immovable", "#forge:relocation_not_supported", "minecraft:end_portal", "minecraft:piston_head", - "minecraft:end_gateway", "minecraft:tall_grass", "minecraft:large_fern", "minecraft:peony", - "minecraft:rose_bush", "minecraft:lilac", "minecraft:sunflower", "minecraft:*_bed", - "minecraft:*_door", "minecraft:big_dripleaf_stem", "minecraft:waterlily", "minecraft:cake", - "minecraft:nether_portal", "minecraft:tall_seagrass", "animania:block_trough", - "animania:block_invisiblock", "colossalchests:*", "ic2:*", "bigreactors:*", "forestry:*", - "tconstruct:*", "rustic:*", "botania:*", "astralsorcery:*", "quark:colored_bed_*", - "immersiveengineering:*", "embers:block_furnace", "embers:ember_bore", - "embers:ember_activator", "embers:mixer", "embers:heat_coil", "embers:large_tank", - "embers:crystal_cell", "embers:alchemy_pedestal", "embers:boiler", "embers:combustor", - "embers:catalzyer", "embers:field_chart", "embers:inferno_forge", - "storagedrawers:framingtable", "skyresources:*", "lootbags:*", "exsartagine:*", - "aquamunda:tank", "opencomputers:*", "malisisdoors:*", "industrialforegoing:*", - "minecolonies:*", "thaumcraft:pillar*", "thaumcraft:infernal_furnace", - "thaumcraft:placeholder*", "thaumcraft:infusion_matrix", "thaumcraft:golem_builder", - "thaumcraft:thaumatorium*", "magneticraft:oil_heater", "magneticraft:solar_panel", - "magneticraft:steam_engine", "magneticraft:shelving_unit", "magneticraft:grinder", - "magneticraft:sieve", "magneticraft:solar_tower", "magneticraft:solar_mirror", - "magneticraft:container", "magneticraft:pumpjack", "magneticraft:solar_panel", - "magneticraft:refinery", "magneticraft:oil_heater", "magneticraft:hydraulic_press", - "magneticraft:multiblock_gap", "refinedstorage:*", "mcmultipart:*", "enderstorage:*", - "betterstorage:*", "practicallogistics2:*", "wearablebackpacks:*", "rftools:screen", - "rftools:creative_screen", "create:*", "magic_doorknob:*", "iceandfire:*", "ftbquests:*", - "waystones:*", "contact:*", "framedblocks:*" - }; + @Property( + type = PropertyType.STRING_ARRAY, + description = "Entities that CAN have other entities stacked on top of them (useWhitelistStacking must be true)" + ) + public String[] allowedStacking = {}; + } - @Property( - type = PropertyType.STRING_ARRAY, - description = "Entities that cannot be picked up" - ) - public String[] forbiddenEntities = { - "minecraft:end_crystal", "minecraft:ender_dragon", "minecraft:ghast", - "minecraft:shulker", "minecraft:leash_knot", "minecraft:armor_stand", - "minecraft:item_frame", "minecraft:painting", "minecraft:shulker_bullet", - "animania:hamster", "animania:ferret*", "animania:hedgehog*", "animania:cart", - "animania:wagon", "mynko:*", "pixelmon:*", "mocreatures:*", "quark:totem", "vehicle:*" - }; + //Blacklist + @Property( + type = PropertyType.CATEGORY, + description = "Blacklist. Read about the format here: https://github.com/Tschipp/CarryOn/wiki/Black---and-Whitelist-Config" + ) + public Blacklist blacklist = new Blacklist(); - @Property( - type = PropertyType.STRING_ARRAY, - description = "Entities that cannot have other entities stacked on top of them" - ) - public String[] forbiddenStacking = { - "minecraft:horse" - }; - } + @Category("blacklist") + public static class Blacklist + { + @Property( + type = PropertyType.STRING_ARRAY, + description = "Blocks that cannot be picked up" + ) + public String[] forbiddenTiles = { + "#forge:immovable", "#forge:relocation_not_supported", "minecraft:end_portal", "minecraft:piston_head", + "minecraft:end_gateway", "minecraft:tall_grass", "minecraft:large_fern", "minecraft:peony", + "minecraft:rose_bush", "minecraft:lilac", "minecraft:sunflower", "minecraft:*_bed", + "minecraft:*_door", "minecraft:big_dripleaf_stem", "minecraft:waterlily", "minecraft:cake", + "minecraft:nether_portal", "minecraft:tall_seagrass", "animania:block_trough", + "animania:block_invisiblock", "colossalchests:*", "ic2:*", "bigreactors:*", "forestry:*", + "tconstruct:*", "rustic:*", "botania:*", "astralsorcery:*", "quark:colored_bed_*", + "immersiveengineering:*", "embers:block_furnace", "embers:ember_bore", + "embers:ember_activator", "embers:mixer", "embers:heat_coil", "embers:large_tank", + "embers:crystal_cell", "embers:alchemy_pedestal", "embers:boiler", "embers:combustor", + "embers:catalzyer", "embers:field_chart", "embers:inferno_forge", + "storagedrawers:framingtable", "skyresources:*", "lootbags:*", "exsartagine:*", + "aquamunda:tank", "opencomputers:*", "malisisdoors:*", "industrialforegoing:*", + "minecolonies:*", "thaumcraft:pillar*", "thaumcraft:infernal_furnace", + "thaumcraft:placeholder*", "thaumcraft:infusion_matrix", "thaumcraft:golem_builder", + "thaumcraft:thaumatorium*", "magneticraft:oil_heater", "magneticraft:solar_panel", + "magneticraft:steam_engine", "magneticraft:shelving_unit", "magneticraft:grinder", + "magneticraft:sieve", "magneticraft:solar_tower", "magneticraft:solar_mirror", + "magneticraft:container", "magneticraft:pumpjack", "magneticraft:solar_panel", + "magneticraft:refinery", "magneticraft:oil_heater", "magneticraft:hydraulic_press", + "magneticraft:multiblock_gap", "refinedstorage:*", "mcmultipart:*", "enderstorage:*", + "betterstorage:*", "practicallogistics2:*", "wearablebackpacks:*", "rftools:screen", + "rftools:creative_screen", "create:*", "magic_doorknob:*", "iceandfire:*", "ftbquests:*", + "waystones:*", "contact:*", "framedblocks:*", "securitycraft:*", "forgemultipartcbe:*", "integrateddynamics:cable", + "mekanismgenerators:wind_generator" + }; - //Custom Pickup Conditions - @Property( - type = PropertyType.CATEGORY, - description = "Custom Pickup Conditions. Read about the format here: https://github.com/Tschipp/CarryOn/wiki/Custom-Pickup-Condition-Config" - ) - public CustomPickupConditions customPickupConditions = new CustomPickupConditions(); - @Category("customPickupConditions") - public static class CustomPickupConditions { - @Property( - type = PropertyType.STRING_ARRAY, - description = "Custom Pickup Conditions for Blocks" - ) - public String[] customPickupConditionsBlocks = {}; + @Property( + type = PropertyType.STRING_ARRAY, + description = "Entities that cannot be picked up" + ) + public String[] forbiddenEntities = { + "minecraft:end_crystal", "minecraft:ender_dragon", "minecraft:ghast", + "minecraft:shulker", "minecraft:leash_knot", "minecraft:armor_stand", + "minecraft:item_frame", "minecraft:painting", "minecraft:shulker_bullet", + "animania:hamster", "animania:ferret*", "animania:hedgehog*", "animania:cart", + "animania:wagon", "mynko:*", "pixelmon:*", "mocreatures:*", "quark:totem", "vehicle:*", + "securitycraft:*", "taterzens:npc", "easy_npc:*" + }; - @Property( - type = PropertyType.STRING_ARRAY, - description = "Custom Pickup Conditions for Entities" - ) - public String[] customPickupConditionsEntities = {}; - } - } + @Property( + type = PropertyType.STRING_ARRAY, + description = "Entities that cannot have other entities stacked on top of them" + ) + public String[] forbiddenStacking = { + "minecraft:horse" + }; + } - @Config("carryon-client") - public static class Client { + //Custom Pickup Conditions + @Property( + type = PropertyType.CATEGORY, + description = "Custom Pickup Conditions. Read about the format here: https://github.com/Tschipp/CarryOn/wiki/Custom-Pickup-Condition-Config" + ) + public CustomPickupConditions customPickupConditions = new CustomPickupConditions(); - @Property( - type = PropertyType.BOOLEAN, - description = "If the front of the Tile Entities should face the player or should face outward" - ) - public boolean facePlayer = false; + @Category("customPickupConditions") + public static class CustomPickupConditions + { + @Property( + type = PropertyType.STRING_ARRAY, + description = "Custom Pickup Conditions for Blocks" + ) + public String[] customPickupConditionsBlocks = {}; - @Property( - type = PropertyType.BOOLEAN, - description = "Arms should render on sides when carrying. Set to false if you experience issues with mods that replace the player model (like MoBends, etc)" - ) - public boolean renderArms = true; + @Property( + type = PropertyType.STRING_ARRAY, + description = "Custom Pickup Conditions for Entities" + ) + public String[] customPickupConditionsEntities = {}; + } + } - @Property( - type = PropertyType.STRING_ARRAY, - description = "Model Overrides based on NBT or Meta. Advanced users only! Read about the format here: https://github.com/Tschipp/CarryOn/wiki/Model-Override-Config" - ) - public String[] modelOverrides = { - "minecraft:redstone_wire->(item)minecraft:redstone", - "minecraft:bamboo_sapling->(block)minecraft:bamboo", - "minecraft:candle_cake->(block)minecraft:cake" - }; - } + @Config("carryon-client") + public static class Client + { + + @Property( + type = PropertyType.BOOLEAN, + description = "If the front of the Tile Entities should face the player or should face outward" + ) + public boolean facePlayer = false; + + @Property( + type = PropertyType.BOOLEAN, + description = "Arms should render on sides when carrying. Set to false if you experience issues with mods that replace the player model (like MoBends, etc)" + ) + public boolean renderArms = true; + + @Property( + type = PropertyType.STRING_ARRAY, + description = "Model Overrides based on NBT or Meta. Advanced users only! Read about the format here: https://github.com/Tschipp/CarryOn/wiki/Model-Override-Config" + ) + public String[] modelOverrides = { + "minecraft:redstone_wire->(item)minecraft:redstone", + "minecraft:bamboo_sapling->(block)minecraft:bamboo", + "minecraft:candle_cake->(block)minecraft:cake" + }; + } } diff --git a/Common/src/main/java/tschipp/carryon/common/config/ListHandler.java b/Common/src/main/java/tschipp/carryon/common/config/ListHandler.java index ce7f7b9..e938c4b 100644 --- a/Common/src/main/java/tschipp/carryon/common/config/ListHandler.java +++ b/Common/src/main/java/tschipp/carryon/common/config/ListHandler.java @@ -1,6 +1,5 @@ package tschipp.carryon.common.config; -import com.mojang.datafixers.kinds.Const; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; @@ -33,7 +32,6 @@ public class ListHandler { private static Set> PROPERTY_EXCEPTION_CLASSES = new HashSet<>(); - public static boolean isPermitted(Block block) { if(Constants.COMMON_CONFIG.settings.useWhitelistBlocks) @@ -142,6 +140,7 @@ public class ListHandler { } } } + } private static void addTag(String tag, Map> tagMap, List> tags) { diff --git a/Common/src/main/java/tschipp/carryon/common/scripting/Matchables.java b/Common/src/main/java/tschipp/carryon/common/scripting/Matchables.java index 90242b0..f6c738a 100644 --- a/Common/src/main/java/tschipp/carryon/common/scripting/Matchables.java +++ b/Common/src/main/java/tschipp/carryon/common/scripting/Matchables.java @@ -29,9 +29,7 @@ public final class Matchables private static float getValueFromStringOrDefault(String toGetFrom, String key, float defaultVal) { Optional val = getValueFromString(toGetFrom, key); - if(val.isPresent()) - return val.get(); - return defaultVal; + return val.orElse(defaultVal); } private static Optional getValueFromString(String toGetFrom, String key) @@ -240,9 +238,9 @@ public final class Matchables int iG = cond.indexOf(">"); int iL = cond.indexOf("<"); - if (iG == -1 ? true : iE < iG && iL == -1 ? true : iE < iL && iE != -1) + if (iG == -1 || (iE < iG && iL == -1 || iE < iL && iE != -1)) numb = cond.substring(iE); - else if (iE == -1 ? true : iG < iE && iL == -1 ? true : iG < iL && iG != -1) + else if (iE == -1 || (iG < iE && iL == -1 || iG < iL && iG != -1)) numb = cond.substring(iG); else numb = cond.substring(iL); @@ -277,8 +275,8 @@ public final class Matchables if (cond == null || cond.isEmpty()) return true; - BlockPos blockpos = new BlockPos(getValueFromStringOrDefault(cond, "x", 0), getValueFromStringOrDefault(cond, "y", 0), getValueFromStringOrDefault(cond, "z", 0)); - BlockPos expand = new BlockPos(getValueFromStringOrDefault(cond, "dx", 0), getValueFromStringOrDefault(cond, "dy", 0), getValueFromStringOrDefault(cond, "dz", 0)); + BlockPos blockpos = new BlockPos((int) getValueFromStringOrDefault(cond, "x", 0), (int) getValueFromStringOrDefault(cond, "y", 0), (int) getValueFromStringOrDefault(cond, "z", 0)); + BlockPos expand = new BlockPos((int) getValueFromStringOrDefault(cond, "dx", 0), (int) getValueFromStringOrDefault(cond, "dy", 0), (int) getValueFromStringOrDefault(cond, "dz", 0)); BlockPos expanded = blockpos.offset(expand); BlockPos pos = elem.blockPosition(); diff --git a/Fabric/src/main/java/tschipp/carryon/config/fabric/ConfigLoaderImpl.java b/Fabric/src/main/java/tschipp/carryon/config/fabric/ConfigLoaderImpl.java index 76a48ad..4c05d3c 100644 --- a/Fabric/src/main/java/tschipp/carryon/config/fabric/ConfigLoaderImpl.java +++ b/Fabric/src/main/java/tschipp/carryon/config/fabric/ConfigLoaderImpl.java @@ -31,6 +31,11 @@ public class ConfigLoaderImpl { FileUtils.write(cfgFile, GSON.toJson(entry.getKey()), StandardCharsets.UTF_8); } else { JsonObject cfgJson = GSON.fromJson(FileUtils.readFileToString(cfgFile, StandardCharsets.UTF_8), JsonObject.class); + if(cfgJson == null) + { + cfgPath.toFile().mkdirs(); + FileUtils.write(cfgFile, GSON.toJson(entry.getKey()), StandardCharsets.UTF_8); + } FileUtils.write(cfgFile, GSON.toJson(loadConfig(entry.getValue(), cfgJson)), StandardCharsets.UTF_8); } } diff --git a/Forge/src/main/java/tschipp/carryon/CarryOnForge.java b/Forge/src/main/java/tschipp/carryon/CarryOnForge.java index 19635f9..2ae7fd1 100644 --- a/Forge/src/main/java/tschipp/carryon/CarryOnForge.java +++ b/Forge/src/main/java/tschipp/carryon/CarryOnForge.java @@ -20,7 +20,6 @@ public class CarryOnForge { // This method is invoked by the Forge mod loader when it is ready // to load your mod. You can access Forge and Common code in this // project. - // Use Forge to bootstrap the Common mod. CarryOnCommon.registerConfig(); diff --git a/Forge/src/main/java/tschipp/carryon/config/forge/ConfigLoaderImpl.java b/Forge/src/main/java/tschipp/carryon/config/forge/ConfigLoaderImpl.java index 97b2a36..13e3455 100644 --- a/Forge/src/main/java/tschipp/carryon/config/forge/ConfigLoaderImpl.java +++ b/Forge/src/main/java/tschipp/carryon/config/forge/ConfigLoaderImpl.java @@ -11,10 +11,7 @@ import net.minecraftforge.fml.event.config.ModConfigEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import tschipp.carryon.config.*; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class ConfigLoaderImpl { @@ -95,7 +92,14 @@ public class ConfigLoaderImpl { case BOOLEAN -> builder.define(data.getId(), data.getBoolean()); case INT -> builder.defineInRange(data.getId(), data.getInt(), annotationData.min(), annotationData.max()); case DOUBLE -> builder.defineInRange(data.getId(), data.getDouble(), annotationData.minD(), annotationData.maxD()); - case STRING_ARRAY -> builder.defineList(data.getId(), Arrays.asList(data.getStringArray()), obj -> true); + case STRING_ARRAY -> builder.defineListAllowEmpty(List.of(data.getId()), () -> { + try { + return Arrays.asList(data.getStringArray()); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return new ArrayList<>(); + }, obj -> obj instanceof String); default -> throw new IllegalAccessException("Unknown property type."); } } diff --git a/Forge/src/main/java/tschipp/carryon/events/ModBusEvents.java b/Forge/src/main/java/tschipp/carryon/events/ModBusEvents.java index be71979..17e11dc 100644 --- a/Forge/src/main/java/tschipp/carryon/events/ModBusEvents.java +++ b/Forge/src/main/java/tschipp/carryon/events/ModBusEvents.java @@ -5,7 +5,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.InterModComms; import net.minecraftforge.fml.InterModComms.IMCMessage; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent; +import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import tschipp.carryon.Constants; import tschipp.carryon.client.modeloverride.ModelOverrideHandler; import tschipp.carryon.common.config.ListHandler; @@ -16,7 +16,7 @@ import java.util.stream.Stream; public class ModBusEvents { @SubscribeEvent(priority = EventPriority.LOW) - public void serverLoad(FMLDedicatedServerSetupEvent event) + public static void serverLoad(FMLCommonSetupEvent event) { Stream messages = InterModComms.getMessages(Constants.MOD_ID);