Skip to content

Commit

Permalink
Expose tater particle spawner fields to all tater block codecs
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 committed Nov 14, 2024
1 parent 8418035 commit 1758057
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.jetbrains.annotations.Nullable;
import xyz.nucleoid.extras.lobby.NEBlocks;
import xyz.nucleoid.extras.lobby.particle.SimpleTaterParticleSpawner;
import xyz.nucleoid.extras.lobby.particle.TaterParticleSpawner;
import xyz.nucleoid.extras.lobby.particle.TaterParticleSpawnerTypes;
import xyz.nucleoid.extras.mixin.BlockWithEntityAccessor;

import com.mojang.serialization.Codec;
Expand Down Expand Up @@ -38,15 +40,20 @@ public class BellTaterBlock extends CubicPotatoBlock implements BlockEntityProvi
public static final MapCodec<BellTaterBlock> CODEC = RecordCodecBuilder.mapCodec(instance ->
instance.group(
createSettingsCodec(),
TaterParticleSpawnerTypes.CODEC.fieldOf("particle_spawner").forGetter(BellTaterBlock::getParticleSpawner),
Codec.STRING.fieldOf("texture").forGetter(BellTaterBlock::getItemTexture)
).apply(instance, BellTaterBlock::new)
);

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

public BellTaterBlock(Settings settings, String texture) {
this(settings, new SimpleTaterParticleSpawner(ParticleTypes.NOTE), texture);
}

