Finalized port to 1.16
This commit is contained in:
parent
c8e79860ad
commit
b470478a40
|
|
@ -88,10 +88,17 @@ repositories {
|
|||
maven {
|
||||
url "https://maven.blamejared.com/"
|
||||
}
|
||||
|
||||
maven {
|
||||
url "https://maven.mcmoddev.com/"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
|
||||
|
||||
//compileOnly fg.deobf("net.darkhax.gamestages:GameStages-1.16.1:3.1.8")
|
||||
|
||||
}
|
||||
|
||||
// Example for how to get properties into the manifest for reading by the runtime..
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import net.minecraftforge.fml.network.simple.SimpleChannel;
|
|||
import net.minecraftforge.forgespi.language.IModInfo;
|
||||
import tschipp.carryon.common.config.Configs;
|
||||
import tschipp.carryon.common.handler.RegistrationHandler;
|
||||
import tschipp.carryon.common.scripting.ScriptReader;
|
||||
import tschipp.carryon.network.client.CarrySlotPacket;
|
||||
import tschipp.carryon.network.client.ScriptReloadPacket;
|
||||
import tschipp.carryon.network.server.SyncKeybindPacket;
|
||||
|
|
@ -57,7 +56,7 @@ public class CarryOn
|
|||
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, Configs.SERVER_CONFIG);
|
||||
|
||||
Configs.loadConfig(Configs.CLIENT_CONFIG, FMLPaths.CONFIGDIR.get().resolve("carryon-client.toml"));
|
||||
Configs.loadConfig(Configs.SERVER_CONFIG, FMLPaths.CONFIGDIR.get().resolve("carryon-server.toml"));
|
||||
// Configs.loadConfig(Configs.SERVER_CONFIG, FMLPaths.CONFIGDIR.get().resolve("carryon-server.toml"));
|
||||
|
||||
info = ModLoadingContext.get().getActiveContainer().getModInfo();
|
||||
}
|
||||
|
|
@ -66,7 +65,6 @@ public class CarryOn
|
|||
{
|
||||
String version = info.getVersion().toString();
|
||||
// PreInitevent.
|
||||
ScriptReader.preInit();
|
||||
CarryOn.network = NetworkRegistry.newSimpleChannel(new ResourceLocation(CarryOn.MODID, "carryonpackets"), () -> version, version::equals, version::equals);
|
||||
|
||||
// CLIENT PACKETS
|
||||
|
|
@ -79,7 +77,6 @@ public class CarryOn
|
|||
RegistrationHandler.regCommonEvents();
|
||||
|
||||
// Init
|
||||
ScriptReader.parseScripts();
|
||||
RegistrationHandler.regOverrideList();
|
||||
RegistrationHandler.regCaps();
|
||||
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ public class RenderEvents
|
|||
matrix.translate(0, -0.5, -1);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.disableCull();
|
||||
|
||||
|
||||
if (Settings.facePlayer.get() ? !isChest(block) : isChest(block))
|
||||
{
|
||||
matrix.rotate(Vector3f.YP.rotationDegrees(180));
|
||||
|
|
@ -271,12 +271,15 @@ public class RenderEvents
|
|||
{
|
||||
CarryRenderHelper.performOverrideTransformation(matrix, carryOverride);
|
||||
|
||||
Block b = StringParser.getBlock(carryOverride.getRenderNameBlock());
|
||||
if (b != null)
|
||||
if (!carryOverride.getRenderNameBlock().isEmpty())
|
||||
{
|
||||
ItemStack s = new ItemStack(b, 1);
|
||||
s.setTag(carryOverride.getRenderNBT());
|
||||
model = Minecraft.getInstance().getItemRenderer().getItemModelWithOverrides(s, world, player);
|
||||
Block b = StringParser.getBlock(carryOverride.getRenderNameBlock());
|
||||
if (b != null)
|
||||
{
|
||||
ItemStack s = new ItemStack(b, 1);
|
||||
s.setTag(carryOverride.getRenderNBT());
|
||||
model = Minecraft.getInstance().getItemRenderer().getItemModelWithOverrides(s, world, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -339,12 +342,15 @@ public class RenderEvents
|
|||
{
|
||||
CarryRenderHelper.performOverrideTransformation(matrix, carryOverride);
|
||||
|
||||
Block b = StringParser.getBlock(carryOverride.getRenderNameBlock());
|
||||
if (b != null)
|
||||
if (!carryOverride.getRenderNameBlock().isEmpty())
|
||||
{
|
||||
ItemStack s = new ItemStack(b, 1);
|
||||
s.setTag(carryOverride.getRenderNBT());
|
||||
model = Minecraft.getInstance().getItemRenderer().getItemModelWithOverrides(s, world, player);
|
||||
Block b = StringParser.getBlock(carryOverride.getRenderNameBlock());
|
||||
if (b != null)
|
||||
{
|
||||
ItemStack s = new ItemStack(b, 1);
|
||||
s.setTag(carryOverride.getRenderNBT());
|
||||
model = Minecraft.getInstance().getItemRenderer().getItemModelWithOverrides(s, world, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -524,8 +530,8 @@ public class RenderEvents
|
|||
Pose pose = player.getPose();
|
||||
|
||||
applyGeneralTransformations(player, partialticks, matrix);
|
||||
|
||||
if(perspective == 2)
|
||||
|
||||
if (perspective == 2)
|
||||
matrix.translate(0, -1.6, 0.65);
|
||||
else
|
||||
matrix.translate(0, -1.6, -0.65);
|
||||
|
|
@ -542,7 +548,7 @@ public class RenderEvents
|
|||
|
||||
if (perspective == 2)
|
||||
matrix.rotate(Vector3f.YP.rotationDegrees(180));
|
||||
|
||||
|
||||
matrix.scale((10 - multiplier) * 0.08f, (10 - multiplier) * 0.08f, (10 - multiplier) * 0.08f);
|
||||
matrix.translate(0.0, height / 2 + -(height / 2) + 1, width - 0.1 < 0.7 ? width - 0.1 + (0.7 - (width - 0.1)) : width - 0.1);
|
||||
|
||||
|
|
@ -550,11 +556,11 @@ public class RenderEvents
|
|||
{
|
||||
matrix.rotate(Vector3f.XN.rotationDegrees(90));
|
||||
matrix.translate(0, -0.2 * height, 0);
|
||||
|
||||
if(pose == Pose.FALL_FLYING)
|
||||
matrix.translate(0, 0 , 0.2);
|
||||
|
||||
if (pose == Pose.FALL_FLYING)
|
||||
matrix.translate(0, 0, 0.2);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -595,9 +601,9 @@ public class RenderEvents
|
|||
{
|
||||
float[] rotLeft = null;
|
||||
float[] rotRight = null;
|
||||
if (overrider.getRenderRotationLeftArm() != null)
|
||||
if (!overrider.getRenderRotationLeftArm().isEmpty())
|
||||
rotLeft = ScriptParseHelper.getXYZArray(overrider.getRenderRotationLeftArm());
|
||||
if (overrider.getRenderRotationRightArm() != null)
|
||||
if (!overrider.getRenderRotationRightArm().isEmpty())
|
||||
rotRight = ScriptParseHelper.getXYZArray(overrider.getRenderRotationRightArm());
|
||||
|
||||
boolean renderRight = overrider.isRenderRightArm();
|
||||
|
|
|
|||
|
|
@ -40,16 +40,19 @@ public class CarryRenderHelper
|
|||
|
||||
public static void performOverrideTransformation(MatrixStack matrix, CarryOnOverride override)
|
||||
{
|
||||
int perspective = getPerspective();
|
||||
|
||||
float[] translation = ScriptParseHelper.getXYZArray(override.getRenderTranslation());
|
||||
float[] rotation = ScriptParseHelper.getXYZArray(override.getRenderRotation());
|
||||
float[] scaled = ScriptParseHelper.getScaled(override.getRenderScaled());
|
||||
|
||||
matrix.translate(translation[0], translation[1], translation[2]);
|
||||
|
||||
Quaternion rot = Vector3f.XP.rotationDegrees(rotation[0]);
|
||||
rot.multiply(Vector3f.YP.rotationDegrees(rotation[1]));
|
||||
rot.multiply(Vector3f.YP.rotationDegrees(rotation[1]));
|
||||
rot.multiply(Vector3f.ZP.rotationDegrees(rotation[2]));
|
||||
|
||||
matrix.rotate(rot);
|
||||
|
||||
matrix.translate(translation[0], translation[1], perspective == 1 && override.isBlock() ? -translation[2] : translation[2]);
|
||||
|
||||
matrix.scale(scaled[0], scaled[1], scaled[2]);
|
||||
}
|
||||
|
||||
|
|
@ -61,22 +64,22 @@ public class CarryRenderHelper
|
|||
|
||||
if (override instanceof ItemStack)
|
||||
{
|
||||
Minecraft.getInstance().getItemRenderer().renderItem((ItemStack) override, TransformType.NONE, false, matrix, buffer, light, 0xFFFFFF, model); //Note: I'm not sure what the second to last argument does, but it seems to work like this
|
||||
Minecraft.getInstance().getItemRenderer().renderItem((ItemStack) override, TransformType.NONE, false, matrix, buffer, light, 0xFFFFFF, model);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Minecraft.getInstance().getItemRenderer().renderItem(tileStack.isEmpty() ? stack : tileStack, TransformType.NONE, false, matrix, buffer, light, 0xFFFFFF, model);
|
||||
}
|
||||
|
||||
|
||||
public static int getPerspective()
|
||||
{
|
||||
boolean isThirdPerson = !Minecraft.getInstance().gameSettings.func_243230_g().func_243192_a();
|
||||
boolean isThirdPersonReverse = Minecraft.getInstance().gameSettings.func_243230_g().func_243193_b();
|
||||
|
||||
if(!isThirdPerson && !isThirdPersonReverse)
|
||||
|
||||
if (!isThirdPerson && !isThirdPersonReverse)
|
||||
return 0;
|
||||
if(isThirdPerson && !isThirdPersonReverse)
|
||||
if (isThirdPerson && !isThirdPersonReverse)
|
||||
return 1;
|
||||
return 2;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class PositionProvider implements ICapabilitySerializable<CompoundNBT>
|
|||
return (LazyOptional<T>) LazyOptional.of(() -> {
|
||||
return new TEPosition();
|
||||
});
|
||||
return null;
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -261,7 +261,7 @@ public class Configs {
|
|||
s.comment("Blacklist");
|
||||
|
||||
forbiddenTiles = s
|
||||
.comment("Tile Entities that cannot be picked up")
|
||||
.comment("Blocks that cannot be picked up")
|
||||
.defineList("blacklist.forbiddenTiles", Arrays.asList(new String[]
|
||||
{
|
||||
"minecraft:end_portal",
|
||||
|
|
|
|||
|
|
@ -60,7 +60,9 @@ import tschipp.carryon.common.item.ItemCarryonBlock;
|
|||
import tschipp.carryon.common.item.ItemCarryonEntity;
|
||||
import tschipp.carryon.common.scripting.CarryOnOverride;
|
||||
import tschipp.carryon.common.scripting.ScriptChecker;
|
||||
import tschipp.carryon.common.scripting.ScriptReader;
|
||||
import tschipp.carryon.network.client.CarrySlotPacket;
|
||||
import tschipp.carryon.network.client.ScriptReloadPacket;
|
||||
|
||||
@EventBusSubscriber(modid = CarryOn.MODID)
|
||||
public class ItemEvents
|
||||
|
|
@ -85,14 +87,14 @@ public class ItemEvents
|
|||
{
|
||||
String command = override.getCommandPlace();
|
||||
|
||||
if (command != null)
|
||||
if (command != null && !command.isEmpty())
|
||||
player.getServer().getCommandManager().handleCommand(player.getServer().getCommandSource(), "/execute as " + player.getGameProfile().getName() + " run " + command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
public void onItemDropped(EntityJoinWorldEvent event)
|
||||
{
|
||||
|
|
@ -172,6 +174,10 @@ public class ItemEvents
|
|||
}
|
||||
|
||||
}
|
||||
if(event.getPlayer() instanceof ServerPlayerEntity)
|
||||
{
|
||||
CarryOn.network.send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity)event.getPlayer()), new ScriptReloadPacket(ScriptReader.OVERRIDES.values()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package tschipp.carryon.common.handler;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
|
@ -15,12 +14,13 @@ import net.minecraft.entity.player.ServerPlayerEntity;
|
|||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.AttackEntityEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
||||
import tschipp.carryon.common.config.Configs.Settings;
|
||||
import tschipp.carryon.common.helper.CarryonGamestageHelper;
|
||||
import tschipp.carryon.common.item.ItemCarryonBlock;
|
||||
import tschipp.carryon.common.scripting.CarryOnOverride;
|
||||
import tschipp.carryon.common.scripting.ScriptChecker;
|
||||
|
|
@ -60,9 +60,10 @@ public class PickupHandler
|
|||
|
||||
if ((state.getBlockHardness(world, pos) != -1 || player.isCreative()))
|
||||
{
|
||||
double distance = pos.distanceSq(player.getPosition());
|
||||
|
||||
if (distance < Math.pow(Settings.maxDistance.get(), 2))
|
||||
double distance = Vector3d.copy(pos).distanceTo(player.getPositionVec());
|
||||
double maxDist = Settings.maxDistance.get();
|
||||
|
||||
if (distance < maxDist)
|
||||
{
|
||||
|
||||
if (!ItemCarryonBlock.isLocked(pos, world))
|
||||
|
|
@ -70,44 +71,7 @@ public class PickupHandler
|
|||
|
||||
if (CustomPickupOverrideHandler.hasSpecialPickupConditions(state))
|
||||
{
|
||||
try
|
||||
{
|
||||
Class<?> gameStageHelper = Class.forName("net.darkhax.gamestages.GameStageHelper");
|
||||
Class<?> iStageData = Class.forName("net.darkhax.gamestages.data.IStageData");
|
||||
|
||||
Method getPlayerData = ObfuscationReflectionHelper.findMethod(gameStageHelper, "getPlayerData", PlayerEntity.class);
|
||||
Method hasStage = ObfuscationReflectionHelper.findMethod(iStageData, "hasStage", String.class);
|
||||
|
||||
Object stageData = getPlayerData.invoke(null, player);
|
||||
String condition = CustomPickupOverrideHandler.getPickupCondition(state);
|
||||
boolean has = (boolean) hasStage.invoke(stageData, condition);
|
||||
|
||||
if (has)
|
||||
return handleProtections((ServerPlayerEntity) player, world, pos, state);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Class<?> playerDataHandler = Class.forName("net.darkhax.gamestages.capabilities.PlayerDataHandler");
|
||||
Class<?> iStageData = Class.forName("net.darkhax.gamestages.capabilities.PlayerDataHandler$IStageData");
|
||||
|
||||
Method getStageData = ObfuscationReflectionHelper.findMethod(playerDataHandler, "getStageData", PlayerEntity.class);
|
||||
Method hasUnlockedStage = ObfuscationReflectionHelper.findMethod(iStageData, "hasUnlockedStage", String.class);
|
||||
|
||||
Object stageData = getStageData.invoke(null, player);
|
||||
String condition = CustomPickupOverrideHandler.getPickupCondition(state);
|
||||
boolean has = (boolean) hasUnlockedStage.invoke(stageData, condition);
|
||||
|
||||
if (has)
|
||||
return handleProtections((ServerPlayerEntity) player, world, pos, state);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return handleProtections((ServerPlayerEntity) player, world, pos, state);
|
||||
}
|
||||
}
|
||||
|
||||
return CarryonGamestageHelper.hasGamestage(CustomPickupOverrideHandler.getPickupCondition(state), player) && handleProtections((ServerPlayerEntity) player, world, pos, state);
|
||||
}
|
||||
else if (Settings.pickupAllBlocks.get() ? true : tile != null)
|
||||
{
|
||||
|
|
@ -155,46 +119,10 @@ public class PickupHandler
|
|||
|
||||
if (CustomPickupOverrideHandler.hasSpecialPickupConditions(toPickUp))
|
||||
{
|
||||
try
|
||||
{
|
||||
Class<?> gameStageHelper = Class.forName("net.darkhax.gamestages.GameStageHelper");
|
||||
Class<?> iStageData = Class.forName("net.darkhax.gamestages.data.IStageData");
|
||||
|
||||
Method getPlayerData = ObfuscationReflectionHelper.findMethod(gameStageHelper, "getPlayerData", PlayerEntity.class);
|
||||
Method hasStage = ObfuscationReflectionHelper.findMethod(iStageData, "hasStage", String.class);
|
||||
|
||||
Object stageData = getPlayerData.invoke(null, player);
|
||||
String condition = CustomPickupOverrideHandler.getPickupCondition(toPickUp);
|
||||
boolean has = (boolean) hasStage.invoke(stageData, condition);
|
||||
|
||||
if (has)
|
||||
return handleProtections((ServerPlayerEntity) player, toPickUp);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Class<?> playerDataHandler = Class.forName("net.darkhax.gamestages.capabilities.PlayerDataHandler");
|
||||
Class<?> iStageData = Class.forName("net.darkhax.gamestages.capabilities.PlayerDataHandler$IStageData");
|
||||
|
||||
Method getStageData = ObfuscationReflectionHelper.findMethod(playerDataHandler, "getStageData", PlayerEntity.class);
|
||||
Method hasUnlockedStage = ObfuscationReflectionHelper.findMethod(iStageData, "hasUnlockedStage", String.class);
|
||||
|
||||
Object stageData = getStageData.invoke(null, player);
|
||||
String condition = CustomPickupOverrideHandler.getPickupCondition(toPickUp);
|
||||
boolean has = (boolean) hasUnlockedStage.invoke(stageData, condition);
|
||||
|
||||
if (has)
|
||||
return handleProtections((ServerPlayerEntity) player, toPickUp);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return handleProtections((ServerPlayerEntity) player, toPickUp);
|
||||
}
|
||||
}
|
||||
return CarryonGamestageHelper.hasGamestage(CustomPickupOverrideHandler.getPickupCondition(toPickUp), player) && handleProtections((ServerPlayerEntity) player, toPickUp);
|
||||
}
|
||||
else
|
||||
return true && handleProtections((ServerPlayerEntity) player, toPickUp);
|
||||
return handleProtections((ServerPlayerEntity) player, toPickUp);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -233,46 +161,10 @@ public class PickupHandler
|
|||
|
||||
if (CustomPickupOverrideHandler.hasSpecialPickupConditions(toPickUp))
|
||||
{
|
||||
try
|
||||
{
|
||||
Class<?> gameStageHelper = Class.forName("net.darkhax.gamestages.GameStageHelper");
|
||||
Class<?> iStageData = Class.forName("net.darkhax.gamestages.data.IStageData");
|
||||
|
||||
Method getPlayerData = ObfuscationReflectionHelper.findMethod(gameStageHelper, "getPlayerData", PlayerEntity.class);
|
||||
Method hasStage = ObfuscationReflectionHelper.findMethod(iStageData, "hasStage", String.class);
|
||||
|
||||
Object stageData = getPlayerData.invoke(null, player);
|
||||
String condition = CustomPickupOverrideHandler.getPickupCondition(toPickUp);
|
||||
boolean has = (boolean) hasStage.invoke(stageData, condition);
|
||||
|
||||
if (has)
|
||||
return handleProtections((ServerPlayerEntity) player, toPickUp);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Class<?> playerDataHandler = Class.forName("net.darkhax.gamestages.capabilities.PlayerDataHandler");
|
||||
Class<?> iStageData = Class.forName("net.darkhax.gamestages.capabilities.PlayerDataHandler$IStageData");
|
||||
|
||||
Method getStageData = ObfuscationReflectionHelper.findMethod(playerDataHandler, "getStageData", PlayerEntity.class);
|
||||
Method hasUnlockedStage = ObfuscationReflectionHelper.findMethod(iStageData, "hasUnlockedStage", String.class);
|
||||
|
||||
Object stageData = getStageData.invoke(null, player);
|
||||
String condition = CustomPickupOverrideHandler.getPickupCondition(toPickUp);
|
||||
boolean has = (boolean) hasUnlockedStage.invoke(stageData, condition);
|
||||
|
||||
if (has)
|
||||
return handleProtections((ServerPlayerEntity) player, toPickUp);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return handleProtections((ServerPlayerEntity) player, toPickUp);
|
||||
}
|
||||
}
|
||||
return CarryonGamestageHelper.hasGamestage(CustomPickupOverrideHandler.getPickupCondition(toPickUp), player) && handleProtections((ServerPlayerEntity) player, toPickUp);
|
||||
}
|
||||
else
|
||||
return true && handleProtections((ServerPlayerEntity) player, toPickUp);
|
||||
return handleProtections((ServerPlayerEntity) player, toPickUp);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
package tschipp.carryon.common.helper;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
||||
public class CarryonGamestageHelper
|
||||
{
|
||||
public static boolean hasGamestage(String stage, PlayerEntity player)
|
||||
{
|
||||
// return GameStageHelper.hasStage(player, stage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ public class ScriptParseHelper
|
|||
|
||||
public static boolean matches(double number, String cond)
|
||||
{
|
||||
if (cond == null)
|
||||
if (cond == null || cond.isEmpty())
|
||||
return true;
|
||||
|
||||
try
|
||||
|
|
@ -60,7 +60,7 @@ public class ScriptParseHelper
|
|||
|
||||
public static boolean matches(Block block, String cond)
|
||||
{
|
||||
if (cond == null)
|
||||
if (cond == null || cond.isEmpty())
|
||||
return true;
|
||||
|
||||
Block toCheck = StringParser.getBlock(cond);
|
||||
|
|
@ -72,7 +72,7 @@ public class ScriptParseHelper
|
|||
|
||||
public static boolean matches(CompoundNBT toCheck, CompoundNBT toMatch)
|
||||
{
|
||||
if (toCheck == null || toMatch == null)
|
||||
if (toCheck == null || toMatch == null || toMatch.isEmpty())
|
||||
return true;
|
||||
|
||||
boolean matching = true;
|
||||
|
|
@ -111,7 +111,7 @@ public class ScriptParseHelper
|
|||
|
||||
public static float getScaledValueFromString(String toGetFrom, String key)
|
||||
{
|
||||
if(toGetFrom == null)
|
||||
if(toGetFrom == null || toGetFrom.isEmpty())
|
||||
return 1;
|
||||
|
||||
String[] s = toGetFrom.split(",");
|
||||
|
|
@ -139,7 +139,7 @@ public class ScriptParseHelper
|
|||
|
||||
public static boolean matchesScore(PlayerEntity player, String cond)
|
||||
{
|
||||
if (cond == null)
|
||||
if (cond == null || cond.isEmpty())
|
||||
return true;
|
||||
|
||||
Scoreboard score = player.getWorldScoreboard();
|
||||
|
|
@ -174,7 +174,7 @@ public class ScriptParseHelper
|
|||
|
||||
public static boolean matches(BlockPos pos, String cond)
|
||||
{
|
||||
if (cond == null)
|
||||
if (cond == null || cond.isEmpty())
|
||||
return true;
|
||||
|
||||
BlockPos blockpos = new BlockPos(getValueFromString(cond, "x"), getValueFromString(cond, "y"), getValueFromString(cond, "z"));
|
||||
|
|
@ -190,7 +190,7 @@ public class ScriptParseHelper
|
|||
|
||||
public static float getValueFromString(String toGetFrom, String key)
|
||||
{
|
||||
if(toGetFrom == null)
|
||||
if(toGetFrom == null || toGetFrom.isEmpty())
|
||||
return 0;
|
||||
|
||||
String[] s = toGetFrom.split(",");
|
||||
|
|
@ -218,7 +218,7 @@ public class ScriptParseHelper
|
|||
|
||||
public static boolean hasEffects(PlayerEntity player, String cond)
|
||||
{
|
||||
if(cond == null)
|
||||
if(cond == null || cond.isEmpty())
|
||||
return true;
|
||||
|
||||
Collection<EffectInstance> effects = player.getActivePotionEffects();
|
||||
|
|
@ -274,7 +274,7 @@ public class ScriptParseHelper
|
|||
|
||||
public static boolean matches(Material material, String cond)
|
||||
{
|
||||
if (cond == null)
|
||||
if (cond == null || cond.isEmpty())
|
||||
return true;
|
||||
|
||||
switch (cond)
|
||||
|
|
|
|||
|
|
@ -1,60 +1,226 @@
|
|||
package tschipp.carryon.common.scripting;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import tschipp.carryon.common.helper.InvalidConfigException;
|
||||
|
||||
public class CarryOnOverride
|
||||
{
|
||||
// BLOCKS
|
||||
private CompoundNBT typeBlockTag;
|
||||
private String typeNameBlock;
|
||||
private String typeMaterial;
|
||||
private String typeHardness;
|
||||
private String typeResistance;
|
||||
private CompoundNBT typeBlockTag = new CompoundNBT();
|
||||
private String typeNameBlock = "";
|
||||
private String typeMaterial = "";
|
||||
private String typeHardness = "";
|
||||
private String typeResistance = "";
|
||||
|
||||
// ENTITIES
|
||||
private CompoundNBT typeEntityTag;
|
||||
private String typeNameEntity;
|
||||
private String typeHeight;
|
||||
private String typeWidth;
|
||||
private String typeHealth;
|
||||
private String typeNameEntity = "";
|
||||
private String typeHeight = "";
|
||||
private String typeWidth = "";
|
||||
private String typeHealth = "";
|
||||
|
||||
// CONDITIONS
|
||||
private String conditionGamestage;
|
||||
private String conditionAchievement;
|
||||
private String conditionXp;
|
||||
private String conditionGamemode;
|
||||
private String conditionScoreboard;
|
||||
private String conditionPosition;
|
||||
private String conditionEffects;
|
||||
private String conditionGamestage = "";
|
||||
private String conditionAchievement = "";
|
||||
private String conditionXp = "";
|
||||
private String conditionGamemode = "";
|
||||
private String conditionScoreboard = "";
|
||||
private String conditionPosition = "";
|
||||
private String conditionEffects = "";
|
||||
|
||||
// RENDER
|
||||
private String renderNameBlock;
|
||||
private String renderNameEntity;
|
||||
private CompoundNBT renderNBT;
|
||||
private String renderTranslation;
|
||||
private String renderRotation;
|
||||
private String renderscaled;
|
||||
private String renderRotationLeftArm;
|
||||
private String renderRotationRightArm;
|
||||
private String renderNameBlock = "";
|
||||
private String renderNameEntity = "";
|
||||
private CompoundNBT renderNBT = new CompoundNBT();
|
||||
private String renderTranslation = "";
|
||||
private String renderRotation = "";
|
||||
private String renderscaled = "";
|
||||
private String renderRotationLeftArm = "";
|
||||
private String renderRotationRightArm = "";
|
||||
private boolean renderLeftArm = true;
|
||||
private boolean renderRightArm = true;
|
||||
|
||||
//EFFECTS
|
||||
private String commandInit;
|
||||
private String commandLoop;
|
||||
private String commandPlace;
|
||||
|
||||
// EFFECTS
|
||||
private String commandInit = "";
|
||||
private String commandLoop = "";
|
||||
private String commandPlace = "";
|
||||
|
||||
private boolean isBlock;
|
||||
private boolean isEntity;
|
||||
private String resourceLocation;
|
||||
|
||||
private String resourceLocation = "";
|
||||
public boolean isInvalid = false;
|
||||
|
||||
public CarryOnOverride(String path)
|
||||
{
|
||||
this.resourceLocation = path;
|
||||
}
|
||||
|
||||
|
||||
public CarryOnOverride(JsonElement jsonElem, ResourceLocation loc)
|
||||
{
|
||||
boolean errored = false;
|
||||
resourceLocation = loc.toString();
|
||||
|
||||
if (jsonElem != null && jsonElem.isJsonObject())
|
||||
{
|
||||
try
|
||||
{
|
||||
JsonObject json = jsonElem.getAsJsonObject();
|
||||
JsonObject object = (JsonObject) json.get("object");
|
||||
JsonObject conditions = (JsonObject) json.get("conditions");
|
||||
JsonObject render = (JsonObject) json.get("render");
|
||||
JsonObject effects = (JsonObject) json.get("effects");
|
||||
|
||||
if ((object != null && conditions != null) || (object != null && render != null) || (object != null && effects != null))
|
||||
{
|
||||
JsonObject block = (JsonObject) object.get("block");
|
||||
JsonObject entity = (JsonObject) object.get("entity");
|
||||
|
||||
if ((block == null && entity == null) || (block != null && entity != null))
|
||||
errored = true;
|
||||
|
||||
if (!errored)
|
||||
{
|
||||
if (block != null)
|
||||
{
|
||||
setBlock(true);
|
||||
JsonElement name = block.get("name");
|
||||
JsonElement material = block.get("material");
|
||||
JsonElement hardness = block.get("hardness");
|
||||
JsonElement resistance = block.get("resistance");
|
||||
JsonObject nbt = (JsonObject) block.get("nbt");
|
||||
|
||||
if (name != null)
|
||||
setTypeNameBlock(name.getAsString());
|
||||
if (material != null)
|
||||
setTypeMaterial(material.getAsString());
|
||||
if (hardness != null)
|
||||
setTypeHardness(hardness.getAsString());
|
||||
if (resistance != null)
|
||||
setTypeResistance(resistance.getAsString());
|
||||
if (nbt != null)
|
||||
setTypeBlockTag(JsonToNBT.getTagFromJson(nbt.toString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
setEntity(true);
|
||||
JsonElement name = entity.get("name");
|
||||
JsonElement health = entity.get("health");
|
||||
JsonElement height = entity.get("height");
|
||||
JsonElement width = entity.get("width");
|
||||
JsonObject nbt = (JsonObject) entity.get("nbt");
|
||||
|
||||
if (name != null)
|
||||
setTypeNameEntity(name.getAsString());
|
||||
if (health != null)
|
||||
setTypeHealth(health.getAsString());
|
||||
if (height != null)
|
||||
setTypeHeight(height.getAsString());
|
||||
if (width != null)
|
||||
setTypeWidth(width.getAsString());
|
||||
if (nbt != null)
|
||||
setTypeEntityTag(JsonToNBT.getTagFromJson(nbt.toString()));
|
||||
}
|
||||
|
||||
if (conditions != null)
|
||||
{
|
||||
JsonElement gamestage = conditions.get("gamestage");
|
||||
JsonElement achievement = conditions.get("advancement");
|
||||
JsonElement xp = conditions.get("xp");
|
||||
JsonElement gamemode = conditions.get("gamemode");
|
||||
JsonElement scoreboard = conditions.get("scoreboard");
|
||||
JsonElement position = conditions.get("position");
|
||||
JsonElement potionEffects = conditions.get("effects");
|
||||
|
||||
if (gamestage != null)
|
||||
setConditionGamestage(gamestage.getAsString());
|
||||
if (achievement != null)
|
||||
setConditionAchievement(achievement.getAsString());
|
||||
if (xp != null)
|
||||
setConditionXp(xp.getAsString());
|
||||
if (gamemode != null)
|
||||
setConditionGamemode(gamemode.getAsString());
|
||||
if (scoreboard != null)
|
||||
setConditionScoreboard(scoreboard.getAsString());
|
||||
if (position != null)
|
||||
setConditionPosition(position.getAsString());
|
||||
if (potionEffects != null)
|
||||
setConditionEffects(potionEffects.getAsString());
|
||||
}
|
||||
|
||||
if (render != null)
|
||||
{
|
||||
JsonElement name_block = render.get("name_block");
|
||||
JsonElement name_entity = render.get("name_entity");
|
||||
JsonObject nbt = (JsonObject) render.get("nbt");
|
||||
JsonElement translation = render.get("translation");
|
||||
JsonElement rotation = render.get("rotation");
|
||||
JsonElement scaled = render.get("scale");
|
||||
JsonElement rotationLeftArm = render.get("rotation_left_arm");
|
||||
JsonElement rotationRightArm = render.get("rotation_right_arm");
|
||||
JsonElement renderLeftArm = render.get("render_left_arm");
|
||||
JsonElement renderRightArm = render.get("render_right_arm");
|
||||
|
||||
if (name_block != null)
|
||||
setRenderNameBlock(name_block.getAsString());
|
||||
if (name_entity != null)
|
||||
setRenderNameEntity(name_entity.getAsString());
|
||||
if (translation != null)
|
||||
setRenderTranslation(translation.getAsString());
|
||||
if (rotation != null)
|
||||
setRenderRotation(rotation.getAsString());
|
||||
if (scaled != null)
|
||||
setRenderscaled(scaled.getAsString());
|
||||
if (nbt != null)
|
||||
setRenderNBT(JsonToNBT.getTagFromJson(nbt.toString()));
|
||||
if (rotationLeftArm != null)
|
||||
setRenderRotationLeftArm(rotationLeftArm.getAsString());
|
||||
if (rotationRightArm != null)
|
||||
setRenderRotationRightArm(rotationRightArm.getAsString());
|
||||
if (renderLeftArm != null)
|
||||
setRenderLeftArm(renderLeftArm.getAsBoolean());
|
||||
if (renderRightArm != null)
|
||||
setRenderRightArm(renderRightArm.getAsBoolean());
|
||||
}
|
||||
|
||||
if (effects != null)
|
||||
{
|
||||
JsonElement commandInit = effects.get("commandPickup");
|
||||
JsonElement commandLoop = effects.get("commandLoop");
|
||||
JsonElement commandPlace = effects.get("commandPlace");
|
||||
|
||||
if (commandInit != null)
|
||||
setCommandInit(commandInit.getAsString());
|
||||
if (commandLoop != null)
|
||||
setCommandLoop(commandLoop.getAsString());
|
||||
if (commandPlace != null)
|
||||
setCommandPlace(commandPlace.getAsString());
|
||||
}
|
||||
}
|
||||
else
|
||||
isInvalid = true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
isInvalid = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
isInvalid = true;
|
||||
|
||||
if(!isBlock && !isEntity)
|
||||
isInvalid = true;
|
||||
|
||||
if(isInvalid)
|
||||
new InvalidConfigException("The script parsing for " + resourceLocation + " has failed! Please double check!").printException();
|
||||
}
|
||||
|
||||
public String getCommandInit()
|
||||
{
|
||||
return commandInit;
|
||||
|
|
@ -133,13 +299,13 @@ public class CarryOnOverride
|
|||
result = prime * result + ((resourceLocation == null) ? 0 : resourceLocation.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Code: " + this.hashCode();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
|
|
@ -364,8 +530,6 @@ public class CarryOnOverride
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean isBlock()
|
||||
{
|
||||
return isBlock;
|
||||
|
|
@ -501,7 +665,6 @@ public class CarryOnOverride
|
|||
this.typeBlockTag = typeBlockTag;
|
||||
}
|
||||
|
||||
|
||||
public void setTypeNameBlock(String typeNameBlock)
|
||||
{
|
||||
this.typeNameBlock = typeNameBlock;
|
||||
|
|
@ -607,8 +770,6 @@ public class CarryOnOverride
|
|||
this.renderscaled = renderscaled;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getCommandPlace()
|
||||
{
|
||||
return commandPlace;
|
||||
|
|
@ -618,7 +779,7 @@ public class CarryOnOverride
|
|||
{
|
||||
this.commandPlace = commandPlace;
|
||||
}
|
||||
|
||||
|
||||
public void serialize(PacketBuffer buf)
|
||||
{
|
||||
// BLOCKS
|
||||
|
|
@ -655,8 +816,8 @@ public class CarryOnOverride
|
|||
buf.writeString(renderRotationRightArm);
|
||||
buf.writeBoolean(renderLeftArm);
|
||||
buf.writeBoolean(renderRightArm);
|
||||
|
||||
//EFFECTS
|
||||
|
||||
// EFFECTS
|
||||
buf.writeString(commandInit);
|
||||
buf.writeString(commandLoop);
|
||||
buf.writeString(commandPlace);
|
||||
|
|
@ -665,7 +826,7 @@ public class CarryOnOverride
|
|||
buf.writeBoolean(isEntity);
|
||||
buf.writeString(resourceLocation);
|
||||
}
|
||||
|
||||
|
||||
public static CarryOnOverride deserialize(PacketBuffer buf)
|
||||
{
|
||||
CarryOnOverride override = new CarryOnOverride("");
|
||||
|
|
@ -702,8 +863,8 @@ public class CarryOnOverride
|
|||
override.renderRotationRightArm = buf.readString();
|
||||
override.renderLeftArm = buf.readBoolean();
|
||||
override.renderRightArm = buf.readBoolean();
|
||||
|
||||
//EFFECTS
|
||||
|
||||
// EFFECTS
|
||||
override.commandInit = buf.readString();
|
||||
override.commandLoop = buf.readString();
|
||||
override.commandPlace = buf.readString();
|
||||
|
|
@ -711,7 +872,7 @@ public class CarryOnOverride
|
|||
override.isBlock = buf.readBoolean();
|
||||
override.isEntity = buf.readBoolean();
|
||||
override.resourceLocation = buf.readString();
|
||||
|
||||
|
||||
return override;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,8 +65,8 @@ public class ScriptChecker
|
|||
float height = entity.getHeight();
|
||||
float width = entity.getWidth();
|
||||
float health = entity instanceof LivingEntity ? ((LivingEntity) entity).getHealth() : 0.0f;
|
||||
CompoundNBT tag = new CompoundNBT();
|
||||
entity.deserializeNBT(tag);
|
||||
CompoundNBT tag = entity.serializeNBT();
|
||||
|
||||
|
||||
boolean isAllowed = Settings.useWhitelistEntities.get() ? ListHandler.isAllowed(entity) : !ListHandler.isForbidden(entity);
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ public class ScriptChecker
|
|||
|
||||
public static boolean matchesAll(CarryOnOverride override, String name, float height, float width, float health, CompoundNBT tag)
|
||||
{
|
||||
boolean matchname = override.getTypeNameEntity() == null ? true : name.equals(override.getTypeNameEntity());
|
||||
boolean matchname = override.getTypeNameEntity().isEmpty() ? true : name.equals(override.getTypeNameEntity());
|
||||
boolean matchheight = ScriptParseHelper.matches(height, override.getTypeHeight());
|
||||
boolean matchwidth = ScriptParseHelper.matches(width, override.getTypeWidth());
|
||||
boolean matchhealth = ScriptParseHelper.matches(health, override.getTypeHealth());
|
||||
|
|
@ -110,14 +110,14 @@ public class ScriptChecker
|
|||
public static boolean fulfillsConditions(CarryOnOverride override, PlayerEntity player)
|
||||
{
|
||||
AdvancementManager manager = ((ServerPlayerEntity) player).server.getAdvancementManager();
|
||||
Advancement adv = manager.getAdvancement(new ResourceLocation((override.getConditionAchievement()) == null ? "" : override.getConditionAchievement()));
|
||||
Advancement adv = manager.getAdvancement(new ResourceLocation((override.getConditionAchievement()).isEmpty() ? "" : override.getConditionAchievement()));
|
||||
|
||||
boolean achievement = adv == null ? true : ((ServerPlayerEntity) player).getAdvancements().getProgress(adv).isDone();
|
||||
boolean gamemode = ScriptParseHelper.matches(((ServerPlayerEntity) player).interactionManager.getGameType().getID(), override.getConditionGamemode());
|
||||
boolean gamestage = true;
|
||||
if (ModList.get().isLoaded("gamestages"))
|
||||
{
|
||||
if (override.getConditionGamestage() != null)
|
||||
if (!override.getConditionGamestage().isEmpty())
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,200 +1,187 @@
|
|||
package tschipp.carryon.common.scripting;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
import tschipp.carryon.CarryOn;
|
||||
import tschipp.carryon.common.config.Configs.Settings;
|
||||
|
||||
public class ScriptReader
|
||||
{
|
||||
private static ArrayList<File> scripts = new ArrayList<File>();
|
||||
public static HashMap<Integer, CarryOnOverride> OVERRIDES = new HashMap<Integer, CarryOnOverride>();
|
||||
|
||||
// public static HashSet<CarryOnOverride> OVERRIDES = new
|
||||
// HashSet<CarryOnOverride>();
|
||||
|
||||
public static void preInit()
|
||||
{
|
||||
scripts.clear();
|
||||
|
||||
CarryOn.CONFIGURATION_FILE = new File(FMLPaths.CONFIGDIR.get().toString(), "/carryon-scripts/");
|
||||
// public static void preInit()
|
||||
// {
|
||||
// scripts.clear();
|
||||
//
|
||||
// CarryOn.CONFIGURATION_FILE = new File(FMLPaths.CONFIGDIR.get().toString(), "/carryon-scripts/");
|
||||
//
|
||||
// if (!CarryOn.CONFIGURATION_FILE.exists())
|
||||
// CarryOn.CONFIGURATION_FILE.mkdir();
|
||||
//
|
||||
// for (File file : CarryOn.CONFIGURATION_FILE.listFiles())
|
||||
// {
|
||||
// if (file.getName().endsWith(".json"))
|
||||
// scripts.add(file);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
if (!CarryOn.CONFIGURATION_FILE.exists())
|
||||
CarryOn.CONFIGURATION_FILE.mkdir();
|
||||
|
||||
for (File file : CarryOn.CONFIGURATION_FILE.listFiles())
|
||||
{
|
||||
if (file.getName().endsWith(".json"))
|
||||
scripts.add(file);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void parseScripts()
|
||||
{
|
||||
OVERRIDES.clear();
|
||||
|
||||
try
|
||||
{
|
||||
if (!Settings.useScripts.get())
|
||||
return;
|
||||
|
||||
for (File file : scripts)
|
||||
{
|
||||
boolean errored = false;
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonObject json = (JsonObject) parser.parse(new FileReader(file.getAbsolutePath()));
|
||||
|
||||
JsonObject object = (JsonObject) json.get("object");
|
||||
JsonObject conditions = (JsonObject) json.get("conditions");
|
||||
JsonObject render = (JsonObject) json.get("render");
|
||||
JsonObject effects = (JsonObject) json.get("effects");
|
||||
|
||||
if ((object != null && conditions != null) || (object != null && render != null) || (object != null && effects != null))
|
||||
{
|
||||
JsonObject block = (JsonObject) object.get("block");
|
||||
JsonObject entity = (JsonObject) object.get("entity");
|
||||
|
||||
if ((block == null && entity == null) || (block != null && entity != null))
|
||||
errored = true;
|
||||
|
||||
if (!errored)
|
||||
{
|
||||
CarryOnOverride override = new CarryOnOverride(file.getAbsolutePath());
|
||||
|
||||
if (block != null)
|
||||
{
|
||||
override.setBlock(true);
|
||||
JsonElement name = block.get("name");
|
||||
JsonElement material = block.get("material");
|
||||
JsonElement hardness = block.get("hardness");
|
||||
JsonElement resistance = block.get("resistance");
|
||||
JsonObject nbt = (JsonObject) block.get("nbt");
|
||||
|
||||
if (name != null)
|
||||
override.setTypeNameBlock(name.getAsString());
|
||||
if (material != null)
|
||||
override.setTypeMaterial(material.getAsString());
|
||||
if (hardness != null)
|
||||
override.setTypeHardness(hardness.getAsString());
|
||||
if (resistance != null)
|
||||
override.setTypeResistance(resistance.getAsString());
|
||||
if (nbt != null)
|
||||
override.setTypeBlockTag(JsonToNBT.getTagFromJson(nbt.toString()));
|
||||
} else
|
||||
{
|
||||
override.setEntity(true);
|
||||
JsonElement name = entity.get("name");
|
||||
JsonElement health = entity.get("health");
|
||||
JsonElement height = entity.get("height");
|
||||
JsonElement width = entity.get("width");
|
||||
JsonObject nbt = (JsonObject) entity.get("nbt");
|
||||
|
||||
if (name != null)
|
||||
override.setTypeNameEntity(name.getAsString());
|
||||
if (health != null)
|
||||
override.setTypeHealth(health.getAsString());
|
||||
if (height != null)
|
||||
override.setTypeHeight(height.getAsString());
|
||||
if (width != null)
|
||||
override.setTypeWidth(width.getAsString());
|
||||
if (nbt != null)
|
||||
override.setTypeEntityTag(JsonToNBT.getTagFromJson(nbt.toString()));
|
||||
}
|
||||
|
||||
if (conditions != null)
|
||||
{
|
||||
JsonElement gamestage = conditions.get("gamestage");
|
||||
JsonElement achievement = conditions.get("advancement");
|
||||
JsonElement xp = conditions.get("xp");
|
||||
JsonElement gamemode = conditions.get("gamemode");
|
||||
JsonElement scoreboard = conditions.get("scoreboard");
|
||||
JsonElement position = conditions.get("position");
|
||||
JsonElement potionEffects = conditions.get("effects");
|
||||
|
||||
if (gamestage != null)
|
||||
override.setConditionGamestage(gamestage.getAsString());
|
||||
if (achievement != null)
|
||||
override.setConditionAchievement(achievement.getAsString());
|
||||
if (xp != null)
|
||||
override.setConditionXp(xp.getAsString());
|
||||
if (gamemode != null)
|
||||
override.setConditionGamemode(gamemode.getAsString());
|
||||
if (scoreboard != null)
|
||||
override.setConditionScoreboard(scoreboard.getAsString());
|
||||
if (position != null)
|
||||
override.setConditionPosition(position.getAsString());
|
||||
if (potionEffects != null)
|
||||
override.setConditionEffects(potionEffects.getAsString());
|
||||
}
|
||||
|
||||
if (render != null)
|
||||
{
|
||||
JsonElement name_block = render.get("name_block");
|
||||
JsonElement name_entity = render.get("name_entity");
|
||||
JsonObject nbt = (JsonObject) render.get("nbt");
|
||||
JsonElement translation = render.get("translation");
|
||||
JsonElement rotation = render.get("rotation");
|
||||
JsonElement scaled = render.get("scale");
|
||||
JsonElement rotationLeftArm = render.get("rotation_left_arm");
|
||||
JsonElement rotationRightArm = render.get("rotation_right_arm");
|
||||
JsonElement renderLeftArm = render.get("render_left_arm");
|
||||
JsonElement renderRightArm = render.get("render_right_arm");
|
||||
|
||||
if (name_block != null)
|
||||
override.setRenderNameBlock(name_block.getAsString());
|
||||
if (name_entity != null)
|
||||
override.setRenderNameEntity(name_entity.getAsString());
|
||||
if (translation != null)
|
||||
override.setRenderTranslation(translation.getAsString());
|
||||
if (rotation != null)
|
||||
override.setRenderRotation(rotation.getAsString());
|
||||
if (scaled != null)
|
||||
override.setRenderscaled(scaled.getAsString());
|
||||
if (nbt != null)
|
||||
override.setRenderNBT(JsonToNBT.getTagFromJson(nbt.toString()));
|
||||
if (rotationLeftArm != null)
|
||||
override.setRenderRotationLeftArm(rotationLeftArm.getAsString());
|
||||
if (rotationRightArm != null)
|
||||
override.setRenderRotationRightArm(rotationRightArm.getAsString());
|
||||
if (renderLeftArm != null)
|
||||
override.setRenderLeftArm(renderLeftArm.getAsBoolean());
|
||||
if (renderRightArm != null)
|
||||
override.setRenderRightArm(renderRightArm.getAsBoolean());
|
||||
}
|
||||
|
||||
if (effects != null)
|
||||
{
|
||||
JsonElement commandInit = effects.get("commandPickup");
|
||||
JsonElement commandLoop = effects.get("commandLoop");
|
||||
JsonElement commandPlace = effects.get("commandPlace");
|
||||
|
||||
if (commandInit != null)
|
||||
override.setCommandInit(commandInit.getAsString());
|
||||
if (commandLoop != null)
|
||||
override.setCommandLoop(commandLoop.getAsString());
|
||||
if (commandPlace != null)
|
||||
override.setCommandPlace(commandPlace.getAsString());
|
||||
}
|
||||
|
||||
OVERRIDES.put(override.hashCode(), override);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Successfully parsed scripts!");
|
||||
} catch (Exception e)
|
||||
{
|
||||
CarryOn.LOGGER.error(e);
|
||||
}
|
||||
}
|
||||
// public static void parseScripts()
|
||||
// {
|
||||
// OVERRIDES.clear();
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// if (!Settings.useScripts.get())
|
||||
// return;
|
||||
//
|
||||
// for (File file : scripts)
|
||||
// {
|
||||
// boolean errored = false;
|
||||
// JsonParser parser = new JsonParser();
|
||||
// JsonObject json = (JsonObject) parser.parse(new FileReader(file.getAbsolutePath()));
|
||||
//
|
||||
// JsonObject object = (JsonObject) json.get("object");
|
||||
// JsonObject conditions = (JsonObject) json.get("conditions");
|
||||
// JsonObject render = (JsonObject) json.get("render");
|
||||
// JsonObject effects = (JsonObject) json.get("effects");
|
||||
//
|
||||
// if ((object != null && conditions != null) || (object != null && render != null) || (object != null && effects != null))
|
||||
// {
|
||||
// JsonObject block = (JsonObject) object.get("block");
|
||||
// JsonObject entity = (JsonObject) object.get("entity");
|
||||
//
|
||||
// if ((block == null && entity == null) || (block != null && entity != null))
|
||||
// errored = true;
|
||||
//
|
||||
// if (!errored)
|
||||
// {
|
||||
// CarryOnOverride override = new CarryOnOverride(file.getAbsolutePath());
|
||||
//
|
||||
// if (block != null)
|
||||
// {
|
||||
// override.setBlock(true);
|
||||
// JsonElement name = block.get("name");
|
||||
// JsonElement material = block.get("material");
|
||||
// JsonElement hardness = block.get("hardness");
|
||||
// JsonElement resistance = block.get("resistance");
|
||||
// JsonObject nbt = (JsonObject) block.get("nbt");
|
||||
//
|
||||
// if (name != null)
|
||||
// override.setTypeNameBlock(name.getAsString());
|
||||
// if (material != null)
|
||||
// override.setTypeMaterial(material.getAsString());
|
||||
// if (hardness != null)
|
||||
// override.setTypeHardness(hardness.getAsString());
|
||||
// if (resistance != null)
|
||||
// override.setTypeResistance(resistance.getAsString());
|
||||
// if (nbt != null)
|
||||
// override.setTypeBlockTag(JsonToNBT.getTagFromJson(nbt.toString()));
|
||||
// } else
|
||||
// {
|
||||
// override.setEntity(true);
|
||||
// JsonElement name = entity.get("name");
|
||||
// JsonElement health = entity.get("health");
|
||||
// JsonElement height = entity.get("height");
|
||||
// JsonElement width = entity.get("width");
|
||||
// JsonObject nbt = (JsonObject) entity.get("nbt");
|
||||
//
|
||||
// if (name != null)
|
||||
// override.setTypeNameEntity(name.getAsString());
|
||||
// if (health != null)
|
||||
// override.setTypeHealth(health.getAsString());
|
||||
// if (height != null)
|
||||
// override.setTypeHeight(height.getAsString());
|
||||
// if (width != null)
|
||||
// override.setTypeWidth(width.getAsString());
|
||||
// if (nbt != null)
|
||||
// override.setTypeEntityTag(JsonToNBT.getTagFromJson(nbt.toString()));
|
||||
// }
|
||||
//
|
||||
// if (conditions != null)
|
||||
// {
|
||||
// JsonElement gamestage = conditions.get("gamestage");
|
||||
// JsonElement achievement = conditions.get("advancement");
|
||||
// JsonElement xp = conditions.get("xp");
|
||||
// JsonElement gamemode = conditions.get("gamemode");
|
||||
// JsonElement scoreboard = conditions.get("scoreboard");
|
||||
// JsonElement position = conditions.get("position");
|
||||
// JsonElement potionEffects = conditions.get("effects");
|
||||
//
|
||||
// if (gamestage != null)
|
||||
// override.setConditionGamestage(gamestage.getAsString());
|
||||
// if (achievement != null)
|
||||
// override.setConditionAchievement(achievement.getAsString());
|
||||
// if (xp != null)
|
||||
// override.setConditionXp(xp.getAsString());
|
||||
// if (gamemode != null)
|
||||
// override.setConditionGamemode(gamemode.getAsString());
|
||||
// if (scoreboard != null)
|
||||
// override.setConditionScoreboard(scoreboard.getAsString());
|
||||
// if (position != null)
|
||||
// override.setConditionPosition(position.getAsString());
|
||||
// if (potionEffects != null)
|
||||
// override.setConditionEffects(potionEffects.getAsString());
|
||||
// }
|
||||
//
|
||||
// if (render != null)
|
||||
// {
|
||||
// JsonElement name_block = render.get("name_block");
|
||||
// JsonElement name_entity = render.get("name_entity");
|
||||
// JsonObject nbt = (JsonObject) render.get("nbt");
|
||||
// JsonElement translation = render.get("translation");
|
||||
// JsonElement rotation = render.get("rotation");
|
||||
// JsonElement scaled = render.get("scale");
|
||||
// JsonElement rotationLeftArm = render.get("rotation_left_arm");
|
||||
// JsonElement rotationRightArm = render.get("rotation_right_arm");
|
||||
// JsonElement renderLeftArm = render.get("render_left_arm");
|
||||
// JsonElement renderRightArm = render.get("render_right_arm");
|
||||
//
|
||||
// if (name_block != null)
|
||||
// override.setRenderNameBlock(name_block.getAsString());
|
||||
// if (name_entity != null)
|
||||
// override.setRenderNameEntity(name_entity.getAsString());
|
||||
// if (translation != null)
|
||||
// override.setRenderTranslation(translation.getAsString());
|
||||
// if (rotation != null)
|
||||
// override.setRenderRotation(rotation.getAsString());
|
||||
// if (scaled != null)
|
||||
// override.setRenderscaled(scaled.getAsString());
|
||||
// if (nbt != null)
|
||||
// override.setRenderNBT(JsonToNBT.getTagFromJson(nbt.toString()));
|
||||
// if (rotationLeftArm != null)
|
||||
// override.setRenderRotationLeftArm(rotationLeftArm.getAsString());
|
||||
// if (rotationRightArm != null)
|
||||
// override.setRenderRotationRightArm(rotationRightArm.getAsString());
|
||||
// if (renderLeftArm != null)
|
||||
// override.setRenderLeftArm(renderLeftArm.getAsBoolean());
|
||||
// if (renderRightArm != null)
|
||||
// override.setRenderRightArm(renderRightArm.getAsBoolean());
|
||||
// }
|
||||
//
|
||||
// if (effects != null)
|
||||
// {
|
||||
// JsonElement commandInit = effects.get("commandPickup");
|
||||
// JsonElement commandLoop = effects.get("commandLoop");
|
||||
// JsonElement commandPlace = effects.get("commandPlace");
|
||||
//
|
||||
// if (commandInit != null)
|
||||
// override.setCommandInit(commandInit.getAsString());
|
||||
// if (commandLoop != null)
|
||||
// override.setCommandLoop(commandLoop.getAsString());
|
||||
// if (commandPlace != null)
|
||||
// override.setCommandPlace(commandPlace.getAsString());
|
||||
// }
|
||||
//
|
||||
// OVERRIDES.put(override.hashCode(), override);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// System.out.println("Successfully parsed scripts!");
|
||||
// } catch (Exception e)
|
||||
// {
|
||||
// CarryOn.LOGGER.error(e);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,9 +35,10 @@ public class ScriptReloadListener extends JsonReloadListener
|
|||
{
|
||||
ScriptReader.OVERRIDES.clear();
|
||||
|
||||
objects.forEach((path, jsonObj) -> {
|
||||
CarryOnOverride override = GSON.fromJson(jsonObj, CarryOnOverride.class);
|
||||
ScriptReader.OVERRIDES.put(override.hashCode(), override);
|
||||
objects.forEach((path, jsonElem) -> {
|
||||
CarryOnOverride override = new CarryOnOverride(jsonElem, path);
|
||||
if(!override.isInvalid)
|
||||
ScriptReader.OVERRIDES.put(override.hashCode(), override);
|
||||
});
|
||||
|
||||
if (EffectiveSide.get().isServer() && ServerLifecycleHooks.getCurrentServer() != null)
|
||||
|
|
|
|||
|
|
@ -45,35 +45,39 @@ public class CarrySlotPacket
|
|||
|
||||
public void handle(Supplier<NetworkEvent.Context> ctx)
|
||||
{
|
||||
ctx.get().enqueueWork(() -> {
|
||||
if (ctx.get().getDirection().getReceptionSide().isClient())
|
||||
{
|
||||
ctx.get().enqueueWork(() -> {
|
||||
|
||||
World world = CarryOn.proxy.getWorld();
|
||||
World world = CarryOn.proxy.getWorld();
|
||||
|
||||
if (world != null)
|
||||
{
|
||||
Entity e = world.getEntityByID(entityid);
|
||||
|
||||
if (e != null && e instanceof PlayerEntity)
|
||||
if (world != null)
|
||||
{
|
||||
PlayerEntity player = (PlayerEntity) e;
|
||||
Entity e = world.getEntityByID(entityid);
|
||||
|
||||
ctx.get().setPacketHandled(true);
|
||||
|
||||
if (slot >= 9)
|
||||
{
|
||||
player.getPersistentData().remove("carrySlot");
|
||||
player.getPersistentData().remove("overrideKey");
|
||||
} else
|
||||
if (e != null && e instanceof PlayerEntity)
|
||||
{
|
||||
PlayerEntity player = (PlayerEntity) e;
|
||||
|
||||
player.getPersistentData().putInt("carrySlot", slot);
|
||||
if (carryOverride != 0)
|
||||
ScriptChecker.setCarryOnOverride(player, carryOverride);
|
||||
ctx.get().setPacketHandled(true);
|
||||
|
||||
if (slot >= 9)
|
||||
{
|
||||
player.getPersistentData().remove("carrySlot");
|
||||
player.getPersistentData().remove("overrideKey");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
player.getPersistentData().putInt("carrySlot", slot);
|
||||
if (carryOverride != 0)
|
||||
ScriptChecker.setCarryOnOverride(player, carryOverride);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,14 +28,17 @@ public class SyncKeybindPacket
|
|||
|
||||
public void handle(Supplier<NetworkEvent.Context> ctx)
|
||||
{
|
||||
ctx.get().enqueueWork(() -> {
|
||||
|
||||
ServerPlayerEntity player = ctx.get().getSender();
|
||||
if (ctx.get().getDirection().getReceptionSide().isServer())
|
||||
{
|
||||
ctx.get().enqueueWork(() -> {
|
||||
|
||||
CarryOnKeybinds.setKeyPressed(player, pressed);
|
||||
|
||||
ctx.get().setPacketHandled(true);
|
||||
});
|
||||
ServerPlayerEntity player = ctx.get().getSender();
|
||||
|
||||
CarryOnKeybinds.setKeyPressed(player, pressed);
|
||||
|
||||
ctx.get().setPacketHandled(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"pack": {
|
||||
"description": "Mod Resources",
|
||||
"pack_format": 4,
|
||||
"_comment": "A pack_format of 4 requires json lang files. Note: we require v4 pack meta for all mods."
|
||||
"description": "Carryon Resources and Data",
|
||||
"pack_format": 6
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user