Skip to content

Commit

Permalink
v1.8.5 - ISpreadableBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
DakotaPride committed Jun 14, 2024
1 parent bc21bbe commit bbbc1a6
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package net.dakotapride.garnished.block;

public interface IDesolateSpread extends ISpreadableBlock {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package net.dakotapride.garnished.block;

public interface ISenileSpread extends ISpreadableBlock {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.dakotapride.garnished.block;

import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;

public interface ISpreadableBlock {
/**
* @return whether spread can be used on this block
*/
boolean isValidTarget(BlockGetter pLevel, BlockPos pPos, BlockState pState, boolean pIsClient);

boolean isSuccess(Level pLevel, RandomSource pRandom, BlockPos pPos, BlockState pState);

void performSpread(ServerLevel pLevel, RandomSource pRandom, BlockPos pPos, BlockState pState);

SimpleParticleType getParticle();
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package net.dakotapride.garnished.block;

import java.util.function.ToIntFunction;

import net.dakotapride.garnished.registry.GarnishedBlocks;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.MultifaceBlock;
import net.minecraft.world.level.block.MultifaceSpreader;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;

public class NetherLichenBlock extends MultifaceBlock implements BonemealableBlock {
import java.util.function.ToIntFunction;

public class NetherLichenBlock extends MultifaceBlock implements ISenileSpread {
private final MultifaceSpreader spreader = new MultifaceSpreader(this);

public NetherLichenBlock(Properties pProperties) {
Expand Down Expand Up @@ -47,26 +47,32 @@ public BlockState updateShape(BlockState pState, Direction pDirection, BlockStat
}

public boolean canBeReplaced(BlockState pState, BlockPlaceContext pUseContext) {
return !pUseContext.getItemInHand().is(GarnishedBlocks.SORROWFUL_LICHEN.asItem()) || super.canBeReplaced(pState, pUseContext);
return !pUseContext.getItemInHand().is(GarnishedBlocks.SORROWFUL_LICHEN.get().asItem()) || super.canBeReplaced(pState, pUseContext);
}

/**
* @return whether bonemeal can be used on this block
*/
public boolean isValidBonemealTarget(LevelReader pLevel, BlockPos pPos, BlockState pState, boolean pIsClient) {
@Override
public boolean isValidTarget(BlockGetter pLevel, BlockPos pPos, BlockState pState, boolean isClient) {
return Direction.stream().anyMatch((p_153316_) -> {
return this.spreader.canSpreadInAnyDirection(pState, pLevel, pPos, p_153316_.getOpposite());
});
}

public boolean isBonemealSuccess(Level pLevel, RandomSource pRandom, BlockPos pPos, BlockState pState) {
public boolean isSuccess(Level pLevel, RandomSource pRandom, BlockPos pPos, BlockState pState) {
return true;
}

public void performBonemeal(ServerLevel pLevel, RandomSource pRandom, BlockPos pPos, BlockState pState) {
public void performSpread(ServerLevel pLevel, RandomSource pRandom, BlockPos pPos, BlockState pState) {
this.spreader.spreadFromRandomFaceTowardRandomDirection(pState, pLevel, pPos, pRandom);
}

@Override
public SimpleParticleType getParticle() {
return ParticleTypes.SOUL;
}

public boolean propagatesSkylightDown(BlockState pState, BlockGetter pLevel, BlockPos pPos) {
return pState.getFluidState().isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.dakotapride.garnished.item;

import org.jetbrains.annotations.NotNull;

import net.dakotapride.garnished.block.IDesolateSpread;
import net.dakotapride.garnished.registry.GarnishedFeatures;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -21,6 +20,8 @@
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;

import org.jetbrains.annotations.NotNull;

public class DesolateSpreadItem extends Item {
public static final int SPREAD_WIDTH = 3;
public static final int SPREAD_HEIGHT = 1;
Expand Down Expand Up @@ -52,16 +53,32 @@ public DesolateSpreadItem(Properties pProperties) {

public boolean applySpread(ItemStack stack, Level level, BlockPos pos) {
BlockState blockstate = level.getBlockState(pos);
if (blockstate.getBlock().defaultBlockState().is(Blocks.END_STONE)) {
if (level instanceof ServerLevel) {
if (this.isSuccessful()) {
this.performSpread((ServerLevel)level, level.random, pos);
if (level.getBlockState(pos.above()).is(Blocks.AIR)) {
if (blockstate.getBlock().defaultBlockState().is(Blocks.END_STONE)) {
if (level instanceof ServerLevel) {
if (this.isSuccessful()) {
this.performSpread((ServerLevel)level, level.random, pos);
}

stack.shrink(1);
}

stack.shrink(1);
return true;
}
}

if (blockstate.getBlock() instanceof IDesolateSpread spreadableBlock) {
if (spreadableBlock.isValidTarget(level, pos, blockstate, level.isClientSide)) {
if (level instanceof ServerLevel) {
if (spreadableBlock.isSuccess(level, level.random, pos, blockstate)) {
spreadableBlock.performSpread((ServerLevel)level, level.random, pos, blockstate);
}

return true;
stack.shrink(1);
}

return true;
}
}

return false;
Expand Down Expand Up @@ -106,19 +123,37 @@ public static void getParticles(LevelAccessor level, BlockPos pos, int data) {
d1 = blockstate.getShape(level, pos).max(Direction.Axis.Y);
}

level.addParticle(ParticleTypes.PORTAL, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, 0.0D, 0.0D, 0.0D);
RandomSource randomsource = level.getRandom();

for(int i = 0; i < data; ++i) {
double d2 = randomsource.nextGaussian() * 0.02D;
double d3 = randomsource.nextGaussian() * 0.02D;
double d4 = randomsource.nextGaussian() * 0.02D;
double d5 = 0.5D - d0;
double d6 = (double)pos.getX() + d5 + randomsource.nextDouble() * d0 * 2.0D;
double d7 = (double)pos.getY() + randomsource.nextDouble() * d1;
double d8 = (double)pos.getZ() + d5 + randomsource.nextDouble() * d0 * 2.0D;
if (!level.getBlockState(BlockPos.containing(d6, d7, d8).below()).isAir()) {
level.addParticle(ParticleTypes.PORTAL, d6, d7, d8, d2, d3, d4);
if (blockstate.getBlock() instanceof IDesolateSpread spreadableBlock) {
level.addParticle(spreadableBlock.getParticle(), (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, 0.0D, 0.0D, 0.0D);
RandomSource randomsource = level.getRandom();

for(int i = 0; i < data; ++i) {
double d2 = randomsource.nextGaussian() * 0.02D;
double d3 = randomsource.nextGaussian() * 0.02D;
double d4 = randomsource.nextGaussian() * 0.02D;
double d5 = 0.5D - d0;
double d6 = (double)pos.getX() + d5 + randomsource.nextDouble() * d0 * 2.0D;
double d7 = (double)pos.getY() + randomsource.nextDouble() * d1;
double d8 = (double)pos.getZ() + d5 + randomsource.nextDouble() * d0 * 2.0D;
if (!level.getBlockState(new BlockPos((int) d6, (int) d7, (int) d8).below()).isAir()) {
level.addParticle(spreadableBlock.getParticle(), d6, d7, d8, d2, d3, d4);
}
}
} else {
level.addParticle(ParticleTypes.PORTAL, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, 0.0D, 0.0D, 0.0D);
RandomSource randomsource = level.getRandom();

for(int i = 0; i < data; ++i) {
double d2 = randomsource.nextGaussian() * 0.02D;
double d3 = randomsource.nextGaussian() * 0.02D;
double d4 = randomsource.nextGaussian() * 0.02D;
double d5 = 0.5D - d0;
double d6 = (double)pos.getX() + d5 + randomsource.nextDouble() * d0 * 2.0D;
double d7 = (double)pos.getY() + randomsource.nextDouble() * d1;
double d8 = (double)pos.getZ() + d5 + randomsource.nextDouble() * d0 * 2.0D;
if (!level.getBlockState(new BlockPos((int) d6, (int) d7, (int) d8).below()).isAir()) {
level.addParticle(ParticleTypes.PORTAL, d6, d7, d8, d2, d3, d4);
}
}
}

Expand Down
78 changes: 57 additions & 21 deletions src/main/java/net/dakotapride/garnished/item/SenileSpreadItem.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package net.dakotapride.garnished.item;

import net.minecraft.core.registries.Registries;

import org.jetbrains.annotations.NotNull;

import net.dakotapride.garnished.block.ISenileSpread;
import net.dakotapride.garnished.registry.GarnishedFeatures;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.registries.Registries;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.RandomSource;
Expand All @@ -22,7 +24,7 @@
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;

public class SenileSpreadItem extends Item {
public class SenileSpreadItem extends Item {
public static final int SPREAD_WIDTH = 3;
public static final int SPREAD_HEIGHT = 1;
public static final int COUNT_MULTIPLIER = 3;
Expand Down Expand Up @@ -53,16 +55,32 @@ public SenileSpreadItem(Properties pProperties) {

public boolean applySpread(ItemStack stack, Level level, BlockPos pos) {
BlockState blockstate = level.getBlockState(pos);
if (blockstate.getBlock().defaultBlockState().is(BlockTags.SOUL_FIRE_BASE_BLOCKS) || blockstate.getBlock().defaultBlockState().is(Blocks.WARPED_NYLIUM) || blockstate.getBlock().defaultBlockState().is(Blocks.CRIMSON_NYLIUM)) {
if (level instanceof ServerLevel) {
if (this.isSuccessful()) {
this.performSpread((ServerLevel)level, level.random, pos);
if (level.getBlockState(pos.above()).is(Blocks.AIR)) {
if (blockstate.getBlock().defaultBlockState().is(BlockTags.SOUL_FIRE_BASE_BLOCKS) || blockstate.getBlock().defaultBlockState().is(Blocks.WARPED_NYLIUM) || blockstate.getBlock().defaultBlockState().is(Blocks.CRIMSON_NYLIUM)) {
if (level instanceof ServerLevel) {
if (this.isSuccessful()) {
this.performSpread((ServerLevel)level, level.random, pos);
}

stack.shrink(1);
}

stack.shrink(1);
return true;
}
}

if (blockstate.getBlock() instanceof ISenileSpread spreadableBlock) {
if (spreadableBlock.isValidTarget(level, pos, blockstate, level.isClientSide)) {
if (level instanceof ServerLevel) {
if (spreadableBlock.isSuccess(level, level.random, pos, blockstate)) {
spreadableBlock.performSpread((ServerLevel)level, level.random, pos, blockstate);
}

return true;
stack.shrink(1);
}

return true;
}
}

return false;
Expand Down Expand Up @@ -117,19 +135,37 @@ public static void getParticles(LevelAccessor level, BlockPos pos, int data) {
d1 = blockstate.getShape(level, pos).max(Direction.Axis.Y);
}

level.addParticle(ParticleTypes.SOUL, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, 0.0D, 0.0D, 0.0D);
RandomSource randomsource = level.getRandom();

for(int i = 0; i < data; ++i) {
double d2 = randomsource.nextGaussian() * 0.02D;
double d3 = randomsource.nextGaussian() * 0.02D;
double d4 = randomsource.nextGaussian() * 0.02D;
double d5 = 0.5D - d0;
double d6 = (double)pos.getX() + d5 + randomsource.nextDouble() * d0 * 2.0D;
double d7 = (double)pos.getY() + randomsource.nextDouble() * d1;
double d8 = (double)pos.getZ() + d5 + randomsource.nextDouble() * d0 * 2.0D;
if (!level.getBlockState(BlockPos.containing(d6, d7, d8).below()).isAir()) {
level.addParticle(ParticleTypes.SOUL, d6, d7, d8, d2, d3, d4);
if (blockstate.getBlock() instanceof ISenileSpread spreadableBlock) {
level.addParticle(spreadableBlock.getParticle(), (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, 0.0D, 0.0D, 0.0D);
RandomSource randomsource = level.getRandom();

for(int i = 0; i < data; ++i) {
double d2 = randomsource.nextGaussian() * 0.02D;
double d3 = randomsource.nextGaussian() * 0.02D;
double d4 = randomsource.nextGaussian() * 0.02D;
double d5 = 0.5D - d0;
double d6 = (double)pos.getX() + d5 + randomsource.nextDouble() * d0 * 2.0D;
double d7 = (double)pos.getY() + randomsource.nextDouble() * d1;
double d8 = (double)pos.getZ() + d5 + randomsource.nextDouble() * d0 * 2.0D;
if (!level.getBlockState(new BlockPos((int) d6, (int) d7, (int) d8).below()).isAir()) {
level.addParticle(spreadableBlock.getParticle(), d6, d7, d8, d2, d3, d4);
}
}
} else {
level.addParticle(ParticleTypes.SOUL, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, 0.0D, 0.0D, 0.0D);
RandomSource randomsource = level.getRandom();

for(int i = 0; i < data; ++i) {
double d2 = randomsource.nextGaussian() * 0.02D;
double d3 = randomsource.nextGaussian() * 0.02D;
double d4 = randomsource.nextGaussian() * 0.02D;
double d5 = 0.5D - d0;
double d6 = (double)pos.getX() + d5 + randomsource.nextDouble() * d0 * 2.0D;
double d7 = (double)pos.getY() + randomsource.nextDouble() * d1;
double d8 = (double)pos.getZ() + d5 + randomsource.nextDouble() * d0 * 2.0D;
if (!level.getBlockState(new BlockPos((int) d6, (int) d7, (int) d8).below()).isAir()) {
level.addParticle(ParticleTypes.SOUL, d6, d7, d8, d2, d3, d4);
}
}
}

Expand Down

0 comments on commit bbbc1a6

Please sign in to comment.