Skip to content

Commit

Permalink
center plants on pots + torch fix #74 #75
Browse files Browse the repository at this point in the history
  • Loading branch information
MBatt1 committed Aug 24, 2023
1 parent d2dd8ec commit 281ddc4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
23 changes: 12 additions & 11 deletions src/main/java/net/cr24/primeval/block/PrimevalBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.Arrays;
import java.util.Iterator;

import static net.cr24.primeval.block.plant.PrimevalPlantBlock.CENTER_CHECK;
import static net.cr24.primeval.item.PrimevalItems.PRIMEVAL_BLOCKS;
import static net.cr24.primeval.item.tool.PrimevalHoeItem.hoeables;

Expand Down Expand Up @@ -90,18 +91,18 @@ public class PrimevalBlocks {
public static final Block OAK_SAPLING = registerBlock("oak_sapling", new GrowingSaplingBlock(SETTINGS_PLANT().ticksRandomly(), OakTrunker.INSTANCE), Weight.HEAVY, Size.LARGE, PRIMEVAL_BLOCKS);
public static final Block BIRCH_SAPLING = registerBlock("birch_sapling", new GrowingSaplingBlock(SETTINGS_PLANT().ticksRandomly(), BirchTrunker.INSTANCE), Weight.HEAVY, Size.LARGE, PRIMEVAL_BLOCKS);
public static final Block SPRUCE_SAPLING = registerBlock("spruce_sapling", new GrowingSaplingBlock(SETTINGS_PLANT().ticksRandomly(), SpruceTrunker.INSTANCE), Weight.HEAVY, Size.LARGE, PRIMEVAL_BLOCKS);
public static final Block GRASS = registerBlock("grass", new GrowingGrassBlock(SETTINGS_PLANT().ticksRandomly().offsetType(AbstractBlock.OffsetType.XZ)), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
public static final Block BUSH = registerBlock("bush", new PrimevalPlantBlock(SETTINGS_PLANT().offsetType(AbstractBlock.OffsetType.XZ)), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
public static final Block SPIKED_PLANT = registerBlock("plant_0", new PrimevalPlantBlock(SETTINGS_PLANT().offsetType(AbstractBlock.OffsetType.XZ)), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
public static final Block LEAFY_PLANT = registerBlock("plant_1", new PrimevalPlantBlock(SETTINGS_PLANT().offsetType(AbstractBlock.OffsetType.XZ)), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
public static final Block SHRUB = registerBlock("shrub", new PrimevalPlantBlock(SETTINGS_PLANT().offsetType(AbstractBlock.OffsetType.XZ)), Weight.LIGHT, Size.MEDIUM, PRIMEVAL_BLOCKS);
public static final Block GRASS = registerBlock("grass", new GrowingGrassBlock(SETTINGS_PLANT().ticksRandomly().offsetType(CENTER_CHECK)), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
public static final Block BUSH = registerBlock("bush", new PrimevalPlantBlock(SETTINGS_PLANT().offsetType(CENTER_CHECK)), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
public static final Block SPIKED_PLANT = registerBlock("plant_0", new PrimevalPlantBlock(SETTINGS_PLANT().offsetType(CENTER_CHECK)), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
public static final Block LEAFY_PLANT = registerBlock("plant_1", new PrimevalPlantBlock(SETTINGS_PLANT().offsetType(CENTER_CHECK)), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
public static final Block SHRUB = registerBlock("shrub", new PrimevalPlantBlock(SETTINGS_PLANT().offsetType(CENTER_CHECK)), Weight.LIGHT, Size.MEDIUM, PRIMEVAL_BLOCKS);
public static final Block MOSS = registerBlock("moss", new SpreadingMossBlock(SETTINGS_PLANT().ticksRandomly()), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
// Flowers
public static final Block POPPY = registerBlock("poppy", new PrimevalPlantBlock(SETTINGS_PLANT()), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
public static final Block DANDELION = registerBlock("dandelion", new PrimevalPlantBlock(SETTINGS_PLANT()), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
public static final Block OXEYE_DAISY = registerBlock("oxeye_daisy", new PrimevalPlantBlock(SETTINGS_PLANT()), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
public static final Block CORNFLOWER = registerBlock("cornflower", new PrimevalPlantBlock(SETTINGS_PLANT()), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
public static final Block LILY_OF_THE_VALLEY = registerBlock("lily_of_the_valley", new PrimevalPlantBlock(SETTINGS_PLANT()), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
public static final Block POPPY = registerBlock("poppy", new PrimevalPlantBlock(SETTINGS_PLANT().offsetType(CENTER_CHECK)), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
public static final Block DANDELION = registerBlock("dandelion", new PrimevalPlantBlock(SETTINGS_PLANT().offsetType(CENTER_CHECK)), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
public static final Block OXEYE_DAISY = registerBlock("oxeye_daisy", new PrimevalPlantBlock(SETTINGS_PLANT().offsetType(CENTER_CHECK)), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
public static final Block CORNFLOWER = registerBlock("cornflower", new PrimevalPlantBlock(SETTINGS_PLANT().offsetType(CENTER_CHECK)), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
public static final Block LILY_OF_THE_VALLEY = registerBlock("lily_of_the_valley", new PrimevalPlantBlock(SETTINGS_PLANT().offsetType(CENTER_CHECK)), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
// Misc
public static final Block REEDS = registerBlock("reeds", new ReedsBlock(SETTINGS_PLANT().ticksRandomly()), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
public static final Block RIVER_GRASS = registerBlock("river_grass", new PrimevalWaterPlantBlock(SETTINGS_PLANT().offsetType(AbstractBlock.OffsetType.XZ)), Weight.VERY_LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
Expand Down Expand Up @@ -188,7 +189,7 @@ public class PrimevalBlocks {
// Intractable Blocks
public static final Block PIT_KILN = registerBlockWithoutItem("pit_kiln", new PitKilnBlock(FabricBlockSettings.of(Material.PLANT).strength(1.0F).sounds(BlockSoundGroup.GRASS).nonOpaque()));
public static final Block CRUDE_CRAFTING_BENCH = registerBlock("crude_crafting_bench", new PrimevalCraftingTableBlock(SETTINGS_REFINED_WOOD()), Weight.HEAVY, Size.LARGE, PRIMEVAL_BLOCKS);
public static final Block CRUDE_TORCH = registerBlock("crude_torch", new TimedTorchBlock(FabricBlockSettings.of(Material.WOOD, MapColor.OAK_TAN).sounds(BlockSoundGroup.WOOD).breakInstantly().noCollision().luminance(TimedTorchBlock::getLuminanceFromState).ticksRandomly()), Weight.LIGHT, Size.SMALL, PRIMEVAL_BLOCKS);
public static final Block CRUDE_TORCH = registerBlock("crude_torch", new TimedTorchBlock(FabricBlockSettings.of((new Material.Builder(MapColor.OAK_TAN)).allowsMovement().notSolid().build()).sounds(BlockSoundGroup.WOOD).breakInstantly().noCollision().luminance(TimedTorchBlock::getLuminanceFromState).ticksRandomly()), Weight.LIGHT, Size.SMALL, PRIMEVAL_BLOCKS); //todo
public static final Item LIT_CRUDE_TORCH = Registry.register(Registry.ITEM, PrimevalMain.getId("crude_torch_lit"), new WeightedBlockItem(CRUDE_TORCH, new FabricItemSettings().maxCount(Size.SMALL.getStackSize()), Weight.LIGHT, Size.SMALL));
public static final Block CAMPFIRE = registerBlock("campfire", new PrimevalCampfireBlock(SETTINGS_STONE().luminance(PrimevalCampfireBlock::getLuminanceFromState).nonOpaque()), Weight.HEAVY, Size.LARGE, null);
public static final Block QUERN = registerBlock("quern", new QuernBlock(SETTINGS_STONE().nonOpaque()), Weight.HEAVY, Size.LARGE, PRIMEVAL_BLOCKS);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
package net.cr24.primeval.block.plant;

import net.cr24.primeval.block.PrimevalBlockTags;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.PlantBlock;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.*;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;

import java.util.function.Function;

public class PrimevalPlantBlock extends PlantBlock {

protected static final VoxelShape SHAPE = Block.createCuboidShape(2.0, 0.0, 2.0, 14.0, 12.0, 14.0);
public static final BooleanProperty CENTERED;
public static Function<BlockState, OffsetType> CENTER_CHECK = (s) -> s.getBlock() instanceof PrimevalPlantBlock && s.get(PrimevalPlantBlock.CENTERED) ? AbstractBlock.OffsetType.NONE : AbstractBlock.OffsetType.XZ;

public PrimevalPlantBlock(Settings settings) {
super(settings);
this.setDefaultState(this.getDefaultState().with(CENTERED, false));
}

public BlockState getPlacementState(ItemPlacementContext ctx) {
World world = ctx.getWorld();
BlockPos pos = ctx.getBlockPos();

return this.getDefaultState().with(CENTERED, world.getBlockState(pos.down()).isIn(PrimevalBlockTags.SPECIAL_PLANTABLE));
}

@Override
Expand All @@ -28,4 +44,13 @@ public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos po
protected boolean canPlantOnTop(BlockState floor, BlockView world, BlockPos pos) {
return floor.isIn(PrimevalBlockTags.HEAVY_SOIL) || floor.isIn(PrimevalBlockTags.MEDIUM_SOIL) || floor.isIn(PrimevalBlockTags.SPECIAL_PLANTABLE);
}

protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
builder.add(CENTERED);
}

static {
CENTERED = BooleanProperty.of("centered");
}
}

0 comments on commit 281ddc4

Please sign in to comment.