Skip to content

Commit

Permalink
Extract particle spawner logic from tater blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 committed Jul 2, 2024
1 parent 137edfe commit 75dbf06
Show file tree
Hide file tree
Showing 33 changed files with 598 additions and 461 deletions.
49 changes: 31 additions & 18 deletions src/main/java/xyz/nucleoid/extras/lobby/NEBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.particle.BlockStateParticleEffect;
import net.minecraft.particle.DustParticleEffect;
import net.minecraft.particle.ItemStackParticleEffect;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.Registries;
Expand All @@ -27,6 +29,7 @@
import xyz.nucleoid.extras.NucleoidExtras;
import xyz.nucleoid.extras.lobby.block.*;
import xyz.nucleoid.extras.lobby.block.tater.*;
import xyz.nucleoid.extras.lobby.particle.*;

public class NEBlocks {
public static final Block NUCLEOID_LOGO = createTaterBlock(ParticleTypes.GLOW_SQUID_INK, "bac7400dfcb9a387361a3ad7c296943eb841a9bda13ad89558e2d6efebf167bc");
Expand Down Expand Up @@ -76,7 +79,7 @@ public class NEBlocks {
public static final Block TRANSIENT_CRIMSON_DOOR = new TransientDoorBlock(Blocks.CRIMSON_DOOR);
public static final Block TRANSIENT_WARPED_DOOR = new TransientDoorBlock(Blocks.WARPED_DOOR);

public static final Block NUCLE_PAST_LOGO = createTaterBlock(new DustParticleEffect(Vec3d.unpackRgb(0x52C471).toVector3f(), 1), "65ed3e4d6ec42bd84d2b5e452087d454aac141a978540f6d200bd8aa863d4db8");
public static final Block NUCLE_PAST_LOGO = createColorTaterBlock(Vec3d.unpackRgb(0x52C471).toVector3f(), "65ed3e4d6ec42bd84d2b5e452087d454aac141a978540f6d200bd8aa863d4db8");

public static final Block TINY_POTATO = createTaterBlock(ParticleTypes.HEART, "573514a23245f15dbad5fb4e622163020864cce4c15d56de3adb90fa5a7137fd");
public static final Block BOTANICAL_TINY_POTATO = createBotanicTaterBlock(ParticleTypes.HEART,
Expand Down Expand Up @@ -204,7 +207,7 @@ public class NEBlocks {
public static final Block LAPIS_TATER = createTaterBlock(Blocks.LAPIS_BLOCK, "58d5cbda5c5046bf0b0f0d447c2fcc5e468707b6a4837c083af8e109aba9ce1c");
public static final Block NETHERITE_TATER = createTaterBlock(Blocks.NETHERITE_BLOCK, "664dce4fade8e5f352001eff6900d9d4b142935ebed303106539f7ad0193621f");
public static final Block QUARTZ_TATER = createTaterBlock(Blocks.QUARTZ_BLOCK, "7e7b4561d09d1a726fec3607706c9e3c77e8fc9b8c7e9c3637ca80ea0c86be21");
public static final Block REDSTONE_TATER = createRedstoneTaterBlock(new DustParticleEffect(DustParticleEffect.RED, 1), "c47dd2536f5a5eb2bdb1ea4389d3af8ca2fd9d5d2c97c660fc5bf4d970c974de");
public static final Block REDSTONE_TATER = createRedstoneTaterBlock(DustParticleEffect.RED, "c47dd2536f5a5eb2bdb1ea4389d3af8ca2fd9d5d2c97c660fc5bf4d970c974de");

public static final Block COPPER_TATER = createTaterBlock(ParticleTypes.SCRAPE, "18207c7cf4007222691750b0783d6959261ddf72980483f7c9fcf96c2cba85b1");
public static final Block EXPOSED_COPPER_TATER = createTaterBlock(ParticleTypes.SCRAPE, "bd5020090643edb5ec25d87cb1f408aad4f6018ec4bbe83d25a031ef1e705e4d");
Expand Down Expand Up @@ -440,51 +443,61 @@ private static AbstractBlock.Settings createTaterBlockSettings() {
}

private static Block createBotanicTaterBlock(ParticleEffect effect, String textureUp, String textureDown) {
return new BotanicalPotatoBlock(createTaterBlockSettings(), textureUp, textureDown, effect, 2);
return new BotanicalPotatoBlock(createTaterBlockSettings(), new SimpleTaterParticleSpawner(effect), textureUp, textureDown);
}

private static Block createTaterBlock(TaterParticleSpawner particleSpawner, String texture) {
return new CubicPotatoBlock(createTaterBlockSettings(), particleSpawner, texture);
}

private static Block createTaterBlock(ParticleEffect effect, String texture) {
return new CubicPotatoBlock(createTaterBlockSettings(), effect, texture);
return createTaterBlock(new SimpleTaterParticleSpawner(effect), texture);
}

private static Block createTaterBlock(Block particleBlock, String texture) {
return new CubicPotatoBlock(createTaterBlockSettings(), particleBlock, texture);
var effect = new BlockStateParticleEffect(ParticleTypes.BLOCK, particleBlock.getDefaultState());
return createTaterBlock(effect, texture);
}

private static Block createTaterBlock(Item particleItem, String texture) {
return new CubicPotatoBlock(createTaterBlockSettings(), particleItem, texture);
var effect = new ItemStackParticleEffect(ParticleTypes.ITEM, new ItemStack(particleItem));
return createTaterBlock(effect, texture);
}

private static Block createTaterBlock(ParticleEffect effect, String texture, int particleRate) {
return new CubicPotatoBlock(createTaterBlockSettings(), effect, texture, particleRate);
return createTaterBlock(new SimpleTaterParticleSpawner(effect, particleRate), texture);
}

private static Block createColorPatternTaterBlock(Vector3f[] pattern, String texture) {
return new ColorPatternTaterBlock(createTaterBlockSettings(), pattern, texture);
return new CubicPotatoBlock(createTaterBlockSettings(), new ColorPatternTaterParticleSpawner(pattern), texture);
}

private static Block createLuckyTaterBlock(String texture, String cooldownTexture) {
return new LuckyTaterBlock(createTaterBlockSettings(), texture, cooldownTexture);
}

private static Block createWardenTaterBlock(String texture) {
return new WardenTaterBlock(createTaterBlockSettings(), texture);
return createTaterBlock(new WardenTaterParticleSpawner(), texture);
}

private static Block createDiceTaterBlock() {
return new DiceTaterBlock(createTaterBlockSettings());
}

private static Block createTateroidBlock(RegistryEntry<SoundEvent> defaultSound, double particleColor, String texture) {
return new TateroidBlock(createTaterBlockSettings(), defaultSound, particleColor, texture);
private static Block createTateroidBlock(RegistryEntry<SoundEvent> defaultSound, double defaultParticleColor, String texture) {
return new TateroidBlock(createTaterBlockSettings(), defaultSound, defaultParticleColor, texture);
}

private static Block createColorTaterBlock(Vector3f color, String texture) {
return createTaterBlock(SimpleTaterParticleSpawner.ofDust(color), texture);
}

private static Block createColorTaterBlock(DyeColor color, String texture) {
return new ColorTaterBlock(createTaterBlockSettings(), color, texture);
return createTaterBlock(SimpleTaterParticleSpawner.ofDust(color), texture);
}

private static Block createRedstoneTaterBlock(ParticleEffect effect, String texture) {
return new RedstoneTaterBlock(createTaterBlockSettings(), effect, texture);
private static Block createRedstoneTaterBlock(Vector3f color, String texture) {
return new RedstoneTaterBlock(createTaterBlockSettings(), SimpleTaterParticleSpawner.ofDust(color), texture);
}

private static Block createDaylightDetectorTaterBlock(String texture, boolean inverted) {
Expand All @@ -500,19 +513,19 @@ private static Block createBellTaterBlock(String texture) {
}

private static Block createElderGuardianParticleTaterBlock(String texture) {
return new ElderGuardianParticleTater(createTaterBlockSettings(), texture);
return createTaterBlock(new SimpleTaterParticleSpawner(ParticleTypes.ELDER_GUARDIAN, 10000, 50), texture);
}

private static Block createCapsuleTaterBlock(Vector3f color, int weight, String texture) {
return new CapsuleTaterBlock(createTaterBlockSettings(), color, weight, texture);
return new CapsuleTaterBlock(createTaterBlockSettings(), RingTaterParticleSpawner.ofDust(color), weight, texture);
}

private static Block createMarkerTaterBlock(Block particleBlock, String texture) {
return new MarkerTaterBlock(createTaterBlockSettings(), particleBlock, texture);
return createTaterBlock(new SimpleMarkerTaterParticleSpawner(particleBlock), texture);
}

private static Block createLightTaterBlock(String texture) {
return new LightTaterBlock(createTaterBlockSettings(), texture);
return createTaterBlock(LightTaterParticleSpawner.INSTANCE, texture);
}

public static void register() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.jetbrains.annotations.Nullable;
import xyz.nucleoid.extras.lobby.NEBlocks;
import xyz.nucleoid.extras.lobby.particle.SimpleTaterParticleSpawner;
import xyz.nucleoid.extras.mixin.BlockWithEntityAccessor;

import net.minecraft.block.Block;
Expand Down Expand Up @@ -32,7 +33,7 @@ public class BellTaterBlock extends CubicPotatoBlock implements BlockEntityProvi
public static final BooleanProperty POWERED = Properties.POWERED;

public BellTaterBlock(Settings settings, String texture) {
super(settings, ParticleTypes.NOTE, texture);
super(settings, new SimpleTaterParticleSpawner(ParticleTypes.NOTE), texture);
this.setDefaultState(this.stateManager.getDefaultState().with(POWERED, false));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.Properties;
Expand All @@ -27,14 +26,15 @@
import net.minecraft.world.World;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import xyz.nucleoid.extras.lobby.particle.TaterParticleSpawner;
import xyz.nucleoid.extras.util.SkinEncoder;

public class BotanicalPotatoBlock extends TinyPotatoBlock implements BlockWithElementHolder {
private final ItemStack upStack;
private final ItemStack downStack;

public BotanicalPotatoBlock(Settings settings, String upperTexture, String lowerTexture, ParticleEffect particleEffect, int particleRate) {
super(settings.nonOpaque(), upperTexture, particleEffect, particleRate);
public BotanicalPotatoBlock(Settings settings, TaterParticleSpawner particleSpawner, String upperTexture, String lowerTexture) {
super(settings.nonOpaque(), particleSpawner, upperTexture);
this.upStack = PolymerUtils.createPlayerHead(this.getItemTexture());
this.downStack = PolymerUtils.createPlayerHead(SkinEncoder.encode(lowerTexture));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,17 @@
package xyz.nucleoid.extras.lobby.block.tater;

import net.minecraft.block.AbstractBlock;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import org.joml.Vector3f;

public class CapsuleTaterBlock extends ColorTaterBlock implements LuckyTaterDrop {
private static final int PARTICLE_COUNT = 8;

private static final double BLOCK_PARTICLE_RADIUS = 0.8;
private static final double PLAYER_PARTICLE_RADIUS = 0.5;
import xyz.nucleoid.extras.lobby.particle.TaterParticleSpawner;

public class CapsuleTaterBlock extends CubicPotatoBlock implements LuckyTaterDrop {
private final int weight;

public CapsuleTaterBlock(AbstractBlock.Settings settings, Vector3f color, int weight, String texture) {
super(settings, color, texture);
public CapsuleTaterBlock(AbstractBlock.Settings settings, TaterParticleSpawner particleSpawner, int weight, String texture) {
super(settings, particleSpawner, texture);

this.weight = weight;
}

@Override
public void spawnBlockParticles(ServerWorld world, BlockPos pos, ParticleEffect particleEffect) {
if (particleEffect != null && world.getRandom().nextInt(getBlockParticleChance()) == 0) {
this.spawnParticlesAround(world, particleEffect, pos.getX() + 0.5, BLOCK_PARTICLE_RADIUS, pos.getY() + 0.5, pos.getZ() + 0.5, BLOCK_PARTICLE_RADIUS, 0);
}
}

@Override
public void spawnPlayerParticles(ServerPlayerEntity player) {
ParticleEffect particleEffect = this.getPlayerParticleEffect(player);
if (particleEffect != null) {
double radius = player.getWidth() / 2 + PLAYER_PARTICLE_RADIUS;
double y = player.getBodyY(0.5);
double centerAngle = player.getYaw() * Math.PI / 180;

this.spawnParticlesAround(player.getServerWorld(), particleEffect, player.getX(), radius, y, player.getZ(), radius, centerAngle);
}
}

private void spawnParticlesAround(ServerWorld world, ParticleEffect particleEffect, double centerX, double radiusX, double y, double centerZ, double radiusZ, double centerAngle) {
for (int i = 0; i < PARTICLE_COUNT; i++) {
double angle = i / (double) PARTICLE_COUNT * Math.PI * 2 + centerAngle;

double x = centerX + Math.cos(angle) * radiusX;
double z = centerZ + Math.sin(angle) * radiusZ;

world.spawnParticles(particleEffect, x, y, z, 1, 0, 0, 0, 0);
}
}

@Override
public boolean isFickle() {
return true;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,29 @@
import eu.pb4.polymer.core.api.utils.PolymerUtils;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;

import java.util.Random;
import net.minecraft.util.math.random.Random;
import xyz.nucleoid.extras.lobby.particle.RandomParticleSpawner;

public final class CorruptaterBlock extends CubicPotatoBlock {
private final Random random = new Random();
private final Random random = Random.createLocal();
public CorruptaterBlock(AbstractBlock.Settings settings, int particleRate) {
super(settings, ParticleTypes.ENTITY_EFFECT, PolymerUtils.NO_TEXTURE_HEAD_VALUE, particleRate);
}

@Override
public ParticleEffect getParticleEffect(int time) {
return getTater().getParticleEffect(time);
super(settings, new RandomParticleSpawner(CorruptaterBlock::getTater), PolymerUtils.NO_TEXTURE_HEAD_VALUE);
}

@Override
public String getPolymerSkinValue(BlockState state, BlockPos pos, ServerPlayerEntity player) {
var tater = getTater();
var tater = getTater(player.getRandom());
return tater.getPolymerSkinValue(tater.getDefaultState(), pos, player);
}

private CubicPotatoBlock getTater() {
return CubicPotatoBlock.CUBIC_TATERS.get(random.nextInt(CubicPotatoBlock.CUBIC_TATERS.size()));
}

@Override
public String getTranslationKey() {
return super.getTranslationKey() + "." + random.nextInt(7);
}

private static CubicPotatoBlock getTater(Random random) {
return CubicPotatoBlock.CUBIC_TATERS.get(random.nextInt(CubicPotatoBlock.CUBIC_TATERS.size()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,26 @@
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.BlockStateParticleEffect;
import net.minecraft.particle.ItemStackParticleEffect;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RotationPropertyHelper;
import xyz.nucleoid.extras.util.SkinEncoder;
import xyz.nucleoid.extras.lobby.particle.TaterParticleSpawner;

import java.util.ArrayList;
import java.util.List;

public class CubicPotatoBlock extends TinyPotatoBlock implements PolymerHeadBlock {
protected static final List<CubicPotatoBlock> CUBIC_TATERS = new ArrayList<>();

public CubicPotatoBlock(Settings settings, ParticleEffect particleEffect, String texture, int particleRate) {
super(settings, texture, particleEffect, particleRate);
public CubicPotatoBlock(Settings settings, TaterParticleSpawner particleSpawner, String texture) {
super(settings, particleSpawner, texture);
CUBIC_TATERS.add(this);
}

public CubicPotatoBlock(Settings settings, ParticleEffect particleEffect, String texture) {
this(settings, particleEffect, texture, 2);
}

public CubicPotatoBlock(Settings settings, BlockState particleState, String texture) {
this(settings, new BlockStateParticleEffect(ParticleTypes.BLOCK, particleState), texture);
}

public CubicPotatoBlock(Settings settings, Block particleBlock, String texture) {
this(settings, particleBlock.getDefaultState(), texture);
}

public CubicPotatoBlock(Settings settings, ItemStack particleStack, String texture) {
this(settings, new ItemStackParticleEffect(ParticleTypes.ITEM, particleStack), texture);
}

public CubicPotatoBlock(Settings settings, Item particleItem, String texture) {
this(settings, new ItemStack(particleItem), texture);
}

@Override
public String getPolymerSkinValue(BlockState state, BlockPos pos, ServerPlayerEntity player) {
return this.getItemTexture();
Expand Down
Loading

0 comments on commit 75dbf06

Please sign in to comment.