Fixed Bugs

This commit is contained in:
Tschipp 2023-04-24 22:24:54 +02:00
parent e06962c125
commit 9f0f26eb83
13 changed files with 355 additions and 299 deletions

View File

@ -14,11 +14,11 @@ public class CarryOnCommonClient
Player player = mc.player; Player player = mc.player;
if(player != null) { if(player != null) {
CarryOnData carry = CarryOnDataManager.getCarryData(player); 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); CarryOnKeybinds.onCarryKey(true);
carry.setKeyPressed(true); carry.setKeyPressed(true);
CarryOnDataManager.setCarryData(player, carry); 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); CarryOnKeybinds.onCarryKey(false);
carry.setKeyPressed(false); carry.setKeyPressed(false);
CarryOnDataManager.setCarryData(player, carry); 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() public static void onCarryClientTick()
{ {
Player player = Minecraft.getInstance().player; Player player = Minecraft.getInstance().player;

View File

@ -1,13 +1,16 @@
package tschipp.carryon.client.render; package tschipp.carryon.client.render;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.math.Vector3f; import com.mojang.math.Vector3f;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.MultiBufferSource.BufferSource; 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.entity.EntityRenderDispatcher;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.resources.model.BakedModel; import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.HumanoidArm; 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.common.scripting.CarryOnScript.ScriptRender;
import tschipp.carryon.platform.Services; import tschipp.carryon.platform.Services;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
public class CarriedObjectRender public class CarriedObjectRender
@ -133,10 +137,11 @@ public class CarriedObjectRender
{ {
} }
manager.setRenderShadow(true); manager.setRenderShadow(true);
matrix.popPose();
} }
// RenderSystem.disableAlphaTest(); // RenderSystem.disableAlphaTest();
matrix.popPose();
} }
/** /**
@ -147,7 +152,6 @@ public class CarriedObjectRender
public static void drawThirdPerson(float partialticks, PoseStack matrix) { public static void drawThirdPerson(float partialticks, PoseStack matrix) {
Minecraft mc = Minecraft.getInstance(); Minecraft mc = Minecraft.getInstance();
Level level = mc.level; Level level = mc.level;
BufferSource buffer = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
int light = 0; int light = 0;
int perspective = CarryRenderHelper.getPerspective(); int perspective = CarryRenderHelper.getPerspective();
EntityRenderDispatcher manager = mc.getEntityRenderDispatcher(); EntityRenderDispatcher manager = mc.getEntityRenderDispatcher();
@ -155,10 +159,19 @@ public class CarriedObjectRender
RenderSystem.enableBlend(); RenderSystem.enableBlend();
RenderSystem.disableCull(); RenderSystem.disableCull();
RenderSystem.disableDepthTest(); RenderSystem.disableDepthTest();
Map<RenderType, BufferBuilder> 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()) for (Player player : level.players())
{ {
try { try {
CarryOnData carry = CarryOnDataManager.getCarryData(player); CarryOnData carry = CarryOnDataManager.getCarryData(player);
if (perspective == 0 && player == mc.player && !(Services.PLATFORM.isModLoaded("firstperson") || Services.PLATFORM.isModLoaded("firstpersonmod"))) 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); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
CarryRenderHelper.renderBakedModel(tileItem, copy, buffer, light, model); CarryRenderHelper.renderBakedModel(tileItem, copy, buffer, light, model);
buffer.endBatch();
matrix.popPose(); matrix.popPose();
} else if (carry.isCarrying(CarryType.ENTITY)) { } else if (carry.isCarrying(CarryType.ENTITY)) {
@ -216,19 +228,26 @@ public class CarriedObjectRender
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
manager.render(entity, 0, 0, 0, 0f, 0, matrix, buffer, light); manager.render(entity, 0, 0, 0, 0f, 0, matrix, buffer, light);
buffer.endBatch();
matrix.popPose(); matrix.popPose();
manager.setRenderShadow(true); manager.setRenderShadow(true);
matrix.popPose(); matrix.popPose();
} }
} }
} }
catch (Exception e) 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.enableDepthTest();
RenderSystem.enableCull(); RenderSystem.enableCull();
RenderSystem.disableBlend(); RenderSystem.disableBlend();

View File

@ -1,12 +1,10 @@
package tschipp.carryon.client.render; package tschipp.carryon.client.render;
import com.mojang.authlib.minecraft.client.MinecraftClient;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Quaternion; import com.mojang.math.Quaternion;
import com.mojang.math.Vector3f; import com.mojang.math.Vector3f;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource; 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.block.model.ItemTransforms.TransformType;
import net.minecraft.client.renderer.entity.ItemRenderer; import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.texture.OverlayTexture;

View File

@ -6,12 +6,14 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps; import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.NbtUtils; import net.minecraft.nbt.NbtUtils;
import net.minecraft.nbt.Tag; import net.minecraft.nbt.Tag;
import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import tschipp.carryon.Constants;
import tschipp.carryon.common.scripting.CarryOnScript; import tschipp.carryon.common.scripting.CarryOnScript;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -121,7 +123,13 @@ public class CarryOnData {
if(this.type != CarryType.ENTITY) if(this.type != CarryType.ENTITY)
throw new IllegalStateException("Called getEntity on data that contained " + this.type); 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<CarryOnScript> getActiveScript() public Optional<CarryOnScript> getActiveScript()

View File

@ -137,6 +137,9 @@ public class PickupHandler {
if (entity.invulnerableTime != 0) if (entity.invulnerableTime != 0)
return false; return false;
if(entity.isRemoved())
return false;
if (entity instanceof TamableAnimal tame) if (entity instanceof TamableAnimal tame)
{ {
UUID owner = tame.getOwnerUUID(); UUID owner = tame.getOwnerUUID();

View File

@ -1,7 +1,6 @@
package tschipp.carryon.common.carry; package tschipp.carryon.common.carry;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundEvents;
@ -29,6 +28,8 @@ import tschipp.carryon.common.config.ListHandler;
import tschipp.carryon.common.scripting.CarryOnScript.ScriptEffects; import tschipp.carryon.common.scripting.CarryOnScript.ScriptEffects;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
@ -284,28 +285,32 @@ public class PlacementHandler
private static BlockPos getDeathPlacementPos(BlockState state, ServerPlayer player) private static BlockPos getDeathPlacementPos(BlockState state, ServerPlayer player)
{ {
MutableBlockPos pos = new MutableBlockPos();
BlockPos p = player.blockPosition(); BlockPos p = player.blockPosition();
int DISTANCE = 15; int DISTANCE = 15;
List<BlockPos> potentialPositions = new ArrayList<>();
for (int j = 0; j < DISTANCE * 2; j++) { for (int j = 0; j < DISTANCE * 2; j++) {
for (int i = 0; i < DISTANCE * 2; i++) { for (int i = 0; i < DISTANCE * 2; i++) {
for (int k = 0; k < DISTANCE * 2; k++) { for (int k = 0; k < DISTANCE * 2; k++) {
int x = i % 2 == 0 ? i / 2 : -(i / 2); int x = i % 2 == 0 ? i / 2 : -(i / 2);
int y = j % 2 == 0 ? j / 2 : -(j / 2); int y = j % 2 == 0 ? j / 2 : -(j / 2);
int z = k % 2 == 0 ? k / 2 : -(k / 2); int z = k % 2 == 0 ? k / 2 : -(k / 2);
potentialPositions.add(new BlockPos(p.getX() + x, p.getY() + y, p.getZ() + z));
}
}
}
pos.set(p.getX() + x, p.getY() + y, p.getZ() + z); potentialPositions.sort(Comparator.comparingDouble(posA -> posA.distToCenterSqr(player.position())));
BlockPlaceContext context = new BlockPlaceContext(player, InteractionHand.MAIN_HAND, ItemStack.EMPTY, BlockHitResult.miss(Vec3.atCenterOf(pos), Direction.DOWN, pos)); for(BlockPos potential : potentialPositions)
{
boolean canPlace = state.canSurvive(player.level, pos) && player.level.getBlockState(pos).canBeReplaced(context) && player.level.isUnobstructed(state, pos, CollisionContext.of(player)); 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) if (canPlace)
return pos; return potential;
}
}
} }
return p; return p;

View File

@ -5,10 +5,12 @@ import tschipp.carryon.config.annotations.Category;
import tschipp.carryon.config.annotations.Config; import tschipp.carryon.config.annotations.Config;
import tschipp.carryon.config.annotations.Property; import tschipp.carryon.config.annotations.Property;
public class CarryConfig { public class CarryConfig
{
@Config("carryon-common") @Config("carryon-common")
public static class Common { public static class Common
{
//Settings //Settings
@Property( @Property(
type = PropertyType.CATEGORY, type = PropertyType.CATEGORY,
@ -17,7 +19,8 @@ public class CarryConfig {
public Settings settings = new Settings(); public Settings settings = new Settings();
@Category("settings") @Category("settings")
public static class Settings { public static class Settings
{
@Property( @Property(
type = PropertyType.DOUBLE, type = PropertyType.DOUBLE,
description = "Maximum distance from where Blocks and Entities can be picked up", description = "Maximum distance from where Blocks and Entities can be picked up",
@ -174,8 +177,10 @@ public class CarryConfig {
//Whitelist //Whitelist
public Whitelist whitelist = new Whitelist(); public Whitelist whitelist = new Whitelist();
@Category("whitelist") @Category("whitelist")
public static class Whitelist { public static class Whitelist
{
@Property( @Property(
type = PropertyType.STRING_ARRAY, type = PropertyType.STRING_ARRAY,
description = "Entities that CAN be picked up (useWhitelistEntities must be true)" description = "Entities that CAN be picked up (useWhitelistEntities must be true)"
@ -201,8 +206,10 @@ public class CarryConfig {
description = "Blacklist. Read about the format here: https://github.com/Tschipp/CarryOn/wiki/Black---and-Whitelist-Config" description = "Blacklist. Read about the format here: https://github.com/Tschipp/CarryOn/wiki/Black---and-Whitelist-Config"
) )
public Blacklist blacklist = new Blacklist(); public Blacklist blacklist = new Blacklist();
@Category("blacklist") @Category("blacklist")
public static class Blacklist { public static class Blacklist
{
@Property( @Property(
type = PropertyType.STRING_ARRAY, type = PropertyType.STRING_ARRAY,
description = "Blocks that cannot be picked up" description = "Blocks that cannot be picked up"
@ -231,7 +238,8 @@ public class CarryConfig {
"magneticraft:multiblock_gap", "refinedstorage:*", "mcmultipart:*", "enderstorage:*", "magneticraft:multiblock_gap", "refinedstorage:*", "mcmultipart:*", "enderstorage:*",
"betterstorage:*", "practicallogistics2:*", "wearablebackpacks:*", "rftools:screen", "betterstorage:*", "practicallogistics2:*", "wearablebackpacks:*", "rftools:screen",
"rftools:creative_screen", "create:*", "magic_doorknob:*", "iceandfire:*", "ftbquests:*", "rftools:creative_screen", "create:*", "magic_doorknob:*", "iceandfire:*", "ftbquests:*",
"waystones:*", "contact:*", "framedblocks:*" "waystones:*", "contact:*", "framedblocks:*", "securitycraft:*", "forgemultipartcbe:*", "integrateddynamics:cable",
"mekanismgenerators:wind_generator"
}; };
@Property( @Property(
@ -243,7 +251,8 @@ public class CarryConfig {
"minecraft:shulker", "minecraft:leash_knot", "minecraft:armor_stand", "minecraft:shulker", "minecraft:leash_knot", "minecraft:armor_stand",
"minecraft:item_frame", "minecraft:painting", "minecraft:shulker_bullet", "minecraft:item_frame", "minecraft:painting", "minecraft:shulker_bullet",
"animania:hamster", "animania:ferret*", "animania:hedgehog*", "animania:cart", "animania:hamster", "animania:ferret*", "animania:hedgehog*", "animania:cart",
"animania:wagon", "mynko:*", "pixelmon:*", "mocreatures:*", "quark:totem", "vehicle:*" "animania:wagon", "mynko:*", "pixelmon:*", "mocreatures:*", "quark:totem", "vehicle:*",
"securitycraft:*", "taterzens:npc", "easy_npc:*"
}; };
@Property( @Property(
@ -261,8 +270,10 @@ public class CarryConfig {
description = "Custom Pickup Conditions. Read about the format here: https://github.com/Tschipp/CarryOn/wiki/Custom-Pickup-Condition-Config" description = "Custom Pickup Conditions. Read about the format here: https://github.com/Tschipp/CarryOn/wiki/Custom-Pickup-Condition-Config"
) )
public CustomPickupConditions customPickupConditions = new CustomPickupConditions(); public CustomPickupConditions customPickupConditions = new CustomPickupConditions();
@Category("customPickupConditions") @Category("customPickupConditions")
public static class CustomPickupConditions { public static class CustomPickupConditions
{
@Property( @Property(
type = PropertyType.STRING_ARRAY, type = PropertyType.STRING_ARRAY,
description = "Custom Pickup Conditions for Blocks" description = "Custom Pickup Conditions for Blocks"
@ -278,7 +289,8 @@ public class CarryConfig {
} }
@Config("carryon-client") @Config("carryon-client")
public static class Client { public static class Client
{
@Property( @Property(
type = PropertyType.BOOLEAN, type = PropertyType.BOOLEAN,

View File

@ -1,6 +1,5 @@
package tschipp.carryon.common.config; package tschipp.carryon.common.config;
import com.mojang.datafixers.kinds.Const;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey; import net.minecraft.tags.TagKey;
@ -33,7 +32,6 @@ public class ListHandler {
private static Set<Class<?>> PROPERTY_EXCEPTION_CLASSES = new HashSet<>(); private static Set<Class<?>> PROPERTY_EXCEPTION_CLASSES = new HashSet<>();
public static boolean isPermitted(Block block) public static boolean isPermitted(Block block)
{ {
if(Constants.COMMON_CONFIG.settings.useWhitelistBlocks) if(Constants.COMMON_CONFIG.settings.useWhitelistBlocks)
@ -142,6 +140,7 @@ public class ListHandler {
} }
} }
} }
} }
private static <T> void addTag(String tag, Map<ResourceLocation, TagKey<T>> tagMap, List<TagKey<T>> tags) { private static <T> void addTag(String tag, Map<ResourceLocation, TagKey<T>> tagMap, List<TagKey<T>> tags) {

View File

@ -29,9 +29,7 @@ public final class Matchables
private static float getValueFromStringOrDefault(String toGetFrom, String key, float defaultVal) private static float getValueFromStringOrDefault(String toGetFrom, String key, float defaultVal)
{ {
Optional<Float> val = getValueFromString(toGetFrom, key); Optional<Float> val = getValueFromString(toGetFrom, key);
if(val.isPresent()) return val.orElse(defaultVal);
return val.get();
return defaultVal;
} }
private static Optional<Float> getValueFromString(String toGetFrom, String key) private static Optional<Float> getValueFromString(String toGetFrom, String key)
@ -240,9 +238,9 @@ public final class Matchables
int iG = cond.indexOf(">"); int iG = cond.indexOf(">");
int iL = 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); 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); numb = cond.substring(iG);
else else
numb = cond.substring(iL); numb = cond.substring(iL);
@ -277,8 +275,8 @@ public final class Matchables
if (cond == null || cond.isEmpty()) if (cond == null || cond.isEmpty())
return true; return true;
BlockPos blockpos = new BlockPos(getValueFromStringOrDefault(cond, "x", 0), getValueFromStringOrDefault(cond, "y", 0), getValueFromStringOrDefault(cond, "z", 0)); BlockPos blockpos = new BlockPos((int) getValueFromStringOrDefault(cond, "x", 0), (int) getValueFromStringOrDefault(cond, "y", 0), (int) getValueFromStringOrDefault(cond, "z", 0));
BlockPos expand = new BlockPos(getValueFromStringOrDefault(cond, "dx", 0), getValueFromStringOrDefault(cond, "dy", 0), getValueFromStringOrDefault(cond, "dz", 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 expanded = blockpos.offset(expand);
BlockPos pos = elem.blockPosition(); BlockPos pos = elem.blockPosition();

View File

@ -31,6 +31,11 @@ public class ConfigLoaderImpl {
FileUtils.write(cfgFile, GSON.toJson(entry.getKey()), StandardCharsets.UTF_8); FileUtils.write(cfgFile, GSON.toJson(entry.getKey()), StandardCharsets.UTF_8);
} else { } else {
JsonObject cfgJson = GSON.fromJson(FileUtils.readFileToString(cfgFile, StandardCharsets.UTF_8), JsonObject.class); 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); FileUtils.write(cfgFile, GSON.toJson(loadConfig(entry.getValue(), cfgJson)), StandardCharsets.UTF_8);
} }
} }

View File

@ -20,7 +20,6 @@ public class CarryOnForge {
// This method is invoked by the Forge mod loader when it is ready // 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 // to load your mod. You can access Forge and Common code in this
// project. // project.
// Use Forge to bootstrap the Common mod. // Use Forge to bootstrap the Common mod.
CarryOnCommon.registerConfig(); CarryOnCommon.registerConfig();

View File

@ -11,10 +11,7 @@ import net.minecraftforge.fml.event.config.ModConfigEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import tschipp.carryon.config.*; import tschipp.carryon.config.*;
import java.util.Arrays; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ConfigLoaderImpl { public class ConfigLoaderImpl {
@ -95,7 +92,14 @@ public class ConfigLoaderImpl {
case BOOLEAN -> builder.define(data.getId(), data.getBoolean()); case BOOLEAN -> builder.define(data.getId(), data.getBoolean());
case INT -> builder.defineInRange(data.getId(), data.getInt(), annotationData.min(), annotationData.max()); 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 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."); default -> throw new IllegalAccessException("Unknown property type.");
} }
} }

View File

@ -5,7 +5,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.InterModComms; import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.InterModComms.IMCMessage; import net.minecraftforge.fml.InterModComms.IMCMessage;
import net.minecraftforge.fml.common.Mod; 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.Constants;
import tschipp.carryon.client.modeloverride.ModelOverrideHandler; import tschipp.carryon.client.modeloverride.ModelOverrideHandler;
import tschipp.carryon.common.config.ListHandler; import tschipp.carryon.common.config.ListHandler;
@ -16,7 +16,7 @@ import java.util.stream.Stream;
public class ModBusEvents { public class ModBusEvents {
@SubscribeEvent(priority = EventPriority.LOW) @SubscribeEvent(priority = EventPriority.LOW)
public void serverLoad(FMLDedicatedServerSetupEvent event) public static void serverLoad(FMLCommonSetupEvent event)
{ {
Stream<IMCMessage> messages = InterModComms.getMessages(Constants.MOD_ID); Stream<IMCMessage> messages = InterModComms.getMessages(Constants.MOD_ID);