Search in sources :

Example 1 with Gas

use of ladysnake.gaspunk.gas.Gas in project Gaspunk by Ladysnake.

the class GasDeserializer method write.

@Override
public void write(JsonWriter out, Gas value) throws IOException {
    out.beginObject();
    if (value.getType() instanceof GasTypes) {
        GasTypes type = (GasTypes) value.getType();
        out.name("gasType");
        out.value(type.name());
    } else
        throw new JsonException("Cannot serialize unknown type " + value.getType());
    if (value.getParticleType() instanceof GasParticleTypes) {
        GasParticleTypes type = (GasParticleTypes) value.getParticleType();
        out.name("particleType");
        out.value(type.name());
    } else
        throw new JsonException("Cannot serialize unknown type " + value.getParticleType());
    out.name("color");
    out.value(value.getColor());
    out.name("bottleColor");
    out.value(value.getBottleColor());
    out.name("agents");
    out.beginArray();
    for (Gas.AgentEffect effect : value.getAgents()) {
        out.beginObject();
        out.name("agent");
        out.value(GasAgents.getId(effect.getAgent()).toString());
        out.name("potency");
        out.value(effect.getPotency());
        out.endObject();
    }
    out.endArray();
    out.endObject();
}
Also used : JsonException(net.minecraft.client.util.JsonException) IGas(ladysnake.gaspunk.api.IGas) Gas(ladysnake.gaspunk.gas.Gas)

Example 2 with Gas

use of ladysnake.gaspunk.gas.Gas in project Gaspunk by Ladysnake.

the class SicknessTests method testGasTick.

// @Test
public void testGasTick() {
    IBreathingHandler handler = CapabilityBreathing.getHandler(mockedCreeper).get();
    Gas gas = new Gas(GasTypes.SMOKE, 0xFF);
    handler.setConcentration(gas, 0.5f);
    assertTrue(handler.getGasConcentrations().containsKey(gas));
    handler.tick();
    assertFalse(handler.getGasConcentrations().containsKey(gas));
}
Also used : IBreathingHandler(ladysnake.gaspunk.api.IBreathingHandler) SuspendableGas(ladysnake.gaspunk.gas.SuspendableGas) Gas(ladysnake.gaspunk.gas.Gas)

Example 3 with Gas

use of ladysnake.gaspunk.gas.Gas in project Gaspunk by Ladysnake.

the class SicknessTests method testMustardGas.

// @Test
public void testMustardGas() {
    IBreathingHandler breathingHandler = CapabilityBreathing.getHandler(mockedCreeper).get();
    final float concentration = 1.0f;
    final float time = 5;
    Gas gas = new Gas(GasTypes.GAS, 0xFF, NERVE, 1);
    for (int i = 0; i < time; i++) {
        breathingHandler.setConcentration(gas, concentration);
        breathingHandler.tick();
    }
    float potency = gas.getAgents().get(0).getPotency();
    float oracle = potency * time;
// TODO make a test for evolution in gas concentration
// assertEquals(oracle, breathingHandler.getGasConcentrations().get(ModGases.MUSTARD_GAS), 1E-8f);
}
Also used : IBreathingHandler(ladysnake.gaspunk.api.IBreathingHandler) SuspendableGas(ladysnake.gaspunk.gas.SuspendableGas) Gas(ladysnake.gaspunk.gas.Gas)

Example 4 with Gas

use of ladysnake.gaspunk.gas.Gas in project Gaspunk by Ladysnake.

the class ModGases method addGases.

