Search in sources :

Example 41 with GasStack

use of mekanism.api.chemical.gas.GasStack in project Mekanism by mekanism.

the class ItemFlamethrower method addHUDStrings.

@Override
public void addHUDStrings(List<ITextComponent> list, PlayerEntity player, ItemStack stack, EquipmentSlotType slotType) {
    boolean hasGas = false;
    Optional<IGasHandler> capability = stack.getCapability(Capabilities.GAS_HANDLER_CAPABILITY).resolve();
    if (capability.isPresent()) {
        IGasHandler gasHandlerItem = capability.get();
        if (gasHandlerItem.getTanks() > 0) {
            // Validate something didn't go terribly wrong, and we actually do have the tank we expect to have
            GasStack storedGas = gasHandlerItem.getChemicalInTank(0);
            if (!storedGas.isEmpty()) {
                list.add(MekanismLang.FLAMETHROWER_STORED.translateColored(EnumColor.GRAY, EnumColor.ORANGE, storedGas.getAmount()));
                hasGas = true;
            }
        }
    }
    if (!hasGas) {
        list.add(MekanismLang.FLAMETHROWER_STORED.translateColored(EnumColor.GRAY, EnumColor.ORANGE, MekanismLang.NO_GAS));
    }
    list.add(MekanismLang.MODE.translate(getMode(stack)));
}
Also used : IGasHandler(mekanism.api.chemical.gas.IGasHandler) GasStack(mekanism.api.chemical.gas.GasStack)

Example 42 with GasStack

use of mekanism.api.chemical.gas.GasStack in project Mekanism by mekanism.

the class CommonPlayerTickHandler method tickEnd.

private void tickEnd(PlayerEntity player) {
    Mekanism.playerState.updateStepAssist(player);
    if (player instanceof ServerPlayerEntity) {
        RadiationManager.INSTANCE.tickServer((ServerPlayerEntity) player);
    }
    ItemStack currentItem = player.inventory.getSelected();
    if (isFlamethrowerOn(player, currentItem)) {
        EntityFlame flame = EntityFlame.create(player);
        if (flame != null) {
            if (flame.isAlive()) {
                // If the flame is alive (and didn't just instantly hit a block while trying to spawn add it to the world)
                player.level.addFreshEntity(flame);
            }
            if (MekanismUtils.isPlayingMode(player)) {
                ((ItemFlamethrower) currentItem.getItem()).useGas(currentItem, 1);
            }
        }
    }
    ItemStack chest = player.getItemBySlot(EquipmentSlotType.CHEST);
    if (isJetpackOn(player, chest)) {
        JetpackMode mode = getJetpackMode(chest);
        if (handleJetpackMotion(player, mode, () -> Mekanism.keyMap.has(player.getUUID(), KeySync.ASCEND))) {
            player.fallDistance = 0.0F;
            if (player instanceof ServerPlayerEntity) {
                ((ServerPlayerEntity) player).connection.aboveGroundTickCount = 0;
            }
        }
        if (chest.getItem() instanceof ItemJetpack) {
            ((ItemJetpack) chest.getItem()).useGas(chest, 1);
        } else {
            ((ItemMekaSuitArmor) chest.getItem()).useGas(chest, MekanismGases.HYDROGEN.get(), 1);
        }
    }
    if (isScubaMaskOn(player, chest)) {
        ItemScubaTank tank = (ItemScubaTank) chest.getItem();
        final int max = player.getMaxAirSupply();
        tank.useGas(chest, 1);
        GasStack received = tank.useGas(chest, max - player.getAirSupply());
        if (!received.isEmpty()) {
            player.setAirSupply(player.getAirSupply() + (int) received.getAmount());
        }
        if (player.getAirSupply() == max) {
            for (EffectInstance effect : player.getActiveEffects()) {
                for (int i = 0; i < 9; i++) {
                    MekanismUtils.speedUpEffectSafely(player, effect);
                }
            }
        }
    }
    Mekanism.playerState.updateFlightInfo(player);
}
Also used : ItemFlamethrower(mekanism.common.item.gear.ItemFlamethrower) ItemJetpack(mekanism.common.item.gear.ItemJetpack) ItemMekaSuitArmor(mekanism.common.item.gear.ItemMekaSuitArmor) ItemScubaTank(mekanism.common.item.gear.ItemScubaTank) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) EntityFlame(mekanism.common.entity.EntityFlame) JetpackMode(mekanism.common.item.gear.ItemJetpack.JetpackMode) GasStack(mekanism.api.chemical.gas.GasStack) ItemStack(net.minecraft.item.ItemStack) EffectInstance(net.minecraft.potion.EffectInstance)