@Override
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, WireOrientation wireOrientation, boolean notify) {
boolean bl = world.isReceivingRedstonePower(pos);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
package xyz.nucleoid.extras.lobby.block.tater;

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import eu.pb4.polymer.core.api.utils.PolymerUtils;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random;
import xyz.nucleoid.extras.lobby.particle.RandomTaterParticleSpawner;
import xyz.nucleoid.extras.lobby.particle.TaterParticleSpawner;
import xyz.nucleoid.extras.lobby.particle.TaterParticleSpawnerTypes;
import xyz.nucleoid.packettweaker.PacketContext;

public final class CorruptaterBlock extends CubicPotatoBlock {
public static final MapCodec<CorruptaterBlock> CODEC = createCodec(CorruptaterBlock::new);
public static final MapCodec<CorruptaterBlock> CODEC = RecordCodecBuilder.mapCodec(instance ->
instance.group(
createSettingsCodec(),
TaterParticleSpawnerTypes.CODEC.fieldOf("particle_spawner").forGetter(CorruptaterBlock::getParticleSpawner)
).apply(instance, CorruptaterBlock::new)
);

private final Random random = Random.createLocal();

public CorruptaterBlock(AbstractBlock.Settings settings, TaterParticleSpawner particleSpawner) {
super(settings, particleSpawner, PolymerUtils.NO_TEXTURE_HEAD_VALUE);
}

public CorruptaterBlock(AbstractBlock.Settings settings) {
super(settings, new RandomTaterParticleSpawner(CorruptaterBlock::getTater, RandomTaterParticleSpawner.DEFAULT_PLAYER_PARTICLE_RATE, RandomTaterParticleSpawner.DEFAULT_BLOCK_PARTICLE_CHANCE), PolymerUtils.NO_TEXTURE_HEAD_VALUE);
this(settings, new RandomTaterParticleSpawner(CorruptaterBlock::getTater, RandomTaterParticleSpawner.DEFAULT_PLAYER_PARTICLE_RATE, RandomTaterParticleSpawner.DEFAULT_BLOCK_PARTICLE_CHANCE));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.jetbrains.annotations.Nullable;
import xyz.nucleoid.extras.lobby.NEBlocks;
import xyz.nucleoid.extras.lobby.particle.SimpleTaterParticleSpawner;
import xyz.nucleoid.extras.lobby.particle.TaterParticleSpawner;
import xyz.nucleoid.extras.lobby.particle.TaterParticleSpawnerTypes;
import xyz.nucleoid.extras.mixin.BlockWithEntityAccessor;

import net.minecraft.block.Block;
Expand All @@ -31,6 +33,7 @@ public class DaylightDetectorTaterBlock extends CubicPotatoBlock implements Bloc
public static final MapCodec<DaylightDetectorTaterBlock> CODEC = RecordCodecBuilder.mapCodec(instance ->
instance.group(
createSettingsCodec(),
TaterParticleSpawnerTypes.CODEC.fieldOf("particle_spawner").forGetter(DaylightDetectorTaterBlock::getParticleSpawner),
Codec.STRING.fieldOf("texture").forGetter(DaylightDetectorTaterBlock::getItemTexture),
Codec.BOOL.fieldOf("inverted").forGetter(tater -> tater.inverted)
).apply(instance, DaylightDetectorTaterBlock::new)
Expand All @@ -40,12 +43,16 @@ public class DaylightDetectorTaterBlock extends CubicPotatoBlock implements Bloc

public final boolean inverted;

public DaylightDetectorTaterBlock(Settings settings, String texture, boolean inverted) {
super(settings, new SimpleTaterParticleSpawner(new BlockStateParticleEffect(ParticleTypes.BLOCK, Blocks.DAYLIGHT_DETECTOR.getDefaultState().with(Properties.INVERTED, inverted))), texture);
public DaylightDetectorTaterBlock(Settings settings, TaterParticleSpawner particleSpawner, String texture, boolean inverted) {
super(settings, particleSpawner, texture);
this.inverted = inverted;
this.setDefaultState(this.stateManager.getDefaultState().with(POWER, 0));
}

public DaylightDetectorTaterBlock(Settings settings, String texture, boolean inverted) {
this(settings, new SimpleTaterParticleSpawner(new BlockStateParticleEffect(ParticleTypes.BLOCK, Blocks.DAYLIGHT_DETECTOR.getDefaultState().with(Properties.INVERTED, inverted))), texture, inverted);
}

@Override
public boolean emitsRedstonePower(BlockState state) {
return true;
Expand Down Expand Up @@ -99,8 +106,8 @@ protected void appendProperties(StateManager.Builder<Block, BlockState> builder)
builder.add(POWER);
}

@Override
public MapCodec<? extends DaylightDetectorTaterBlock> getCodec() {
return CODEC;
}
@Override
public MapCodec<? extends DaylightDetectorTaterBlock> getCodec() {
return CODEC;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xyz.nucleoid.extras.lobby.block.tater;

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -17,11 +18,18 @@
import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;
import xyz.nucleoid.extras.lobby.particle.SimpleTaterParticleSpawner;
import xyz.nucleoid.extras.lobby.particle.TaterParticleSpawner;
import xyz.nucleoid.extras.lobby.particle.TaterParticleSpawnerTypes;
import xyz.nucleoid.extras.util.SkinEncoder;
import xyz.nucleoid.packettweaker.PacketContext;

public class DiceTaterBlock extends CubicPotatoBlock {
public static final MapCodec<DiceTaterBlock> CODEC = createCodec(DiceTaterBlock::new);
public static final MapCodec<DiceTaterBlock> CODEC = RecordCodecBuilder.mapCodec(instance ->
instance.group(
createSettingsCodec(),
TaterParticleSpawnerTypes.CODEC.fieldOf("particle_spawner").forGetter(DiceTaterBlock::getParticleSpawner)
).apply(instance, DiceTaterBlock::new)
);

private static final int ROLLING_FACE = 0;
private static final int MAX_FACE = 6;
Expand All @@ -37,12 +45,16 @@ public class DiceTaterBlock extends CubicPotatoBlock {
SkinEncoder.encode("9c40bf70f1648b7ee438a6a22904228ab5fbbd4926af30ae8ade4df01b8d7413"),
};

public DiceTaterBlock(Settings settings) {
super(settings, new SimpleTaterParticleSpawner(ParticleTypes.POOF), TEXTURES[6]);
public DiceTaterBlock(Settings settings, TaterParticleSpawner particleSpawner) {
super(settings, particleSpawner, TEXTURES[6]);

this.setDefaultState(this.stateManager.getDefaultState().with(FACE, 1));
}

public DiceTaterBlock(Settings settings) {
this(settings, new SimpleTaterParticleSpawner(ParticleTypes.POOF));
}

private boolean isRolling(BlockState state) {
return state.get(FACE) == ROLLING_FACE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import net.minecraft.world.World;
import xyz.nucleoid.extras.lobby.particle.LuckyTaterParticleSpawner;
import xyz.nucleoid.extras.lobby.particle.TaterParticleContext;
import xyz.nucleoid.extras.lobby.particle.TaterParticleSpawner;
import xyz.nucleoid.extras.lobby.particle.TaterParticleSpawnerTypes;
import xyz.nucleoid.extras.tag.NEBlockTags;
import xyz.nucleoid.extras.util.SkinEncoder;
import xyz.nucleoid.packettweaker.PacketContext;
Expand All @@ -32,6 +34,7 @@ public class LuckyTaterBlock extends CubicPotatoBlock {
public static final MapCodec<LuckyTaterBlock> CODEC = RecordCodecBuilder.mapCodec(instance ->
instance.group(
createSettingsCodec(),
TaterParticleSpawnerTypes.CODEC.fieldOf("particle_spawner").forGetter(LuckyTaterBlock::getParticleSpawner),
Codec.STRING.fieldOf("texture").forGetter(LuckyTaterBlock::getItemTexture),
Codec.STRING.fieldOf("cooldown_texture").forGetter(tater -> tater.cooldownTexture)
).apply(instance, LuckyTaterBlock::new)
Expand All @@ -44,6 +47,13 @@ public class LuckyTaterBlock extends CubicPotatoBlock {

private final String cooldownTexture;

public LuckyTaterBlock(Settings settings, TaterParticleSpawner particleSpawner, String texture, String cooldownTexture) {
super(settings, particleSpawner, texture);
this.cooldownTexture = SkinEncoder.encode(cooldownTexture);

this.setDefaultState(this.stateManager.getDefaultState().with(PHASE, LuckyTaterPhase.READY));
}

public LuckyTaterBlock(Settings settings, String texture, String cooldownTexture) {
super(settings, LuckyTaterParticleSpawner.DEFAULT, texture);
this.cooldownTexture = SkinEncoder.encode(cooldownTexture);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import xyz.nucleoid.extras.lobby.particle.SimpleTaterParticleSpawner;
import xyz.nucleoid.extras.lobby.particle.TaterParticleSpawner;
import xyz.nucleoid.extras.lobby.particle.TaterParticleSpawnerTypes;

public class TargetTaterBlock extends CubicPotatoBlock {
public static final MapCodec<TargetTaterBlock> CODEC = RecordCodecBuilder.mapCodec(instance ->
instance.group(
createSettingsCodec(),
TaterParticleSpawnerTypes.CODEC.fieldOf("particle_spawner").forGetter(TargetTaterBlock::getParticleSpawner),
Codec.STRING.fieldOf("texture").forGetter(TargetTaterBlock::getItemTexture)
).apply(instance, TargetTaterBlock::new)
);
Expand All @@ -41,11 +44,15 @@ public class TargetTaterBlock extends CubicPotatoBlock {
private static final int RECOVERABLE_POWER_DELAY = 20;
private static final int REGULAR_POWER_DELAY = 8;

public TargetTaterBlock(Settings settings, String texture) {
super(settings, new SimpleTaterParticleSpawner(new BlockStateParticleEffect(ParticleTypes.BLOCK, Blocks.TARGET.getDefaultState())), texture);
public TargetTaterBlock(Settings settings, TaterParticleSpawner particleSpawner, String texture) {
super(settings, particleSpawner, texture);
this.setDefaultState(this.stateManager.getDefaultState().with(POWER, 0));
}

public TargetTaterBlock(Settings settings, String texture) {
this(settings, new SimpleTaterParticleSpawner(new BlockStateParticleEffect(ParticleTypes.BLOCK, Blocks.TARGET.getDefaultState())), texture);
}

@Override
public void onProjectileHit(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile) {
int power = TargetTaterBlock.trigger(world, state, hit, projectile);
Expand Down Expand Up @@ -113,8 +120,8 @@ public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState
}
}

@Override
public MapCodec<? extends TargetTaterBlock> getCodec() {
return CODEC;
}
@Override
public MapCodec<? extends TargetTaterBlock> getCodec() {
return CODEC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import net.minecraft.world.World;
import net.minecraft.world.block.WireOrientation;
import xyz.nucleoid.extras.lobby.NEBlocks;
import xyz.nucleoid.extras.lobby.particle.TaterParticleSpawner;
import xyz.nucleoid.extras.lobby.particle.TaterParticleSpawnerTypes;
import xyz.nucleoid.extras.lobby.particle.TateroidParticleSpawner;
import xyz.nucleoid.extras.mixin.BlockWithEntityAccessor;

Expand All @@ -32,7 +34,7 @@ public class TateroidBlock extends CubicPotatoBlock implements BlockEntityProvid
instance.group(
createSettingsCodec(),
SoundEvent.ENTRY_CODEC.fieldOf("default_sound").forGetter(TateroidBlock::getDefaultSound),
TateroidParticleSpawner.DEFAULT_PARTICLE_COLOR_CODEC.forGetter(tater -> tater.defaultParticleColor),
TaterParticleSpawnerTypes.CODEC.fieldOf("particle_spawner").forGetter(TateroidBlock::getParticleSpawner),
Codec.STRING.fieldOf("texture").forGetter(TateroidBlock::getItemTexture)
).apply(instance, TateroidBlock::new)
);
Expand All @@ -41,17 +43,19 @@ public class TateroidBlock extends CubicPotatoBlock implements BlockEntityProvid
private static final int FULL_DURATION = 15 * SharedConstants.TICKS_PER_SECOND;

private final RegistryEntry<SoundEvent> defaultSound;
private final double defaultParticleColor;

public TateroidBlock(Settings settings, RegistryEntry<SoundEvent> defaultSound, double defaultParticleColor, String texture) {
super(settings, new TateroidParticleSpawner(ParticleTypes.NOTE, TateroidParticleSpawner.DEFAULT_PLAYER_PARTICLE_RATE, TateroidParticleSpawner.DEFAULT_BLOCK_PARTICLE_CHANCE, defaultParticleColor), texture);
public TateroidBlock(Settings settings, RegistryEntry<SoundEvent> defaultSound, TaterParticleSpawner particleSpawner, String texture) {
super(settings, particleSpawner, texture);

this.defaultSound = defaultSound;
this.defaultParticleColor = defaultParticleColor;

this.setDefaultState(this.stateManager.getDefaultState().with(POWERED, false));
}

public TateroidBlock(Settings settings, RegistryEntry<SoundEvent> defaultSound, double defaultParticleColor, String texture) {
this(settings, defaultSound, new TateroidParticleSpawner(ParticleTypes.NOTE, TateroidParticleSpawner.DEFAULT_PLAYER_PARTICLE_RATE, TateroidParticleSpawner.DEFAULT_BLOCK_PARTICLE_CHANCE, defaultParticleColor), texture);
}

private void activate(World world, BlockPos pos, int duration) {
var optional = world.getBlockEntity(pos, NEBlocks.TATEROID_ENTITY);
if (optional.isPresent()) {
Expand Down

0 comments on commit 1758057

Please sign in to comment.