Skip to content

Commit

Permalink
fix(block): giant lilypad isnt a buggy mess anymore!
Browse files Browse the repository at this point in the history
  • Loading branch information
CallMeEchoCodes committed Dec 12, 2024
1 parent 7d9a720 commit adebb12
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class FireflyJarParticle extends SpriteBillboardParticle {
protected FireflyJarParticle(ClientWorld clientWorld, double x, double y, double z) {
super(clientWorld, x, y, z);
this.maxAge = 400;
this.red = 0.101960786f;
this.green = 0.11764706f;
this.blue = 0.105882354f;
this.red = 26 / 255F;
this.green = 30 / 255F;
this.blue = 27 / 255F;

xMover = clientWorld.random.nextBoolean();
counterClockwise = clientWorld.random.nextBoolean();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package dev.spiritstudios.hollow.block;

import net.minecraft.block.*;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.HorizontalFacingBlock;
import net.minecraft.block.LilyPadBlock;
import net.minecraft.block.ShapeContext;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.EnumProperty;
Expand All @@ -11,6 +18,7 @@
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -28,15 +36,42 @@ public GiantLilyPadBlock(Settings settings) {
}

@Override
public BlockState onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
public @Nullable BlockState getPlacementState(ItemPlacementContext ctx) {
World world = ctx.getWorld();
BlockPos pos = ctx.getBlockPos();

if (posInvalid(world, pos) || posInvalid(world, pos.east()) || posInvalid(world, pos.south()) || posInvalid(world, pos.east().south())
) return null;

return this.getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing());
}

private boolean posInvalid(World world, BlockPos pos) {
return (!world.isWater(pos.down()) && !world.getBlockState(pos.down()).isIn(BlockTags.ICE)) || !world.isAir(pos);
}

@Override
public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) {
if (world.isClient() || state.get(PIECE) != Piece.NORTH_WEST) return;

world.setBlockState(pos.south(), state.with(PIECE, Piece.SOUTH_WEST));
world.setBlockState(pos.east(), state.with(PIECE, Piece.NORTH_EAST));
world.setBlockState(pos.south().east(), state.with(PIECE, Piece.SOUTH_EAST));
}

@Override
protected void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
super.onStateReplaced(state, world, pos, newState, moved);
if (newState.isOf(this)) return;

for (BlockPos blockPos : getBlocks(pos, state)) {
if (blockPos.equals(pos)) continue;
BlockState blockState = world.getBlockState(blockPos);
if (blockState.getBlock() == this) world.breakBlock(blockPos, blockPos.equals(pos));
if (blockState.isOf(this)) world.breakBlock(blockPos, false);
}

return super.onBreak(world, pos, state, player);
}


public List<BlockPos> getBlocks(BlockPos pos, BlockState state) {
List<BlockPos> blocks = new ArrayList<>();
if (state.getBlock() != this) return blocks;
Expand Down Expand Up @@ -68,7 +103,6 @@ public enum Piece implements StringIdentifiable {
SOUTH_WEST,
SOUTH_EAST;


@Override
public String asString() { return this.name().toLowerCase(Locale.ROOT); }
}
Expand Down
73 changes: 0 additions & 73 deletions src/main/java/dev/spiritstudios/hollow/item/GiantLilyPadItem.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import dev.spiritstudios.hollow.Hollow;
import dev.spiritstudios.hollow.item.CopperHornItem;
import dev.spiritstudios.hollow.item.GiantLilyPadItem;
import net.minecraft.item.Item;
import net.minecraft.item.PlaceableOnWaterItem;
import net.minecraft.item.SpawnEggItem;
Expand All @@ -19,7 +18,7 @@ public final class HollowItems {
);

public static final Item LOTUS_LILYPAD = new PlaceableOnWaterItem(HollowBlocks.LOTUS_LILYPAD, new Item.Settings());
public static final Item GIANT_LILYPAD = new GiantLilyPadItem(HollowBlocks.GIANT_LILYPAD, new Item.Settings());
public static final Item GIANT_LILYPAD = new PlaceableOnWaterItem(HollowBlocks.GIANT_LILYPAD, new Item.Settings());

public static final Item MUSIC_DISC_POSTMORTEM = new Item(
new Item.Settings()
Expand Down

0 comments on commit adebb12

Please sign in to comment.