Example 43 with GasStack

use of mekanism.api.chemical.gas.GasStack in project Mekanism by mekanism.

the class RenderNutritionalLiquifier method render.

@Override
protected void render(TileEntityNutritionalLiquifier tile, float partialTick, MatrixStack matrix, IRenderTypeBuffer renderer, int light, int overlayLight, IProfiler profiler) {
    if (!tile.gasTank.isEmpty()) {
        GasStack paste = tile.gasTank.getStack();
        float gasScale = paste.getAmount() / (float) tile.gasTank.getCapacity();
        MekanismRenderer.renderObject(getPasteModel(paste), matrix, renderer.getBuffer(Atlases.translucentCullBlockSheet()), MekanismRenderer.getColorARGB(paste, gasScale, true), light, overlayLight, FaceDisplay.FRONT);
    }
    boolean active = tile.getActive();
    matrix.pushPose();
    if (active) {
        matrix.translate(0.5, 0.5, 0.5);
        matrix.mulPose(Vector3f.YP.rotationDegrees((tile.getLevel().getGameTime() + partialTick) * BLADE_SPEED % 360));
        matrix.translate(-0.5, -0.5, -0.5);
    }
    Entry entry = matrix.last();
    IVertexBuilder bladeBuffer = renderer.getBuffer(Atlases.solidBlockSheet());
    for (BakedQuad quad : MekanismModelCache.INSTANCE.LIQUIFIER_BLADE.getBakedModel().getQuads(null, null, tile.getLevel().random)) {
        bladeBuffer.addVertexData(entry, quad, 1F, 1F, 1F, 1F, light, overlayLight);
    }
    matrix.popPose();
    // Render the item and particle
    ItemStack stack = tile.getRenderStack();
    if (!stack.isEmpty()) {
        matrix.pushPose();
        matrix.translate(0.5, 0.6, 0.5);
        if (active) {
            // Make the item rotate if the liquifier is active
            matrix.mulPose(Vector3f.YP.rotationDegrees((tile.getLevel().getGameTime() + partialTick) * ROTATE_SPEED % 360));
        }
        Minecraft.getInstance().getItemRenderer().renderStatic(stack, TransformType.GROUND, light, overlayLight, matrix, renderer);
        matrix.popPose();
        if (active && Minecraft.getInstance().options.particles != ParticleStatus.MINIMAL) {
            // Render eating particles
            PseudoParticleData pseudoParticles = particles.computeIfAbsent(tile, t -> new PseudoParticleData());
            if (!Minecraft.getInstance().isPaused()) {
                // Don't add particles if the game is paused
                if (pseudoParticles.lastTick != tile.getLevel().getGameTime()) {
                    pseudoParticles.lastTick = tile.getLevel().getGameTime();
                    pseudoParticles.particles.removeIf(PseudoParticle::tick);
                }
                int rate = Minecraft.getInstance().options.particles == ParticleStatus.DECREASED ? 12 : 4;
                if (tile.getLevel().getGameTime() % rate == 0) {
                    pseudoParticles.particles.add(new PseudoParticle(tile.getLevel(), stack));
                // TODO - 1.18: Try using this instead of our pseudo particles as maybe it will be able to render properly
                // behind translucent glass and our contents in fast
                /*Vector3d motion = new Vector3d((world.random.nextFloat() - 0.5D) * 0.075D,
                              world.random.nextDouble() * 0.1D,
                              (world.random.nextFloat() - 0.5D) * 0.075D);
                        Vector3d position = new Vector3d((world.random.nextFloat() - 0.5D) * 0.3D,
                              (world.random.nextFloat() - 0.5D) * 0.3D,
                              (world.random.nextFloat() - 0.5D) * 0.3D);
                        position = position.add(pos.getX() + 0.5, pos.getY() + 0.55, pos.getZ() + 0.5);
                        world.addParticle(new ItemParticleData(ParticleTypes.ITEM, stack), position.x, position.y, position.z, motion.x, motion.y + 0.05D, motion.z);*/
                }
            }
            // Render particles
            IVertexBuilder buffer = renderer.getBuffer(MekanismRenderType.nutritionalParticle());
            matrix.pushPose();
            matrix.translate(0.5, 0.55, 0.5);
            Matrix4f matrix4f = matrix.last().pose();
            for (PseudoParticle particle : pseudoParticles.particles) {
                particle.render(matrix4f, buffer, partialTick, light);
            }
            matrix.popPose();
        } else {
            particles.remove(tile);
        }
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.model.BakedQuad) Entry(com.mojang.blaze3d.matrix.MatrixStack.Entry) Matrix4f(net.minecraft.util.math.vector.Matrix4f) GasStack(mekanism.api.chemical.gas.GasStack) ItemStack(net.minecraft.item.ItemStack) IVertexBuilder(com.mojang.blaze3d.vertex.IVertexBuilder)

Example 44 with GasStack

use of mekanism.api.chemical.gas.GasStack in project Mekanism by mekanism.

the class SerializerHelper method serializeBoxedChemicalStack.

/**
 * Helper to serialize a Boxed Chemical Stack into a Json Object.
 *
 * @param stack Stack to serialize.
 *
 * @return Json representation.
 */
public static JsonElement serializeBoxedChemicalStack(@Nonnull BoxedChemicalStack stack) {
    JsonObject json;
    ChemicalType chemicalType = stack.getChemicalType();
    if (chemicalType == ChemicalType.GAS) {
        json = serializeGasStack((GasStack) stack.getChemicalStack());
    } else if (chemicalType == ChemicalType.INFUSION) {
        json = serializeInfusionStack((InfusionStack) stack.getChemicalStack());
    } else if (chemicalType == ChemicalType.PIGMENT) {
        json = serializePigmentStack((PigmentStack) stack.getChemicalStack());
    } else if (chemicalType == ChemicalType.SLURRY) {
        json = serializeSlurryStack((SlurryStack) stack.getChemicalStack());
    } else {
        throw new IllegalStateException("Unknown chemical type");
    }
    json.addProperty(JsonConstants.CHEMICAL_TYPE, chemicalType.getSerializedName());
    return json;
}
Also used : PigmentStack(mekanism.api.chemical.pigment.PigmentStack) ChemicalType(mekanism.api.chemical.ChemicalType) JsonObject(com.google.gson.JsonObject) GasStack(mekanism.api.chemical.gas.GasStack)

Aggregations

GasStack (mekanism.api.chemical.gas.GasStack)44 ItemStack (net.minecraft.item.ItemStack)17 JsonSyntaxException (com.google.gson.JsonSyntaxException)8 IngredientHelper (mekanism.common.integration.projecte.IngredientHelper)8 FluidStackIngredient (mekanism.api.recipes.inputs.FluidStackIngredient)7 FluidStack (net.minecraftforge.fluids.FluidStack)7 List (java.util.List)6 IGasHandler (mekanism.api.chemical.gas.IGasHandler)6 PigmentStack (mekanism.api.chemical.pigment.PigmentStack)6 FloatingLong (mekanism.api.math.FloatingLong)6 GasStackIngredient (mekanism.api.recipes.inputs.chemical.GasStackIngredient)6 NonNull (mekanism.api.annotations.NonNull)5 InfusionStack (mekanism.api.chemical.infuse.InfusionStack)5 SlurryStack (mekanism.api.chemical.slurry.SlurryStack)5 Nonnull (javax.annotation.Nonnull)4 JsonElement (com.google.gson.JsonElement)3 Collections (java.util.Collections)3 Nullable (javax.annotation.Nullable)3 ChemicalType (mekanism.api.chemical.ChemicalType)3 BoxedChemicalStack (mekanism.api.chemical.merged.BoxedChemicalStack)3