Search in sources :

Example 1 with JetpackMode

use of mekanism.common.item.gear.ItemJetpack.JetpackMode 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)

Example 2 with JetpackMode

use of mekanism.common.item.gear.ItemJetpack.JetpackMode 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)

Aggregations

ItemJetpack (mekanism.common.item.gear.ItemJetpack)2 JetpackMode (mekanism.common.item.gear.ItemJetpack.JetpackMode)2 ItemStack (net.minecraft.item.ItemStack)2 EffectInstance (net.minecraft.potion.EffectInstance)2 Entry (java.util.Map.Entry)1 UUID (java.util.UUID)1 GasStack (mekanism.api.chemical.gas.GasStack)1 GuiRadialSelector (mekanism.client.gui.GuiRadialSelector)1 GeigerSound (mekanism.client.sound.GeigerSound)1 ModuleJetpackUnit (mekanism.common.content.gear.mekasuit.ModuleJetpackUnit)1 EntityFlame (mekanism.common.entity.EntityFlame)1 ItemFlamethrower (mekanism.common.item.gear.ItemFlamethrower)1 ItemMekaSuitArmor (mekanism.common.item.gear.ItemMekaSuitArmor)1 ItemScubaTank (mekanism.common.item.gear.ItemScubaTank)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 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1