From 0399bc515c658939a0406f3e2c5daba3fc5877d7 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Wed, 18 May 2022 21:51:42 +0200 Subject: [PATCH] Intensified flapping - Sounds for the display board --- .../source/FillLevelDisplaySource.java | 2 +- .../display/FlapDisplaySection.java | 16 ++++++++--- .../display/FlapDisplayTileEntity.java | 28 ++++++++++++++++--- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/block/display/source/FillLevelDisplaySource.java b/src/main/java/com/simibubi/create/content/logistics/block/display/source/FillLevelDisplaySource.java index f1d8e2ad1..910a72dd1 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/display/source/FillLevelDisplaySource.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/display/source/FillLevelDisplaySource.java @@ -34,7 +34,7 @@ public class FillLevelDisplaySource extends NumericSingleLineDisplaySource { .getString("Label"); int labelSize = label.isEmpty() ? 0 : label.length() + 1; - int length = Math.min(stats.maxColumns() - labelSize, 32); + int length = Math.min(stats.maxColumns() - labelSize, 128); if (context.getTargetTE() instanceof SignBlockEntity) length = (int) (length * 6f / 9f); diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/management/display/FlapDisplaySection.java b/src/main/java/com/simibubi/create/content/logistics/trains/management/display/FlapDisplaySection.java index 7987066da..d59a3b165 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/management/display/FlapDisplaySection.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/management/display/FlapDisplaySection.java @@ -81,15 +81,18 @@ public class FlapDisplaySection { spinningTicks = 0; } - public void tick() { + public int tick() { if (cyclingOptions == null) - return; + return 0; int max = Math.max(4, (int) (cyclingOptions.length * 1.75f)); if (spinningTicks > max) - return; + return 0; + spinningTicks++; if (spinningTicks <= max && spinningTicks < 2) - return; + return spinningTicks == 1 ? 0 : spinning.length; + + int spinningFlaps = 0; for (int i = 0; i < spinning.length; i++) { int increasingChance = Mth.clamp(8 - spinningTicks, 1, 10); boolean continueSpin = Create.RANDOM.nextInt(increasingChance * max / 4) != 0; @@ -102,7 +105,12 @@ public class FlapDisplaySection { spinning[i + 1] &= continueSpin; if (spinningTicks > max) spinning[i] = false; + + if (spinning[i]) + spinningFlaps++; } + + return spinningFlaps; } public float getSize() { diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/management/display/FlapDisplayTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/trains/management/display/FlapDisplayTileEntity.java index a3beee299..7b2dc5d9d 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/management/display/FlapDisplayTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/management/display/FlapDisplayTileEntity.java @@ -5,6 +5,7 @@ import java.util.Arrays; import java.util.List; import com.google.gson.JsonElement; +import com.simibubi.create.AllSoundEvents; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.utility.DyeHelper; @@ -18,6 +19,8 @@ import net.minecraft.core.Vec3i; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; import net.minecraft.world.item.DyeColor; import net.minecraft.world.level.block.entity.BlockEntity; @@ -104,9 +107,25 @@ public class FlapDisplayTileEntity extends KineticTileEntity { isRunning = super.isSpeedRequirementFulfilled(); if (!level.isClientSide || !isRunning) return; - List lines = getLines(); - lines.forEach(l -> l.getSections() - .forEach(FlapDisplaySection::tick)); + int activeFlaps = 0; + for (FlapDisplayLayout line : lines) + for (FlapDisplaySection section : line.getSections()) + activeFlaps += section.tick(); + if (activeFlaps == 0) + return; + + float volume = Mth.clamp(activeFlaps / 20f, 0.25f, 1.5f); + float bgVolume = Mth.clamp(activeFlaps / 40f, 0.25f, 1f); + BlockPos middle = worldPosition.relative(getDirection().getClockWise(), xSize / 2) + .relative(Direction.DOWN, ySize / 2); + AllSoundEvents.SCROLL_VALUE.playAt(level, middle, volume, 0.56f, false); + level.playLocalSound(middle.getX(), middle.getY(), middle.getZ(), SoundEvents.CALCITE_HIT, SoundSource.BLOCKS, + .35f * bgVolume, 1.95f, false); + } + + @Override + protected boolean isNoisy() { + return false; } @Override @@ -279,7 +298,8 @@ public class FlapDisplayTileEntity extends KineticTileEntity { public int getLineColor(int line) { DyeColor color = colour[line]; - return color == null ? 0xFF_D3C6BA : DyeHelper.DYE_TABLE.get(color) + return color == null ? 0xFF_D3C6BA + : DyeHelper.DYE_TABLE.get(color) .getFirst() | 0xFF_000000; } }