@SubscribeEvent
public static void addGases(RegistryEvent.Register<PotionType> event) {
    REGISTRY.register(new SuspendableGas(GasTypes.GAS, 0x00FFFFFF, GasAgents.getAgent(new ResourceLocation(GasPunk.MOD_ID, "nerve")), 0.8F).setRegistryName("sarin_gas"));
    REGISTRY.register(new Gas(GasTypes.GAS, GasParticleTypes.GAS, 0x99FFFFFF, 0xAA0033FF, ImmutableList.of(), new String[0]).setRegistryName("air"));
    for (EnumDyeColor color : EnumDyeColor.values()) {
        // this is probably illegal in 53 states but I didn't want to parse the value back from the table
        REGISTRY.register(new Gas(GasTypes.SMOKE, 0xFF000000 | (int) ReflectionHelper.getPrivateValue(EnumDyeColor.class, color, "colorValue", "field_193351_w")).setRegistryName("colored_smoke_" + color.getName()));
    }
}
Also used : SuspendableGas(ladysnake.gaspunk.gas.SuspendableGas) ResourceLocation(net.minecraft.util.ResourceLocation) SuspendableGas(ladysnake.gaspunk.gas.SuspendableGas) Gas(ladysnake.gaspunk.gas.Gas) IGas(ladysnake.gaspunk.api.IGas) EnumDyeColor(net.minecraft.item.EnumDyeColor) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with Gas

use of ladysnake.gaspunk.gas.Gas in project Gaspunk by Ladysnake.

the class GasDeserializer method loadGases.

@SubscribeEvent
public static void loadGases(RegistryEvent.Register<IGas> event) {
    ModContainer gaspunkContainer = Loader.instance().activeModContainer();
    Loader.instance().getActiveModList().forEach(GasDeserializer::loadGases);
    Loader.instance().setActiveModContainer(gaspunkContainer);
    File configFolder = new File(Loader.instance().getConfigDir(), GasPunk.MOD_ID + "/custom_gases");
    // if the config folder was just created or couldn't be created, no need to search it
    try {
        if (!configFolder.mkdirs() && configFolder.exists()) {
            Files.walk(configFolder.toPath()).forEach(path -> loadGases(configFolder.toPath(), path));
        } else if (configFolder.exists()) {
            // generate an example gas file
            IGas exampleGas = new Gas.Builder().addAgent(GasAgents.getAgent(new ResourceLocation(GasPunk.MOD_ID, "lachrymator")), 0.5f).addAgent(GasAgents.getAgent(new ResourceLocation(GasPunk.MOD_ID, "nerve")), 0.375f).setColor(0x55CAFE66).setBottleColor(0x75DADD10).setType(GasTypes.GAS).addTooltipLine("For more examples, check the technical wiki:").addTooltipLine("https://github.com/Ladysnake/Gaspunk/wiki").build();
            Files.write(configFolder.toPath().resolve("_example.json"), GSON.toJson(exampleGas).getBytes(), StandardOpenOption.CREATE_NEW);
        }
    } catch (IOException e) {
        GasPunk.LOGGER.error("Error while loading gases from config", e);
    }
}
Also used : IGas(ladysnake.gaspunk.api.IGas) ModContainer(net.minecraftforge.fml.common.ModContainer) ResourceLocation(net.minecraft.util.ResourceLocation) AbstractGas(ladysnake.gaspunk.api.AbstractGas) IGas(ladysnake.gaspunk.api.IGas) Gas(ladysnake.gaspunk.gas.Gas) IOException(java.io.IOException) File(java.io.File) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

Gas (ladysnake.gaspunk.gas.Gas)6 IGas (ladysnake.gaspunk.api.IGas)4 SuspendableGas (ladysnake.gaspunk.gas.SuspendableGas)3 IOException (java.io.IOException)2 AbstractGas (ladysnake.gaspunk.api.AbstractGas)2 IBreathingHandler (ladysnake.gaspunk.api.IBreathingHandler)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 JsonException (net.minecraft.client.util.JsonException)1 EnumDyeColor (net.minecraft.item.EnumDyeColor)1 ModContainer (net.minecraftforge.fml.common.ModContainer)1 FormattedMessage (org.apache.logging.log4j.message.FormattedMessage)1