Blossom berry
This commit is contained in:
parent
2a2641eea3
commit
ca769ebc66
30 changed files with 257 additions and 36 deletions
|
@ -8,12 +8,12 @@ import net.minecraft.util.math.Direction;
|
|||
import net.minecraft.world.StructureWorldAccess;
|
||||
import ru.betterend.blocks.BlockProperties.TripleShape;
|
||||
import ru.betterend.blocks.basis.FurBlock;
|
||||
import ru.betterend.blocks.basis.PlantWithAgeBlock;
|
||||
import ru.betterend.blocks.basis.EndPlantWithAgeBlock;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
public class BlueVineSeedBlock extends PlantWithAgeBlock {
|
||||
public class BlueVineSeedBlock extends EndPlantWithAgeBlock {
|
||||
@Override
|
||||
public void growAdult(StructureWorldAccess world, Random random, BlockPos pos) {
|
||||
int height = MHelper.randRange(2, 5, random);
|
||||
|
|
|
@ -8,12 +8,12 @@ import net.minecraft.util.math.BlockPos;
|
|||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.WorldView;
|
||||
import ru.betterend.blocks.BlockProperties.TripleShape;
|
||||
import ru.betterend.blocks.basis.PlantWithAgeBlock;
|
||||
import ru.betterend.blocks.basis.EndPlantWithAgeBlock;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
|
||||
public class BulbVineSeedBlock extends PlantWithAgeBlock {
|
||||
public class BulbVineSeedBlock extends EndPlantWithAgeBlock {
|
||||
@Override
|
||||
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
|
||||
BlockState up = world.getBlockState(pos.up());
|
||||
|
|
|
@ -13,12 +13,12 @@ import net.minecraft.util.math.BlockPos.Mutable;
|
|||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import ru.betterend.blocks.BlockProperties.TripleShape;
|
||||
import ru.betterend.blocks.basis.PlantWithAgeBlock;
|
||||
import ru.betterend.blocks.basis.EndPlantWithAgeBlock;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
public class GlowingPillarSeedBlock extends PlantWithAgeBlock {
|
||||
public class GlowingPillarSeedBlock extends EndPlantWithAgeBlock {
|
||||
public GlowingPillarSeedBlock() {
|
||||
super(FabricBlockSettings.of(Material.PLANT)
|
||||
.luminance((state) -> { return state.get(AGE) * 3 + 3; })
|
||||
|
|
|
@ -8,12 +8,12 @@ import net.minecraft.util.math.BlockPos.Mutable;
|
|||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import ru.betterend.blocks.BlockProperties.PentaShape;
|
||||
import ru.betterend.blocks.basis.PlantWithAgeBlock;
|
||||
import ru.betterend.blocks.basis.EndPlantWithAgeBlock;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
public class LanceleafSeedBlock extends PlantWithAgeBlock {
|
||||
public class LanceleafSeedBlock extends EndPlantWithAgeBlock {
|
||||
@Override
|
||||
public void growAdult(StructureWorldAccess world, Random random, BlockPos pos) {
|
||||
int height = MHelper.randRange(4, 6, random);
|
||||
|
|
|
@ -16,12 +16,12 @@ import net.minecraft.util.shape.VoxelShape;
|
|||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.World;
|
||||
import ru.betterend.blocks.basis.PlantWithAgeBlock;
|
||||
import ru.betterend.blocks.basis.EndPlantWithAgeBlock;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndItems;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
public class ShadowBerryBlock extends PlantWithAgeBlock {
|
||||
public class ShadowBerryBlock extends EndPlantWithAgeBlock {
|
||||
private static final VoxelShape SHAPE = Block.createCuboidShape(1, 0, 1, 15, 8, 15);
|
||||
|
||||
@Override
|
||||
|
|
114
src/main/java/ru/betterend/blocks/basis/EndCropBlock.java
Normal file
114
src/main/java/ru/betterend/blocks/basis/EndCropBlock.java
Normal file
|
@ -0,0 +1,114 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContext;
|
||||
import net.minecraft.loot.context.LootContextParameters;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.IntProperty;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
public class EndCropBlock extends EndPlantBlock {
|
||||
public static final IntProperty AGE = IntProperty.of("age", 0, 3);
|
||||
|
||||
private final Block[] terrain;
|
||||
private final Item drop;
|
||||
|
||||
public EndCropBlock(Item drop, Block... terrain) {
|
||||
super(FabricBlockSettings.of(Material.PLANT)
|
||||
.breakByTool(FabricToolTags.HOES)
|
||||
.sounds(BlockSoundGroup.GRASS)
|
||||
.breakByHand(true)
|
||||
.ticksRandomly()
|
||||
.noCollision());
|
||||
this.drop = drop;
|
||||
this.terrain = terrain;
|
||||
this.setDefaultState(getDefaultState().with(AGE, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
|
||||
stateManager.add(AGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isTerrain(BlockState state) {
|
||||
for (Block block: terrain) {
|
||||
if (state.isOf(block)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
|
||||
if (state.get(AGE) < 3) {
|
||||
return Collections.singletonList(new ItemStack(this));
|
||||
}
|
||||
ItemStack tool = builder.get(LootContextParameters.TOOL);
|
||||
if (tool != null && tool.isEffectiveOn(state)) {
|
||||
int enchantment = EnchantmentHelper.getLevel(Enchantments.FORTUNE, tool);
|
||||
if (enchantment > 0) {
|
||||
int countSeeds = MHelper.randRange(MathHelper.clamp(1 + enchantment, 1, 3), 3, MHelper.RANDOM);
|
||||
int countDrops = MHelper.randRange(MathHelper.clamp(1 + enchantment, 1, 2), 2, MHelper.RANDOM);
|
||||
return Lists.newArrayList(new ItemStack(this, countSeeds), new ItemStack(drop, countDrops));
|
||||
}
|
||||
}
|
||||
int countSeeds = MHelper.randRange(1, 3, MHelper.RANDOM);
|
||||
int countDrops = MHelper.randRange(1, 2, MHelper.RANDOM);
|
||||
return Lists.newArrayList(new ItemStack(this, countSeeds), new ItemStack(drop, countDrops));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractBlock.OffsetType getOffsetType() {
|
||||
return AbstractBlock.OffsetType.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void grow(ServerWorld world, Random random, BlockPos pos, BlockState state) {
|
||||
int age = state.get(AGE);
|
||||
if (age < 3) {
|
||||
BlocksHelper.setWithUpdate(world, pos, state.with(AGE, age + 1));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) {
|
||||
return state.get(AGE) < 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canGrow(World world, Random random, BlockPos pos, BlockState state) {
|
||||
return random.nextInt(8) == 0 && state.get(AGE) < 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
|
||||
super.scheduledTick(state, world, pos, random);
|
||||
if (canGrow(world, random, pos, state)) {
|
||||
grow(world, random, pos, state);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,11 +13,12 @@ import net.minecraft.state.StateManager;
|
|||
import net.minecraft.state.property.IntProperty;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class PlantWithAgeBlock extends EndPlantBlock {
|
||||
public abstract class EndPlantWithAgeBlock extends EndPlantBlock {
|
||||
public static final IntProperty AGE = IntProperty.of("age", 0, 3);
|
||||
|
||||
public PlantWithAgeBlock() {
|
||||
public EndPlantWithAgeBlock() {
|
||||
this(FabricBlockSettings.of(Material.PLANT)
|
||||
.breakByTool(FabricToolTags.SHEARS)
|
||||
.sounds(BlockSoundGroup.GRASS)
|
||||
|
@ -26,7 +27,7 @@ public abstract class PlantWithAgeBlock extends EndPlantBlock {
|
|||
.noCollision());
|
||||
}
|
||||
|
||||
public PlantWithAgeBlock(FabricBlockSettings settings) {
|
||||
public EndPlantWithAgeBlock(FabricBlockSettings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
|
@ -39,15 +40,18 @@ public abstract class PlantWithAgeBlock extends EndPlantBlock {
|
|||
|
||||
@Override
|
||||
public void grow(ServerWorld world, Random random, BlockPos pos, BlockState state) {
|
||||
if (random.nextInt(4) == 0) {
|
||||
int age = state.get(AGE);
|
||||
if (age < 3) {
|
||||
world.setBlockState(pos, state.with(AGE, age + 1));
|
||||
}
|
||||
else {
|
||||
growAdult(world, random, pos);
|
||||
}
|
||||
int age = state.get(AGE);
|
||||
if (age < 3) {
|
||||
world.setBlockState(pos, state.with(AGE, age + 1));
|
||||
}
|
||||
else {
|
||||
growAdult(world, random, pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canGrow(World world, Random random, BlockPos pos, BlockState state) {
|
||||
return random.nextInt(8) == 0;
|
||||
}
|
||||
|
||||
@Override
|
|
@ -86,6 +86,7 @@ import ru.betterend.blocks.PedestalVanilla;
|
|||
import ru.betterend.blocks.RunedFlavolite;
|
||||
import ru.betterend.blocks.TerminiteBlock;
|
||||
import ru.betterend.blocks.basis.FurBlock;
|
||||
import ru.betterend.blocks.basis.EndCropBlock;
|
||||
import ru.betterend.blocks.basis.EndLeavesBlock;
|
||||
import ru.betterend.blocks.basis.EndOreBlock;
|
||||
import ru.betterend.blocks.basis.SimpleLeavesBlock;
|
||||
|
@ -220,6 +221,9 @@ public class EndBlocks {
|
|||
|
||||
public static final Block SMALL_JELLYSHROOM = registerBlock("small_jellyshroom", new SmallJellyshroomBlock());
|
||||
|
||||
// Crops
|
||||
public static final Block BLOSSOM_BERRY = registerBlock("blossom_berry_seed", new EndCropBlock(EndItems.BLOSSOM_BERRY, PINK_MOSS));
|
||||
|
||||
// Water plants
|
||||
public static final Block BUBBLE_CORAL = registerBlock("bubble_coral", new BubbleCoralBlock());
|
||||
public static final Block MENGER_SPONGE = registerBlock("menger_sponge", new MengerSpongeBlock());
|
||||
|
|
|
@ -111,6 +111,10 @@ public class EndItems {
|
|||
public final static Item BUCKET_END_FISH = registerItem("bucket_end_fish", new FishBucketItem(EndEntities.END_FISH, Fluids.WATER, makeItemSettings().maxCount(1)));
|
||||
public final static Item SWEET_BERRY_JELLY = registerFood("sweet_berry_jelly", 3, 0.75F);
|
||||
public final static Item SHADOW_BERRY_JELLY = registerFood("shadow_berry_jelly", 4, 0.75F, new StatusEffectInstance(StatusEffects.NIGHT_VISION, 400));
|
||||
public final static Item BLOSSOM_BERRY = registerFood("blossom_berry", FoodComponents.APPLE);
|
||||
|
||||
// Drinks
|
||||
public final static Item UMBRELLA_CLUSTER_JUICE = registerDrink("umbrella_cluster_juice");
|
||||
|
||||
// Toolparts //
|
||||
public final static Item AETERNIUM_SHOVEL_HEAD = registerItem("aeternium_shovel_head");
|
||||
|
@ -121,9 +125,6 @@ public class EndItems {
|
|||
public final static Item AETERNIUM_SWORD_BLADE = registerItem("aeternium_sword_blade");
|
||||
public final static Item AETERNIUM_SWORD_HANDLE = registerItem("aeternium_sword_handle");
|
||||
|
||||
// Drinks
|
||||
public final static Item UMBRELLA_CLUSTER_JUICE = registerDrink("umbrella_cluster_juice");
|
||||
|
||||
protected static Item registerItem(String name) {
|
||||
return registerItem(BetterEnd.makeID(name), new PatternedItem(makeItemSettings()));
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.util.Random;
|
|||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import ru.betterend.blocks.basis.PlantWithAgeBlock;
|
||||
import ru.betterend.blocks.basis.EndPlantWithAgeBlock;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
@ -26,10 +26,10 @@ public class BlueVineFeature extends ScatterFeature {
|
|||
@Override
|
||||
public void generate(StructureWorldAccess world, Random random, BlockPos blockPos) {
|
||||
if (small) {
|
||||
BlocksHelper.setWithoutUpdate(world, blockPos, EndBlocks.BLUE_VINE_SEED.getDefaultState().with(PlantWithAgeBlock.AGE, random.nextInt(4)));
|
||||
BlocksHelper.setWithoutUpdate(world, blockPos, EndBlocks.BLUE_VINE_SEED.getDefaultState().with(EndPlantWithAgeBlock.AGE, random.nextInt(4)));
|
||||
}
|
||||
else {
|
||||
PlantWithAgeBlock seed = ((PlantWithAgeBlock) EndBlocks.BLUE_VINE_SEED);
|
||||
EndPlantWithAgeBlock seed = ((EndPlantWithAgeBlock) EndBlocks.BLUE_VINE_SEED);
|
||||
seed.growAdult(world, random, blockPos);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.util.Random;
|
|||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import ru.betterend.blocks.basis.PlantWithAgeBlock;
|
||||
import ru.betterend.blocks.basis.EndPlantWithAgeBlock;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
|
||||
public class GlowPillarFeature extends ScatterFeature {
|
||||
|
@ -19,7 +19,7 @@ public class GlowPillarFeature extends ScatterFeature {
|
|||
|
||||
@Override
|
||||
public void generate(StructureWorldAccess world, Random random, BlockPos blockPos) {
|
||||
PlantWithAgeBlock seed = ((PlantWithAgeBlock) EndBlocks.GLOWING_PILLAR_SEED);
|
||||
EndPlantWithAgeBlock seed = ((EndPlantWithAgeBlock) EndBlocks.GLOWING_PILLAR_SEED);
|
||||
seed.growAdult(world, random, blockPos);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.util.Random;
|
|||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import ru.betterend.blocks.basis.PlantWithAgeBlock;
|
||||
import ru.betterend.blocks.basis.EndPlantWithAgeBlock;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
|
||||
public class LanceleafFeature extends ScatterFeature {
|
||||
|
@ -19,7 +19,7 @@ public class LanceleafFeature extends ScatterFeature {
|
|||
|
||||
@Override
|
||||
public void generate(StructureWorldAccess world, Random random, BlockPos blockPos) {
|
||||
PlantWithAgeBlock seed = ((PlantWithAgeBlock) EndBlocks.LANCELEAF_SEED);
|
||||
EndPlantWithAgeBlock seed = ((EndPlantWithAgeBlock) EndBlocks.LANCELEAF_SEED);
|
||||
seed.growAdult(world, random, blockPos);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import net.minecraft.block.BlockState;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import ru.betterend.blocks.basis.DoublePlantBlock;
|
||||
import ru.betterend.blocks.basis.PlantWithAgeBlock;
|
||||
import ru.betterend.blocks.basis.EndPlantWithAgeBlock;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
|
||||
public class SinglePlantFeature extends ScatterFeature {
|
||||
|
@ -56,9 +56,9 @@ public class SinglePlantFeature extends ScatterFeature {
|
|||
BlocksHelper.setWithoutUpdate(world, blockPos, state);
|
||||
BlocksHelper.setWithoutUpdate(world, blockPos.up(), state.with(DoublePlantBlock.TOP, true));
|
||||
}
|
||||
else if (plant instanceof PlantWithAgeBlock) {
|
||||
else if (plant instanceof EndPlantWithAgeBlock) {
|
||||
int age = random.nextInt(4);
|
||||
BlockState state = plant.getDefaultState().with(PlantWithAgeBlock.AGE, age);
|
||||
BlockState state = plant.getDefaultState().with(EndPlantWithAgeBlock.AGE, age);
|
||||
BlocksHelper.setWithoutUpdate(world, blockPos, state);
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue