Skip to content

Commit

Permalink
Droopleaves get placed like scaffolding, so it is significantly less …
Browse files Browse the repository at this point in the history
…annoying to stack them
  • Loading branch information
f-raZ0R committed Oct 28, 2024
1 parent e7449e9 commit 1ddc7a5
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
BlockState blockState = world.getBlockState(blockPos);
return blockState.isOf(this) || blockState.isOf(SpectrumBlocks.DROOPLEAF_STEM) || blockState.isIn(BlockTags.BIG_DRIPLEAF_PLACEABLE);
}
public boolean canReplace(BlockState state, ItemPlacementContext context) {
return context.getStack().isOf(this.asItem());
}
public boolean emitsRedstonePower(BlockState state) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import de.dafuqs.spectrum.blocks.FluidLogging;
import de.dafuqs.spectrum.registries.SpectrumBlocks;
import de.dafuqs.spectrum.registries.SpectrumItems;
import net.minecraft.block.*;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.server.world.ServerWorld;
Expand Down Expand Up @@ -59,6 +61,9 @@ public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
BlockState blockState = world.getBlockState(blockPos);
return (blockState.isOf(this) || blockState.isIn(BlockTags.BIG_DRIPLEAF_PLACEABLE) || blockState.isOf(SpectrumBlocks.DROOPLEAF)) && (BlockLocating.findColumnEnd(world, pos, state.getBlock(), Direction.DOWN, SpectrumBlocks.DROOPLEAF).isPresent() || BlockLocating.findColumnEnd(world, pos, state.getBlock(), Direction.UP, SpectrumBlocks.DROOPLEAF).isPresent());
}
public boolean canReplace(BlockState state, ItemPlacementContext context) {
return context.getStack().isOf(SpectrumItems.DROOPLEAF);
}
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if ((direction == Direction.DOWN || direction == Direction.UP) && !state.canPlaceAt(world, pos)) {
world.scheduleBlockTick(pos, this, 1);
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/de/dafuqs/spectrum/items/DroopleafItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package de.dafuqs.spectrum.items;

import de.dafuqs.spectrum.blocks.redstone.DroopleafBlock;
import de.dafuqs.spectrum.registries.SpectrumBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

public class DroopleafItem extends BlockItem {
public DroopleafItem(Block block, Item.Settings settings) {
super(block, settings);
}
@Nullable
public ItemPlacementContext getPlacementContext(ItemPlacementContext context) {
BlockPos blockPos = context.getBlockPos();
World world = context.getWorld();
BlockState blockState = world.getBlockState(blockPos);
if (!blockState.isOf(SpectrumBlocks.DROOPLEAF) && !blockState.isOf(SpectrumBlocks.DROOPLEAF_STEM)) {
return this.getBlock().canPlaceAt(blockState,world,blockPos) ? context : null;
} else {
BlockPos.Mutable mutable = blockPos.mutableCopy().move(Direction.UP);
while(true) {
if (!world.isClient && !world.isInBuildLimit(mutable)) {
PlayerEntity playerEntity = context.getPlayer();
int j = world.getTopY();
if (playerEntity instanceof ServerPlayerEntity && mutable.getY() >= j) {
((ServerPlayerEntity)playerEntity).sendMessageToClient(Text.translatable("build.tooHigh", j - 1).formatted(Formatting.RED), true);
}
break;
}
blockState = world.getBlockState(mutable);
if (!blockState.isOf(SpectrumBlocks.DROOPLEAF) && !blockState.isOf(SpectrumBlocks.DROOPLEAF_STEM)) {
if (blockState.canReplace(context)) {
return ItemPlacementContext.offset(context, mutable, Direction.UP);
}
break;
}
mutable.move(Direction.UP);
}
return null;
}
}

protected boolean checkStatePlacement() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,7 @@ public static void register() {
registerBlock("deeper_down_portal", DEEPER_DOWN_PORTAL);
registerBlock("glistering_melon_stem", GLISTERING_MELON_STEM);
registerBlock("attached_glistering_melon_stem", ATTACHED_GLISTERING_MELON_STEM);
registerBlock("droopleaf", DROOPLEAF);
registerBlock("droopleaf_stem", DROOPLEAF_STEM);
registerBlock("stuck_storm_stone", STUCK_STORM_STONE);
registerBlock("wand_light", WAND_LIGHT_BLOCK);
Expand Down Expand Up @@ -1902,7 +1903,6 @@ private static void registerMagicalBlocks(FabricItemSettings settings) {
registerBlockWithItem("creative_particle_spawner", CREATIVE_PARTICLE_SPAWNER, new BlockItem(CREATIVE_PARTICLE_SPAWNER, IS.of(Rarity.EPIC)), DyeColor.PINK);

registerBlockWithItem("glistering_melon", GLISTERING_MELON, settings, DyeColor.LIME);
registerBlockWithItem("droopleaf", DROOPLEAF, settings, DyeColor.LIME);

registerBlockWithItem("lava_sponge", LAVA_SPONGE, settings, DyeColor.ORANGE);
registerBlockWithItem("wet_lava_sponge", WET_LAVA_SPONGE, new WetLavaSpongeItem(WET_LAVA_SPONGE, IS.of(1).recipeRemainder(LAVA_SPONGE.asItem())), DyeColor.ORANGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public static void register() {
entries.add(SpectrumBlocks.PARTICLE_SPAWNER);

entries.add(SpectrumBlocks.GLISTERING_MELON);
entries.add(SpectrumBlocks.DROOPLEAF);
entries.add(SpectrumItems.DROOPLEAF);
entries.add(SpectrumBlocks.LAVA_SPONGE);
entries.add(SpectrumBlocks.WET_LAVA_SPONGE);
entries.add(SpectrumBlocks.ETHEREAL_PLATFORM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ public Map<Enchantment, Integer> getDefaultEnchantments() {

public static final Item GLISTERING_MELON_SEEDS = new AliasedBlockItem(SpectrumBlocks.GLISTERING_MELON_STEM, IS.of());
public static final Item AMARANTH_GRAINS = new AliasedBlockItem(SpectrumBlocks.AMARANTH, IS.of());
public static final Item DROOPLEAF = new DroopleafItem(SpectrumBlocks.DROOPLEAF, IS.of());

public static final Item MELOCHITES_COOKBOOK_VOL_1 = new CookbookItem(IS.of().maxCount(1).rarity(Rarity.UNCOMMON), "cuisine/cookbooks/melochites_cookbook_vol_1");
public static final Item MELOCHITES_COOKBOOK_VOL_2 = new CookbookItem(IS.of().maxCount(1).rarity(Rarity.UNCOMMON), "cuisine/cookbooks/melochites_cookbook_vol_2");
Expand Down Expand Up @@ -680,6 +681,7 @@ public static void registerResources() {

register("glistering_melon_seeds", GLISTERING_MELON_SEEDS, DyeColor.LIME);
register("amaranth_grains", AMARANTH_GRAINS, DyeColor.LIME);
register("droopleaf", DROOPLEAF, DyeColor.LIME);

register("vegetal", VEGETAL, DyeColor.LIME);
register("neolith", NEOLITH, DyeColor.PINK);
Expand Down

0 comments on commit 1ddc7a5

Please sign in to comment.