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);
}
}
}
}
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);
}
Aggregations