| 1 | package net.minecraft.client.renderer;
|
| 2 |
|
| 3 | import java.util.HashMap;
|
| 4 | import java.util.Map;
|
| 5 | import java.util.function.Supplier;
|
| 6 | import net.fabricmc.api.EnvType;
|
| 7 | import net.fabricmc.api.Environment;
|
| 8 | import net.minecraft.client.Camera;
|
| 9 | import net.minecraft.client.Minecraft;
|
| 10 | import net.minecraft.client.multiplayer.ClientLevel;
|
| 11 | import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
| 12 | import net.minecraft.client.resources.sounds.SoundInstance;
|
| 13 | import net.minecraft.core.BlockPos;
|
| 14 | import net.minecraft.core.Direction;
|
| 15 | import net.minecraft.core.Holder;
|
| 16 | import net.minecraft.core.Direction.Axis;
|
| 17 | import net.minecraft.core.particles.ItemParticleOption;
|
| 18 | import net.minecraft.core.particles.ParticleType;
|
| 19 | import net.minecraft.core.particles.ParticleTypes;
|
| 20 | import net.minecraft.core.particles.PowerParticleOption;
|
| 21 | import net.minecraft.core.particles.SculkChargeParticleOptions;
|
| 22 | import net.minecraft.core.particles.ShriekParticleOption;
|
| 23 | import net.minecraft.core.particles.SimpleParticleType;
|
| 24 | import net.minecraft.core.particles.SpellParticleOption;
|
| 25 | import net.minecraft.core.registries.Registries;
|
| 26 | import net.minecraft.sounds.SoundEvent;
|
| 27 | import net.minecraft.sounds.SoundEvents;
|
| 28 | import net.minecraft.sounds.SoundSource;
|
| 29 | import net.minecraft.util.BlockUtil;
|
| 30 | import net.minecraft.util.Mth;
|
| 31 | import net.minecraft.util.ParticleUtils;
|
| 32 | import net.minecraft.util.RandomSource;
|
| 33 | import net.minecraft.util.valueproviders.IntProvider;
|
| 34 | import net.minecraft.util.valueproviders.UniformInt;
|
| 35 | import net.minecraft.world.entity.EntityTypes;
|
| 36 | import net.minecraft.world.entity.LivingEntity;
|
| 37 | import net.minecraft.world.item.BoneMealItem;
|
| 38 | import net.minecraft.world.item.Items;
|
| 39 | import net.minecraft.world.item.JukeboxSong;
|
| 40 | import net.minecraft.world.level.Level;
|
| 41 | import net.minecraft.world.level.block.Block;
|
| 42 | import net.minecraft.world.level.block.BrushableBlock;
|
| 43 | import net.minecraft.world.level.block.ComposterBlock;
|
| 44 | import net.minecraft.world.level.block.MultifaceBlock;
|
| 45 | import net.minecraft.world.level.block.PointedDripstoneBlock;
|
| 46 | import net.minecraft.world.level.block.SculkShriekerBlock;
|
| 47 | import net.minecraft.world.level.block.SoundType;
|
| 48 | import net.minecraft.world.level.block.LevelEvent.Value;
|
| 49 | import net.minecraft.world.level.block.entity.trialspawner.TrialSpawner;
|
| 50 | import net.minecraft.world.level.block.entity.trialspawner.TrialSpawner.FlameParticle;
|
| 51 | import net.minecraft.world.level.block.entity.vault.VaultBlockEntity;
|
| 52 | import net.minecraft.world.level.block.entity.vault.VaultBlockEntity.Client;
|
| 53 | import net.minecraft.world.level.block.state.BlockState;
|
| 54 | import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
| 55 | import net.minecraft.world.phys.AABB;
|
| 56 | import net.minecraft.world.phys.Vec3;
|
| 57 |
|
| 58 | @Environment(EnvType.CLIENT)
|
| 59 | public class LevelEventHandler {
|
| 60 | private final Minecraft minecraft;
|
| 61 | private final ClientLevel level;
|
| 62 | private final Map<BlockPos, SoundInstance> playingJukeboxSongs = new HashMap<>();
|
| 63 |
|
| 64 | public LevelEventHandler(final Minecraft minecraft, final ClientLevel level) {
|
| 65 | this.minecraft = minecraft;
|
| 66 | this.level = level;
|
| 67 | }
|
| 68 |
|
| 69 | public void globalLevelEvent(final @Value int type, final BlockPos pos, final int data) {
|
| 70 | switch (type) {
|
| 71 | case 1023:
|
| 72 | case 1028:
|
| 73 | case 1038:
|
| 74 | Camera camera = this.minecraft.gameRenderer.mainCamera();
|
| 75 | if (camera.isInitialized()) {
|
| 76 | Vec3 directionToEvent = Vec3.atCenterOf(pos).subtract(camera.position()).normalize();
|
| 77 | Vec3 soundPos = camera.position().add(directionToEvent.scale(2.0));
|
| 78 | if (type == 1023) {
|
| 79 | this.level.playLocalSound(soundPos.x, soundPos.y, soundPos.z, SoundEvents.WITHER_SPAWN, SoundSource.HOSTILE, 1.0F, 1.0F, false);
|
| 80 | } else if (type == 1038) {
|
| 81 | this.level.playLocalSound(soundPos.x, soundPos.y, soundPos.z, SoundEvents.END_PORTAL_SPAWN, SoundSource.HOSTILE, 1.0F, 1.0F, false);
|
| 82 | } else {
|
| 83 | this.level.playLocalSound(soundPos.x, soundPos.y, soundPos.z, SoundEvents.ENDER_DRAGON_DEATH, SoundSource.HOSTILE, 5.0F, 1.0F, false);
|
| 84 | }
|
| 85 | }
|
| 86 | }
|
| 87 | }
|
| 88 |
|
| 89 | public void levelEvent(final @Value int eventType, final BlockPos pos, final int data) {
|
| 90 | RandomSource random = this.level.getRandom();
|
| 91 | switch (eventType) {
|
| 92 | case 1000:
|
| 93 | this.level.playLocalSound(pos, SoundEvents.DISPENSER_DISPENSE, SoundSource.BLOCKS, 1.0F, 1.0F, false);
|
| 94 | break;
|
| 95 | case 1001:
|
| 96 | this.level.playLocalSound(pos, SoundEvents.DISPENSER_FAIL, SoundSource.BLOCKS, 1.0F, 1.2F, false);
|
| 97 | break;
|
| 98 | case 1002:
|
| 99 | this.level.playLocalSound(pos, SoundEvents.DISPENSER_LAUNCH, SoundSource.BLOCKS, 1.0F, 1.2F, false);
|
| 100 | break;
|
| 101 | case 1004:
|
| 102 | this.level.playLocalSound(pos, SoundEvents.FIREWORK_ROCKET_SHOOT, SoundSource.NEUTRAL, 1.0F, 1.2F, false);
|
| 103 | break;
|
| 104 | case 1009:
|
| 105 | if (data == 0) {
|
| 106 | this.level.playLocalSound(pos, SoundEvents.FIRE_EXTINGUISH, SoundSource.BLOCKS, 0.5F, 2.6F + (random.nextFloat() - random.nextFloat()) * 0.8F, false);
|
| 107 | } else if (data == 1) {
|
| 108 | this.level
|
| 109 | .playLocalSound(pos, SoundEvents.GENERIC_EXTINGUISH_FIRE, SoundSource.BLOCKS, 0.7F, 1.6F + (random.nextFloat() - random.nextFloat()) * 0.4F, false);
|
| 110 | }
|
| 111 | break;
|
| 112 | case 1010:
|
| 113 | this.level.registryAccess().lookupOrThrow(Registries.JUKEBOX_SONG).get(data).ifPresent(song -> this.playJukeboxSong(song, pos));
|
| 114 | break;
|
| 115 | case 1011:
|
| 116 | this.stopJukeboxSongAndNotifyNearby(pos);
|
| 117 | break;
|
| 118 | case 1015:
|
| 119 | this.level.playLocalSound(pos, SoundEvents.GHAST_WARN, SoundSource.HOSTILE, 10.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
|
| 120 | break;
|
| 121 | case 1016:
|
| 122 | this.level.playLocalSound(pos, SoundEvents.GHAST_SHOOT, SoundSource.HOSTILE, 10.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
|
| 123 | break;
|
| 124 | case 1017:
|
| 125 | this.level.playLocalSound(pos, SoundEvents.ENDER_DRAGON_SHOOT, SoundSource.HOSTILE, 10.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
|
| 126 | break;
|
| 127 | case 1018:
|
| 128 | this.level.playLocalSound(pos, SoundEvents.BLAZE_SHOOT, SoundSource.HOSTILE, 2.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
|
| 129 | break;
|
| 130 | case 1019:
|
| 131 | this.level
|
| 132 | .playLocalSound(pos, SoundEvents.ZOMBIE_ATTACK_WOODEN_DOOR, SoundSource.HOSTILE, 2.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
|
| 133 | break;
|
| 134 | case 1020:
|
| 135 | this.level
|
| 136 | .playLocalSound(pos, SoundEvents.ZOMBIE_ATTACK_IRON_DOOR, SoundSource.HOSTILE, 2.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
|
| 137 | break;
|
| 138 | case 1021:
|
| 139 | this.level
|
| 140 | .playLocalSound(pos, SoundEvents.ZOMBIE_BREAK_WOODEN_DOOR, SoundSource.HOSTILE, 2.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
|
| 141 | break;
|
| 142 | case 1022:
|
| 143 | this.level.playLocalSound(pos, SoundEvents.WITHER_BREAK_BLOCK, SoundSource.HOSTILE, 2.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
|
| 144 | break;
|
| 145 | case 1024:
|
| 146 | this.level.playLocalSound(pos, SoundEvents.WITHER_SHOOT, SoundSource.HOSTILE, 2.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
|
| 147 | break;
|
| 148 | case 1025:
|
| 149 | this.level.playLocalSound(pos, SoundEvents.BAT_TAKEOFF, SoundSource.NEUTRAL, 0.05F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
|
| 150 | break;
|
| 151 | case 1026:
|
| 152 | this.level.playLocalSound(pos, SoundEvents.ZOMBIE_INFECT, SoundSource.HOSTILE, 2.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
|
| 153 | break;
|
| 154 | case 1027:
|
| 155 | this.level
|
| 156 | .playLocalSound(pos, SoundEvents.ZOMBIE_VILLAGER_CONVERTED, SoundSource.HOSTILE, 2.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
|
| 157 | break;
|
| 158 | case 1029:
|
| 159 | this.level.playLocalSound(pos, SoundEvents.ANVIL_DESTROY, SoundSource.BLOCKS, 1.0F, random.nextFloat() * 0.1F + 0.9F, false);
|
| 160 | break;
|
| 161 | case 1030:
|
| 162 | this.level.playLocalSound(pos, SoundEvents.ANVIL_USE, SoundSource.BLOCKS, 1.0F, random.nextFloat() * 0.1F + 0.9F, false);
|
| 163 | break;
|
| 164 | case 1031:
|
| 165 | this.level.playLocalSound(pos, SoundEvents.ANVIL_LAND, SoundSource.BLOCKS, 0.3F, random.nextFloat() * 0.1F + 0.9F, false);
|
| 166 | break;
|
| 167 | case 1032:
|
| 168 | this.minecraft.getSoundManager().play(SimpleSoundInstance.forLocalAmbience(SoundEvents.PORTAL_TRAVEL, random.nextFloat() * 0.4F + 0.8F, 0.25F));
|
| 169 | break;
|
| 170 | case 1033:
|
| 171 | this.level.playLocalSound(pos, SoundEvents.CHORUS_FLOWER_GROW, SoundSource.BLOCKS, 1.0F, 1.0F, false);
|
| 172 | break;
|
| 173 | case 1034:
|
| 174 | this.level.playLocalSound(pos, SoundEvents.CHORUS_FLOWER_DEATH, SoundSource.BLOCKS, 1.0F, 1.0F, false);
|
| 175 | break;
|
| 176 | case 1035:
|
| 177 | this.level.playLocalSound(pos, SoundEvents.BREWING_STAND_BREW, SoundSource.BLOCKS, 1.0F, 1.0F, false);
|
| 178 | break;
|
| 179 | case 1039:
|
| 180 | this.level.playLocalSound(pos, SoundEvents.PHANTOM_BITE, SoundSource.HOSTILE, 0.3F, random.nextFloat() * 0.1F + 0.9F, false);
|
| 181 | break;
|
| 182 | case 1040:
|
| 183 | this.level
|
| 184 | .playLocalSound(pos, SoundEvents.ZOMBIE_CONVERTED_TO_DROWNED, SoundSource.HOSTILE, 2.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
|
| 185 | break;
|
| 186 | case 1041:
|
| 187 | this.level
|
| 188 | .playLocalSound(pos, SoundEvents.HUSK_CONVERTED_TO_ZOMBIE, SoundSource.HOSTILE, 2.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
|
| 189 | break;
|
| 190 | case 1042:
|
| 191 | this.level.playLocalSound(pos, SoundEvents.GRINDSTONE_USE, SoundSource.BLOCKS, 1.0F, random.nextFloat() * 0.1F + 0.9F, false);
|
| 192 | break;
|
| 193 | case 1043:
|
| 194 | this.level.playLocalSound(pos, SoundEvents.BOOK_PAGE_TURN, SoundSource.BLOCKS, 1.0F, random.nextFloat() * 0.1F + 0.9F, false);
|
| 195 | break;
|
| 196 | case 1044:
|
| 197 | this.level.playLocalSound(pos, SoundEvents.SMITHING_TABLE_USE, SoundSource.BLOCKS, 1.0F, random.nextFloat() * 0.1F + 0.9F, false);
|
| 198 | break;
|
| 199 | case 1045:
|
| 200 | this.level.playLocalSound(pos, SoundEvents.POINTED_DRIPSTONE_LAND, SoundSource.BLOCKS, 2.0F, random.nextFloat() * 0.1F + 0.9F, false);
|
| 201 | break;
|
| 202 | case 1046:
|
| 203 | this.level.playLocalSound(pos, SoundEvents.POINTED_DRIPSTONE_DRIP_LAVA_INTO_CAULDRON, SoundSource.BLOCKS, 2.0F, random.nextFloat() * 0.1F + 0.9F, false);
|
| 204 | break;
|
| 205 | case 1047:
|
| 206 | this.level.playLocalSound(pos, SoundEvents.POINTED_DRIPSTONE_DRIP_WATER_INTO_CAULDRON, SoundSource.BLOCKS, 2.0F, random.nextFloat() * 0.1F + 0.9F, false);
|
| 207 | break;
|
| 208 | case 1048:
|
| 209 | this.level
|
| 210 | .playLocalSound(pos, SoundEvents.SKELETON_CONVERTED_TO_STRAY, SoundSource.HOSTILE, 2.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, false);
|
| 211 | break;
|
| 212 | case 1049:
|
| 213 | this.level.playLocalSound(pos, SoundEvents.CRAFTER_CRAFT, SoundSource.BLOCKS, 1.0F, 1.0F, false);
|
| 214 | break;
|
| 215 | case 1050:
|
| 216 | this.level.playLocalSound(pos, SoundEvents.CRAFTER_FAIL, SoundSource.BLOCKS, 1.0F, 1.0F, false);
|
| 217 | break;
|
| 218 | case 1051:
|
| 219 | this.level.playLocalSound(pos, SoundEvents.WIND_CHARGE_THROW, SoundSource.BLOCKS, 0.5F, 0.4F / (this.level.getRandom().nextFloat() * 0.4F + 0.8F), false);
|
| 220 | break;
|
| 221 | case 1052:
|
| 222 | this.level.playLocalSound(pos, SoundEvents.SULFUR_SPIKE_LAND, SoundSource.BLOCKS, 2.0F, random.nextFloat() * 0.1F + 0.9F, false);
|
| 223 | break;
|
| 224 | case 1053:
|
| 225 | case 1054:
|
| 226 | this.level.playLocalSound(pos, SoundEvents.SPLASH_POTION_BREAK, SoundSource.NEUTRAL, 1.0F, random.nextFloat() * 0.1F + 0.9F, false);
|
| 227 | break;
|
| 228 | case 1500:
|
| 229 | ComposterBlock.handleFill(this.level, pos, data > 0);
|
| 230 | break;
|
| 231 | case 1501:
|
| 232 | this.level.playLocalSound(pos, SoundEvents.LAVA_EXTINGUISH, SoundSource.BLOCKS, 0.5F, 2.6F + (random.nextFloat() - random.nextFloat()) * 0.8F, false);
|
| 233 |
|
| 234 | for (int i = 0; i < 8; i++) {
|
| 235 | this.level.addParticle(ParticleTypes.LARGE_SMOKE, pos.getX() + random.nextDouble(), pos.getY() + 1.2, pos.getZ() + random.nextDouble(), 0.0, 0.0, 0.0);
|
| 236 | }
|
| 237 | break;
|
| 238 | case 1502:
|
| 239 | this.level
|
| 240 | .playLocalSound(pos, SoundEvents.REDSTONE_TORCH_BURNOUT, SoundSource.BLOCKS, 0.5F, 2.6F + (random.nextFloat() - random.nextFloat()) * 0.8F, false);
|
| 241 |
|
| 242 | for (int i = 0; i < 5; i++) {
|
| 243 | double x = pos.getX() + random.nextDouble() * 0.6 + 0.2;
|
| 244 | double y = pos.getY() + random.nextDouble() * 0.6 + 0.2;
|
| 245 | double z = pos.getZ() + random.nextDouble() * 0.6 + 0.2;
|
| 246 | this.level.addParticle(ParticleTypes.SMOKE, x, y, z, 0.0, 0.0, 0.0);
|
| 247 | }
|
| 248 | break;
|
| 249 | case 1503:
|
| 250 | this.level.playLocalSound(pos, SoundEvents.END_PORTAL_FRAME_FILL, SoundSource.BLOCKS, 1.0F, 1.0F, false);
|
| 251 |
|
| 252 | for (int i = 0; i < 16; i++) {
|
| 253 | double x = pos.getX() + (5.0 + random.nextDouble() * 6.0) / 16.0;
|
| 254 | double y = pos.getY() + 0.8125;
|
| 255 | double z = pos.getZ() + (5.0 + random.nextDouble() * 6.0) / 16.0;
|
| 256 | this.level.addParticle(ParticleTypes.SMOKE, x, y, z, 0.0, 0.0, 0.0);
|
| 257 | }
|
| 258 | break;
|
| 259 | case 1504:
|
| 260 | PointedDripstoneBlock.spawnDripParticle(this.level, pos, this.level.getBlockState(pos));
|
| 261 | break;
|
| 262 | case 1505:
|
| 263 | BoneMealItem.addGrowthParticles(this.level, pos, data);
|
| 264 | this.level.playLocalSound(pos, SoundEvents.BONE_MEAL_USE, SoundSource.BLOCKS, 1.0F, 1.0F, false);
|
| 265 | break;
|
| 266 | case 2000:
|
| 267 | this.shootParticles(data, pos, random, ParticleTypes.SMOKE);
|
| 268 | break;
|
| 269 | case 2001:
|
| 270 | BlockState blockState = Block.stateById(data);
|
| 271 | if (!blockState.isAir()) {
|
| 272 | SoundType soundType = blockState.getSoundType();
|
| 273 | this.level.playLocalSound(pos, soundType.getBreakSound(), SoundSource.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F, false);
|
| 274 | }
|
| 275 |
|
| 276 | this.level.addDestroyBlockEffect(pos, blockState);
|
| 277 | break;
|
| 278 | case 2002:
|
| 279 | this.potionSplashParticles(ParticleTypes.EFFECT, pos, data, random);
|
| 280 | break;
|
| 281 | case 2003:
|
| 282 | double x = pos.getX() + 0.5;
|
| 283 | double y = pos.getY();
|
| 284 | double z = pos.getZ() + 0.5;
|
| 285 | ItemParticleOption breakParticle = new ItemParticleOption(ParticleTypes.ITEM, Items.ENDER_EYE);
|
| 286 |
|
| 287 | for (int i = 0; i < 8; i++) {
|
| 288 | this.level.addParticle(breakParticle, x, y, z, random.nextGaussian() * 0.15, random.nextDouble() * 0.2, random.nextGaussian() * 0.15);
|
| 289 | }
|
| 290 |
|
| 291 | for (double angle = 0.0; angle < Math.PI * 2; angle += Math.PI / 20) {
|
| 292 | this.level
|
| 293 | .addParticle(ParticleTypes.PORTAL, x + Math.cos(angle) * 5.0, y - 0.4, z + Math.sin(angle) * 5.0, Math.cos(angle) * -5.0, 0.0, Math.sin(angle) * -5.0);
|
| 294 | this.level
|
| 295 | .addParticle(ParticleTypes.PORTAL, x + Math.cos(angle) * 5.0, y - 0.4, z + Math.sin(angle) * 5.0, Math.cos(angle) * -7.0, 0.0, Math.sin(angle) * -7.0);
|
| 296 | }
|
| 297 | break;
|
| 298 | case 2004:
|
| 299 | for (int i = 0; i < 20; i++) {
|
| 300 | double x = pos.getX() + 0.5 + (random.nextDouble() - 0.5) * 2.0;
|
| 301 | double y = pos.getY() + 0.5 + (random.nextDouble() - 0.5) * 2.0;
|
| 302 | double z = pos.getZ() + 0.5 + (random.nextDouble() - 0.5) * 2.0;
|
| 303 | this.level.addParticle(ParticleTypes.SMOKE, x, y, z, 0.0, 0.0, 0.0);
|
| 304 | this.level.addParticle(ParticleTypes.FLAME, x, y, z, 0.0, 0.0, 0.0);
|
| 305 | }
|
| 306 | break;
|
| 307 | case 2006:
|
| 308 | for (int i = 0; i < 200; i++) {
|
| 309 | float dist = random.nextFloat() * 4.0F;
|
| 310 | float angle = random.nextFloat() * (float) (Math.PI * 2);
|
| 311 | double velocityX = Mth.cos(angle) * dist;
|
| 312 | double velocityY = 0.01 + random.nextDouble() * 0.5;
|
| 313 | double velocityZ = Mth.sin(angle) * dist;
|
| 314 | this.level
|
| 315 | .addParticle(
|
| 316 | PowerParticleOption.create(ParticleTypes.DRAGON_BREATH, dist),
|
| 317 | pos.getX() + velocityX * 0.1,
|
| 318 | pos.getY() + 0.3,
|
| 319 | pos.getZ() + velocityZ * 0.1,
|
| 320 | velocityX,
|
| 321 | velocityY,
|
| 322 | velocityZ
|
| 323 | );
|
| 324 | }
|
| 325 |
|
| 326 | if (data == 1) {
|
| 327 | this.level.playLocalSound(pos, SoundEvents.DRAGON_FIREBALL_EXPLODE, SoundSource.HOSTILE, 1.0F, random.nextFloat() * 0.1F + 0.9F, false);
|
| 328 | }
|
| 329 | break;
|
| 330 | case 2007:
|
| 331 | this.potionSplashParticles(ParticleTypes.INSTANT_EFFECT, pos, data, random);
|
| 332 | break;
|
| 333 | case 2008:
|
| 334 | this.level.addParticle(ParticleTypes.EXPLOSION, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 0.0, 0.0, 0.0);
|
| 335 | break;
|
| 336 | case 2009:
|
| 337 | for (int i = 0; i < 8; i++) {
|
| 338 | this.level.addParticle(ParticleTypes.CLOUD, pos.getX() + random.nextDouble(), pos.getY() + 1.2, pos.getZ() + random.nextDouble(), 0.0, 0.0, 0.0);
|
| 339 | }
|
| 340 | break;
|
| 341 | case 2010:
|
| 342 | this.shootParticles(data, pos, random, ParticleTypes.WHITE_SMOKE);
|
| 343 | break;
|
| 344 | case 2011:
|
| 345 | ParticleUtils.spawnParticleInBlock(this.level, pos, data, ParticleTypes.HAPPY_VILLAGER);
|
| 346 | break;
|
| 347 | case 2012:
|
| 348 | ParticleUtils.spawnParticleInBlock(this.level, pos, data, ParticleTypes.HAPPY_VILLAGER);
|
| 349 | break;
|
| 350 | case 2013:
|
| 351 | ParticleUtils.spawnSmashAttackParticles(this.level, pos, data);
|
| 352 | break;
|
| 353 | case 2014:
|
| 354 | this.level.addDestroyBlockEffect(pos, Block.stateById(data));
|
| 355 | break;
|
| 356 | case 2015: {
|
| 357 | BlockPos toPos = BlockUtil.unpackDifferenceInPosition(pos, data, 16, 8, 16);
|
| 358 | this.singleBlockTeleportationParticles(pos, random, toPos);
|
| 359 | break;
|
| 360 | }
|
| 361 | case 2016: {
|
| 362 | BlockPos toPos = BlockUtil.unpackDifferenceInPosition(pos, data, 8, 8, 8);
|
| 363 | this.singleBlockTeleportationParticles(pos, random, toPos);
|
| 364 | break;
|
| 365 | }
|
| 366 | case 2017: {
|
| 367 | BlockPos toPos = BlockUtil.unpackDifferenceInPosition(pos, data, 127, 127, 127);
|
| 368 | this.singleBlockTeleportationParticles(pos, random, toPos);
|
| 369 | break;
|
| 370 | }
|
| 371 | case 2018: {
|
| 372 | float bbWidth = EntityTypes.ENDERMAN.getWidth();
|
| 373 | float bbHeight = EntityTypes.ENDERMAN.getHeight();
|
| 374 | BlockPos toPos = BlockUtil.unpackDifferenceInPosition(pos, data, 127, 127, 127);
|
| 375 |
|
| 376 | for (int particle = 0; particle < 128; particle++) {
|
| 377 | double randomDistance = random.nextDouble();
|
| 378 | float velocityX = (random.nextFloat() - 0.5F) * 0.2F;
|
| 379 | float velocityY = (random.nextFloat() - 0.5F) * 0.2F;
|
| 380 | float velocityZ = (random.nextFloat() - 0.5F) * 0.2F;
|
| 381 | double x = Mth.lerp(randomDistance, toPos.getX(), pos.getX()) + (random.nextDouble() - 0.5) * bbWidth * 2.0;
|
| 382 | double y = Mth.lerp(randomDistance, toPos.getY(), pos.getY()) + random.nextDouble() * bbHeight;
|
| 383 | double z = Mth.lerp(randomDistance, toPos.getZ(), pos.getZ()) + (random.nextDouble() - 0.5) * bbWidth * 2.0;
|
| 384 | this.level.addParticle(ParticleTypes.PORTAL, x, y, z, velocityX, velocityY, velocityZ);
|
| 385 | }
|
| 386 | break;
|
| 387 | }
|
| 388 | case 2019:
|
| 389 | case 2020:
|
| 390 | Direction[] directions = Direction.values();
|
| 391 | int ordinal = Mth.clamp(data, 0, directions.length - 1);
|
| 392 | this.level.addBreakingBlockEffects(pos, directions[ordinal], eventType == 2020);
|
| 393 | break;
|
| 394 | case 3000:
|
| 395 | this.level.addAlwaysVisibleParticle(ParticleTypes.EXPLOSION_EMITTER, true, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 0.0, 0.0, 0.0);
|
| 396 | this.level
|
| 397 | .playLocalSound(pos, SoundEvents.END_GATEWAY_SPAWN, SoundSource.BLOCKS, 10.0F, (1.0F + (random.nextFloat() - random.nextFloat()) * 0.2F) * 0.7F, false);
|
| 398 | break;
|
| 399 | case 3001:
|
| 400 | this.level.playLocalSound(pos, SoundEvents.ENDER_DRAGON_GROWL, SoundSource.HOSTILE, 64.0F, 0.8F + random.nextFloat() * 0.3F, false);
|
| 401 | break;
|
| 402 | case 3002:
|
| 403 | if (data >= 0 && data < Axis.VALUES.length) {
|
| 404 | ParticleUtils.spawnParticlesAlongAxis(Axis.VALUES[data], this.level, pos, 0.125, ParticleTypes.ELECTRIC_SPARK, UniformInt.of(10, 19));
|
| 405 | } else {
|
| 406 | ParticleUtils.spawnParticlesOnBlockFaces(this.level, pos, ParticleTypes.ELECTRIC_SPARK, UniformInt.of(3, 5));
|
| 407 | }
|
| 408 | break;
|
| 409 | case 3003:
|
| 410 | ParticleUtils.spawnParticlesOnBlockFaces(this.level, pos, ParticleTypes.WAX_ON, UniformInt.of(3, 5));
|
| 411 | break;
|
| 412 | case 3004:
|
| 413 | ParticleUtils.spawnParticlesOnBlockFaces(this.level, pos, ParticleTypes.WAX_OFF, UniformInt.of(3, 5));
|
| 414 | break;
|
| 415 | case 3005:
|
| 416 | ParticleUtils.spawnParticlesOnBlockFaces(this.level, pos, ParticleTypes.SCRAPE, UniformInt.of(3, 5));
|
| 417 | break;
|
| 418 | case 3006:
|
| 419 | int count = data >> 6;
|
| 420 | if (count > 0) {
|
| 421 | if (random.nextFloat() < 0.3F + count * 0.1F) {
|
| 422 | float volume = 0.15F + 0.02F * count * count * random.nextFloat();
|
| 423 | float pitch = 0.4F + 0.3F * count * random.nextFloat();
|
| 424 | this.level.playLocalSound(pos, SoundEvents.SCULK_BLOCK_CHARGE, SoundSource.BLOCKS, volume, pitch, false);
|
| 425 | }
|
| 426 |
|
| 427 | byte particleData = (byte)(data & 63);
|
| 428 | IntProvider repetition = UniformInt.of(0, count);
|
| 429 | float speedVar = 0.005F;
|
| 430 | Supplier<Vec3> speedSupplier = () -> new Vec3(
|
| 431 | Mth.nextDouble(random, -0.005F, 0.005F), Mth.nextDouble(random, -0.005F, 0.005F), Mth.nextDouble(random, -0.005F, 0.005F)
|
| 432 | );
|
| 433 | if (particleData == 0) {
|
| 434 | for (Direction direction : Direction.values()) {
|
| 435 | float fullBlockRotation = direction == Direction.DOWN ? (float) Math.PI : 0.0F;
|
| 436 | double fullBlockFactor = direction.getAxis() == Axis.Y ? 0.65 : 0.57;
|
| 437 | ParticleUtils.spawnParticlesOnBlockFace(
|
| 438 | this.level, pos, new SculkChargeParticleOptions(fullBlockRotation), repetition, direction, speedSupplier, fullBlockFactor
|
| 439 | );
|
| 440 | }
|
| 441 | } else {
|
| 442 | for (Direction direction : MultifaceBlock.unpack(particleData)) {
|
| 443 | float facesBlockRotation = direction == Direction.UP ? (float) Math.PI : 0.0F;
|
| 444 | double facesBlockFactor = 0.35;
|
| 445 | ParticleUtils.spawnParticlesOnBlockFace(this.level, pos, new SculkChargeParticleOptions(facesBlockRotation), repetition, direction, speedSupplier, 0.35);
|
| 446 | }
|
| 447 | }
|
| 448 | } else {
|
| 449 | this.level.playLocalSound(pos, SoundEvents.SCULK_BLOCK_CHARGE, SoundSource.BLOCKS, 1.0F, 1.0F, false);
|
| 450 | boolean isSolid = this.level.getBlockState(pos).isCollisionShapeFullBlock(this.level, pos);
|
| 451 | int particleCount = isSolid ? 40 : 20;
|
| 452 | float spread = isSolid ? 0.45F : 0.25F;
|
| 453 | float speed = 0.07F;
|
| 454 |
|
| 455 | for (int i = 0; i < particleCount; i++) {
|
| 456 | float velocityX = 2.0F * random.nextFloat() - 1.0F;
|
| 457 | float velocityY = 2.0F * random.nextFloat() - 1.0F;
|
| 458 | float velocityZ = 2.0F * random.nextFloat() - 1.0F;
|
| 459 | this.level
|
| 460 | .addParticle(
|
| 461 | ParticleTypes.SCULK_CHARGE_POP,
|
| 462 | pos.getX() + 0.5 + velocityX * spread,
|
| 463 | pos.getY() + 0.5 + velocityY * spread,
|
| 464 | pos.getZ() + 0.5 + velocityZ * spread,
|
| 465 | velocityX * 0.07F,
|
| 466 | velocityY * 0.07F,
|
| 467 | velocityZ * 0.07F
|
| 468 | );
|
| 469 | }
|
| 470 | }
|
| 471 | break;
|
| 472 | case 3007:
|
| 473 | for (int i = 0; i < 10; i++) {
|
| 474 | this.level.addParticle(new ShriekParticleOption(i * 5), pos.getX() + 0.5, pos.getY() + SculkShriekerBlock.TOP_Y, pos.getZ() + 0.5, 0.0, 0.0, 0.0);
|
| 475 | }
|
| 476 |
|
| 477 | BlockState state = this.level.getBlockState(pos);
|
| 478 | boolean isWaterlogged = state.hasProperty(BlockStateProperties.WATERLOGGED) && state.getValue(BlockStateProperties.WATERLOGGED);
|
| 479 | if (!isWaterlogged) {
|
| 480 | this.level
|
| 481 | .playLocalSound(
|
| 482 | pos.getX() + 0.5,
|
| 483 | pos.getY() + SculkShriekerBlock.TOP_Y,
|
| 484 | pos.getZ() + 0.5,
|
| 485 | SoundEvents.SCULK_SHRIEKER_SHRIEK,
|
| 486 | SoundSource.BLOCKS,
|
| 487 | 2.0F,
|
| 488 | 0.6F + random.nextFloat() * 0.4F,
|
| 489 | false
|
| 490 | );
|
| 491 | }
|
| 492 | break;
|
| 493 | case 3008:
|
| 494 | BlockState blockStateForBrushing = Block.stateById(data);
|
| 495 | if (blockStateForBrushing.getBlock() instanceof BrushableBlock brushableBlock) {
|
| 496 | this.level.playLocalSound(pos, brushableBlock.getBrushCompletedSound(), SoundSource.PLAYERS, 1.0F, 1.0F, false);
|
| 497 | }
|
| 498 |
|
| 499 | this.level.addDestroyBlockEffect(pos, blockStateForBrushing);
|
| 500 | break;
|
| 501 | case 3009:
|
| 502 | ParticleUtils.spawnParticlesOnBlockFaces(this.level, pos, ParticleTypes.EGG_CRACK, UniformInt.of(3, 6));
|
| 503 | break;
|
| 504 | case 3011:
|
| 505 | TrialSpawner.addSpawnParticles(this.level, pos, random, FlameParticle.decode(data).particleType);
|
| 506 | break;
|
| 507 | case 3012:
|
| 508 | this.level
|
| 509 | .playLocalSound(pos, SoundEvents.TRIAL_SPAWNER_SPAWN_MOB, SoundSource.BLOCKS, 1.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, true);
|
| 510 | TrialSpawner.addSpawnParticles(this.level, pos, random, FlameParticle.decode(data).particleType);
|
| 511 | break;
|
| 512 | case 3013:
|
| 513 | this.level
|
| 514 | .playLocalSound(pos, SoundEvents.TRIAL_SPAWNER_DETECT_PLAYER, SoundSource.BLOCKS, 1.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, true);
|
| 515 | TrialSpawner.addDetectPlayerParticles(this.level, pos, random, data, ParticleTypes.TRIAL_SPAWNER_DETECTED_PLAYER);
|
| 516 | break;
|
| 517 | case 3014:
|
| 518 | this.level
|
| 519 | .playLocalSound(pos, SoundEvents.TRIAL_SPAWNER_EJECT_ITEM, SoundSource.BLOCKS, 1.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, true);
|
| 520 | TrialSpawner.addEjectItemParticles(this.level, pos, random);
|
| 521 | break;
|
| 522 | case 3015:
|
| 523 | if (this.level.getBlockEntity(pos) instanceof VaultBlockEntity entity) {
|
| 524 | Client.emitActivationParticles(
|
| 525 | this.level, entity.getBlockPos(), entity.getBlockState(), entity.getSharedData(), data == 0 ? ParticleTypes.SMALL_FLAME : ParticleTypes.SOUL_FIRE_FLAME
|
| 526 | );
|
| 527 | this.level.playLocalSound(pos, SoundEvents.VAULT_ACTIVATE, SoundSource.BLOCKS, 1.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, true);
|
| 528 | }
|
| 529 | break;
|
| 530 | case 3016:
|
| 531 | Client.emitDeactivationParticles(this.level, pos, data == 0 ? ParticleTypes.SMALL_FLAME : ParticleTypes.SOUL_FIRE_FLAME);
|
| 532 | this.level.playLocalSound(pos, SoundEvents.VAULT_DEACTIVATE, SoundSource.BLOCKS, 1.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, true);
|
| 533 | break;
|
| 534 | case 3017:
|
| 535 | TrialSpawner.addEjectItemParticles(this.level, pos, random);
|
| 536 | break;
|
| 537 | case 3018:
|
| 538 | for (int i = 0; i < 10; i++) {
|
| 539 | double velocityX = random.nextGaussian() * 0.02;
|
| 540 | double velocityY = random.nextGaussian() * 0.02;
|
| 541 | double velocityZ = random.nextGaussian() * 0.02;
|
| 542 | this.level
|
| 543 | .addParticle(
|
| 544 | ParticleTypes.POOF,
|
| 545 | pos.getX() + random.nextDouble(),
|
| 546 | pos.getY() + random.nextDouble(),
|
| 547 | pos.getZ() + random.nextDouble(),
|
| 548 | velocityX,
|
| 549 | velocityY,
|
| 550 | velocityZ
|
| 551 | );
|
| 552 | }
|
| 553 |
|
| 554 | this.level.playLocalSound(pos, SoundEvents.COBWEB_PLACE, SoundSource.BLOCKS, 1.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, true);
|
| 555 | break;
|
| 556 | case 3019:
|
| 557 | this.level
|
| 558 | .playLocalSound(pos, SoundEvents.TRIAL_SPAWNER_DETECT_PLAYER, SoundSource.BLOCKS, 1.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, true);
|
| 559 | TrialSpawner.addDetectPlayerParticles(this.level, pos, random, data, ParticleTypes.TRIAL_SPAWNER_DETECTED_PLAYER_OMINOUS);
|
| 560 | break;
|
| 561 | case 3020:
|
| 562 | this.level
|
| 563 | .playLocalSound(
|
| 564 | pos,
|
| 565 | SoundEvents.TRIAL_SPAWNER_OMINOUS_ACTIVATE,
|
| 566 | SoundSource.BLOCKS,
|
| 567 | data == 0 ? 0.3F : 1.0F,
|
| 568 | (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F,
|
| 569 | true
|
| 570 | );
|
| 571 | TrialSpawner.addDetectPlayerParticles(this.level, pos, random, 0, ParticleTypes.TRIAL_SPAWNER_DETECTED_PLAYER_OMINOUS);
|
| 572 | TrialSpawner.addBecomeOminousParticles(this.level, pos, random);
|
| 573 | break;
|
| 574 | case 3021:
|
| 575 | this.level
|
| 576 | .playLocalSound(pos, SoundEvents.TRIAL_SPAWNER_SPAWN_ITEM, SoundSource.BLOCKS, 1.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F, true);
|
| 577 | TrialSpawner.addSpawnParticles(this.level, pos, random, FlameParticle.decode(data).particleType);
|
| 578 | }
|
| 579 | }
|
| 580 |
|
| 581 | private void singleBlockTeleportationParticles(final BlockPos pos, final RandomSource random, final BlockPos toPos) {
|
| 582 | for (int particle = 0; particle < 128; particle++) {
|
| 583 | double randomDistance = random.nextDouble();
|
| 584 | float velocityX = (random.nextFloat() - 0.5F) * 0.2F;
|
| 585 | float velocityY = (random.nextFloat() - 0.5F) * 0.2F;
|
| 586 | float velocityZ = (random.nextFloat() - 0.5F) * 0.2F;
|
| 587 | double x = Mth.lerp(randomDistance, toPos.getX(), pos.getX()) + (random.nextDouble() - 0.5) + 0.5;
|
| 588 | double y = Mth.lerp(randomDistance, toPos.getY(), pos.getY()) + random.nextDouble() - 0.5;
|
| 589 | double z = Mth.lerp(randomDistance, toPos.getZ(), pos.getZ()) + (random.nextDouble() - 0.5) + 0.5;
|
| 590 | this.level.addParticle(ParticleTypes.PORTAL, x, y, z, velocityX, velocityY, velocityZ);
|
| 591 | }
|
| 592 | }
|
| 593 |
|
| 594 | private void shootParticles(final int data, final BlockPos pos, final RandomSource random, final SimpleParticleType particle) {
|
| 595 | Direction direction = Direction.from3DDataValue(data);
|
| 596 | int normalX = direction.getStepX();
|
| 597 | int normalY = direction.getStepY();
|
| 598 | int normalZ = direction.getStepZ();
|
| 599 |
|
| 600 | for (int i = 0; i < 10; i++) {
|
| 601 | double pow = random.nextDouble() * 0.2 + 0.01;
|
| 602 | double x = pos.getX() + normalX * 0.6 + 0.5 + normalX * 0.01 + (random.nextDouble() - 0.5) * normalZ * 0.5;
|
| 603 | double y = pos.getY() + normalY * 0.6 + 0.5 + normalY * 0.01 + (random.nextDouble() - 0.5) * normalY * 0.5;
|
| 604 | double z = pos.getZ() + normalZ * 0.6 + 0.5 + normalZ * 0.01 + (random.nextDouble() - 0.5) * normalX * 0.5;
|
| 605 | double velocityX = normalX * pow + random.nextGaussian() * 0.01;
|
| 606 | double velocityY = normalY * pow + random.nextGaussian() * 0.01;
|
| 607 | double velocityZ = normalZ * pow + random.nextGaussian() * 0.01;
|
| 608 | this.level.addParticle(particle, x, y, z, velocityX, velocityY, velocityZ);
|
| 609 | }
|
| 610 | }
|
| 611 |
|
| 612 | private void playJukeboxSong(final Holder<JukeboxSong> songHolder, final BlockPos pos) {
|
| 613 | this.stopJukeboxSong(pos);
|
| 614 | JukeboxSong song = songHolder.value();
|
| 615 | SoundEvent sound = song.soundEvent().value();
|
| 616 | SoundInstance instance = SimpleSoundInstance.forJukeboxSong(sound, Vec3.atCenterOf(pos));
|
| 617 | this.playingJukeboxSongs.put(pos, instance);
|
| 618 | this.minecraft.getSoundManager().play(instance);
|
| 619 | this.minecraft.gui.hud.setNowPlaying(song.description());
|
| 620 | this.notifyNearbyEntities(this.level, pos, true);
|
| 621 | }
|
| 622 |
|
| 623 | private void stopJukeboxSong(final BlockPos pos) {
|
| 624 | SoundInstance removedInstance = this.playingJukeboxSongs.remove(pos);
|
| 625 | if (removedInstance != null) {
|
| 626 | this.minecraft.getSoundManager().stop(removedInstance);
|
| 627 | }
|
| 628 | }
|
| 629 |
|
| 630 | private void stopJukeboxSongAndNotifyNearby(final BlockPos pos) {
|
| 631 | this.stopJukeboxSong(pos);
|
| 632 | this.notifyNearbyEntities(this.level, pos, false);
|
| 633 | }
|
| 634 |
|
| 635 | private void notifyNearbyEntities(final Level level, final BlockPos pos, final boolean isPlaying) {
|
| 636 | for (LivingEntity entity : level.getEntitiesOfClass(LivingEntity.class, new AABB(pos).inflate(3.0))) {
|
| 637 | entity.setRecordPlayingNearby(pos, isPlaying);
|
| 638 | }
|
| 639 | }
|
| 640 |
|
| 641 | private void potionSplashParticles(final ParticleType<SpellParticleOption> particleType, final BlockPos pos, final int data, final RandomSource random) {
|
| 642 | Vec3 particlePos = Vec3.atBottomCenterOf(pos);
|
| 643 | ItemParticleOption breakParticle = new ItemParticleOption(ParticleTypes.ITEM, Items.SPLASH_POTION);
|
| 644 |
|
| 645 | for (int i = 0; i < 8; i++) {
|
| 646 | this.level
|
| 647 | .addParticle(
|
| 648 | breakParticle, particlePos.x, particlePos.y, particlePos.z, random.nextGaussian() * 0.15, random.nextDouble() * 0.2, random.nextGaussian() * 0.15
|
| 649 | );
|
| 650 | }
|
| 651 |
|
| 652 | float red = (data >> 16 & 0xFF) / 255.0F;
|
| 653 | float green = (data >> 8 & 0xFF) / 255.0F;
|
| 654 | float blue = (data >> 0 & 0xFF) / 255.0F;
|
| 655 |
|
| 656 | for (int i = 0; i < 100; i++) {
|
| 657 | double dist = random.nextDouble() * 4.0;
|
| 658 | double angle = random.nextDouble() * Math.PI * 2.0;
|
| 659 | double velocityX = Math.cos(angle) * dist;
|
| 660 | double velocityY = 0.01 + random.nextDouble() * 0.5;
|
| 661 | double velocityZ = Math.sin(angle) * dist;
|
| 662 | float randomBrightness = 0.75F + random.nextFloat() * 0.25F;
|
| 663 | SpellParticleOption particle = SpellParticleOption.create(
|
| 664 | particleType, red * randomBrightness, green * randomBrightness, blue * randomBrightness, (float)dist
|
| 665 | );
|
| 666 | this.level.addParticle(particle, particlePos.x + velocityX * 0.1, particlePos.y + 0.3, particlePos.z + velocityZ * 0.1, velocityX, velocityY, velocityZ);
|
| 667 | }
|
| 668 | }
|
| 669 | }
|
| 670 |
|