Search in sources :

Example 1 with ModuleJetpackUnit

use of mekanism.common.content.gear.mekasuit.ModuleJetpackUnit in project Mekanism by mekanism.

the class ClientTickHandler method tickStart.

public void tickStart() {
    MekanismClient.ticksPassed++;
    if (firstTick && minecraft.level != null) {
        MekanismClient.launchClient();
        firstTick = false;
    }
    if (minecraft.level != null) {
        shouldReset = true;
    } else if (shouldReset) {
        MekanismClient.reset();
        shouldReset = false;
    }
    if (minecraft.level != null && minecraft.player != null && !minecraft.isPaused()) {
        if (!initHoliday || MekanismClient.ticksPassed % 1_200 == 0) {
            HolidayManager.notify(Minecraft.getInstance().player);
            initHoliday = true;
        }
        // Reboot player sounds if needed
        SoundHandler.restartSounds();
        if (minecraft.level.getGameTime() - lastScrollTime > 20) {
            scrollDelta = 0;
        }
        RadiationManager.INSTANCE.tickClient(minecraft.player);
        UUID playerUUID = minecraft.player.getUUID();
        // Update player's state for various items; this also automatically notifies server if something changed and
        // kicks off sounds as necessary
        Mekanism.playerState.setJetpackState(playerUUID, isJetpackActive(minecraft.player), true);
        Mekanism.playerState.setScubaMaskState(playerUUID, isScubaMaskOn(minecraft.player), true);
        Mekanism.playerState.setGravitationalModulationState(playerUUID, isGravitationalModulationOn(minecraft.player), true);
        Mekanism.playerState.setFlamethrowerState(playerUUID, hasFlamethrower(minecraft.player), isFlamethrowerOn(minecraft.player), true);
        for (Iterator<Entry<PlayerEntity, TeleportData>> iter = portableTeleports.entrySet().iterator(); iter.hasNext(); ) {
            Entry<PlayerEntity, TeleportData> entry = iter.next();
            PlayerEntity player = entry.getKey();
            for (int i = 0; i < 100; i++) {
                double x = player.getX() + rand.nextDouble() - 0.5D;
                double y = player.getY() + rand.nextDouble() * 2 - 2D;
                double z = player.getZ() + rand.nextDouble() - 0.5D;
                minecraft.level.addParticle(ParticleTypes.PORTAL, x, y, z, 0, 1, 0);
            }
            TeleportData data = entry.getValue();
            if (minecraft.level.getGameTime() == data.teleportTime) {
                Mekanism.packetHandler.sendToServer(new PacketPortableTeleporterTeleport(data.hand, data.identity));
                iter.remove();
            }
        }
        ItemStack chestStack = minecraft.player.getItemBySlot(EquipmentSlotType.CHEST);
        IModule<ModuleJetpackUnit> jetpackModule = MekanismAPI.getModuleHelper().load(chestStack, MekanismModules.JETPACK_UNIT);
        if (!chestStack.isEmpty() && (chestStack.getItem() instanceof ItemJetpack || jetpackModule != null)) {
            MekanismClient.updateKey(minecraft.player.input.jumping, KeySync.ASCEND);
        }
        if (isJetpackActive(minecraft.player)) {
            JetpackMode mode = CommonPlayerTickHandler.getJetpackMode(chestStack);
            if (CommonPlayerTickHandler.handleJetpackMotion(minecraft.player, mode, () -> minecraft.player.input.jumping)) {
                minecraft.player.fallDistance = 0.0F;
            }
        }
        if (isScubaMaskOn(minecraft.player) && minecraft.player.getAirSupply() == minecraft.player.getMaxAirSupply()) {
            for (EffectInstance effect : minecraft.player.getActiveEffects()) {
                for (int i = 0; i < 9; i++) {
                    MekanismUtils.speedUpEffectSafely(minecraft.player, effect);
                }
            }
        }
        if (isVisionEnhancementOn(minecraft.player)) {
            visionEnhancement = true;
            // adds if it doesn't exist, otherwise tops off duration to 220. equal or less than 200 will make vision flickers
            minecraft.player.addEffect(new EffectInstance(Effects.NIGHT_VISION, 220, 0, false, true, false));
        } else if (visionEnhancement) {
            visionEnhancement = false;
            EffectInstance effect = minecraft.player.getEffect(Effects.NIGHT_VISION);
            if (effect != null && effect.getDuration() <= 220) {
                // Only remove it if it is our effect and not one that has a longer remaining duration
                minecraft.player.removeEffect(Effects.NIGHT_VISION);
            }
        }
        ItemStack stack = minecraft.player.getItemBySlot(EquipmentSlotType.MAINHAND);
        if (MekKeyHandler.isRadialPressed() && stack.getItem() instanceof IRadialModeItem) {
            if (minecraft.screen == null || minecraft.screen instanceof GuiRadialSelector) {
                updateSelectorRenderer((IRadialModeItem<?>) stack.getItem());
            }
        } else if (minecraft.screen instanceof GuiRadialSelector) {
            minecraft.setScreen(null);
        }
        if (MekanismConfig.client.enablePlayerSounds.get()) {
            RadiationScale scale = RadiationManager.INSTANCE.getClientScale();
            if (scale != RadiationScale.NONE && !SoundHandler.radiationSoundMap.containsKey(scale)) {
                GeigerSound sound = GeigerSound.create(minecraft.player, scale);
                SoundHandler.radiationSoundMap.put(scale, sound);
                SoundHandler.playSound(sound);
            }
        }
    }
}
Also used : GuiRadialSelector(mekanism.client.gui.GuiRadialSelector) ItemJetpack(mekanism.common.item.gear.ItemJetpack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ModuleJetpackUnit(mekanism.common.content.gear.mekasuit.ModuleJetpackUnit) Entry(java.util.Map.Entry) GeigerSound(mekanism.client.sound.GeigerSound) IRadialModeItem(mekanism.common.item.interfaces.IRadialModeItem) RadiationScale(mekanism.common.lib.radiation.RadiationManager.RadiationScale) PacketPortableTeleporterTeleport(mekanism.common.network.to_server.PacketPortableTeleporterTeleport) JetpackMode(mekanism.common.item.gear.ItemJetpack.JetpackMode) UUID(java.util.UUID) ItemStack(net.minecraft.item.ItemStack) EffectInstance(net.minecraft.potion.EffectInstance)

Aggregations

Entry (java.util.Map.Entry)1 UUID (java.util.UUID)1 GuiRadialSelector (mekanism.client.gui.GuiRadialSelector)1 GeigerSound (mekanism.client.sound.GeigerSound)1 ModuleJetpackUnit (mekanism.common.content.gear.mekasuit.ModuleJetpackUnit)1 ItemJetpack (mekanism.common.item.gear.ItemJetpack)1 JetpackMode (mekanism.common.item.gear.ItemJetpack.JetpackMode)1 IRadialModeItem (mekanism.common.item.interfaces.IRadialModeItem)1 RadiationScale (mekanism.common.lib.radiation.RadiationManager.RadiationScale)1 PacketPortableTeleporterTeleport (mekanism.common.network.to_server.PacketPortableTeleporterTeleport)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ItemStack (net.minecraft.item.ItemStack)1 EffectInstance (net.minecraft.potion.EffectInstance)1