Skip to content

Commit

Permalink
basiscs of qeldry berry
Browse files Browse the repository at this point in the history
  • Loading branch information
gemsb committed Jan 13, 2025
1 parent fcca094 commit 876a0c5
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/net/ugi/sculk_depths/block/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@ public class ModBlocks {
public static final Block SCULK_PEDESTAL = registerBlock("sculk_pedestal",
new PedestalBlock(AbstractBlock.Settings.create().strength(-1f, 3600000.0f).pistonBehavior(PistonBehavior.BLOCK)), ModItemGroup.SCULK_DEPTHS_BLOCKS);

public static final Block QELDRY_BERRY_BUSH = registerBlock("qeldry_berry_bush",
new QeldryBerryBush(AbstractBlock.Settings.copy(Blocks.SWEET_BERRY_BUSH)), ModItemGroup.SCULK_DEPTHS_BLOCKS);

//auric //TODO check blocksettings


Expand Down
127 changes: 127 additions & 0 deletions src/main/java/net/ugi/sculk_depths/block/custom/QeldryBerryBush.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package net.ugi.sculk_depths.block.custom;

import com.mojang.serialization.MapCodec;
import net.minecraft.block.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.state.property.Property;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.ItemActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldView;
import net.minecraft.world.event.GameEvent;
import net.ugi.sculk_depths.block.ModBlocks;
import net.ugi.sculk_depths.item.ModItems;

public class QeldryBerryBush extends PlantBlock implements Fertilizable {
public static final MapCodec<QeldryBerryBush> CODEC = createCodec(QeldryBerryBush::new);
public static final int MAX_AGE = 3;
public static final IntProperty AGE;
private static final VoxelShape SMALL_SHAPE;
private static final VoxelShape LARGE_SHAPE;

public MapCodec<QeldryBerryBush> getCodec() {
return CODEC;
}

public QeldryBerryBush(AbstractBlock.Settings settings) {
super(settings);
this.setDefaultState((BlockState)((BlockState)this.stateManager.getDefaultState()).with(AGE, 0));
}

public ItemStack getPickStack(WorldView world, BlockPos pos, BlockState state) {
return new ItemStack(ModItems.QELDRY_BERRY);
}

protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if ((Integer)state.get(AGE) == 0) {
return SMALL_SHAPE;
} else {
return (Integer)state.get(AGE) < 3 ? LARGE_SHAPE : super.getOutlineShape(state, world, pos, context);
}
}

protected boolean hasRandomTicks(BlockState state) {
return (Integer)state.get(AGE) < 3;
}

protected void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
int i = (Integer)state.get(AGE);
if (i < 3 && random.nextInt(5) == 0 && world.getBaseLightLevel(pos.up(), 0) >= 9) {
BlockState blockState = (BlockState)state.with(AGE, i + 1);
world.setBlockState(pos, blockState, 2);
world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Emitter.of(blockState));
}

}

protected void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
}

protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
int i = (Integer)state.get(AGE);
boolean bl = i == 3;
return !bl && stack.isOf(Items.BONE_MEAL) ? ItemActionResult.SKIP_DEFAULT_BLOCK_INTERACTION : super.onUseWithItem(stack, state, world, pos, player, hand, hit);
}

protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
int i = (Integer)state.get(AGE);
boolean bl = i == 3;
if (i > 1) {
dropStack(world, pos, new ItemStack(ModItems.QELDRY_BERRY, 1));
world.playSound((PlayerEntity)null, pos, SoundEvents.BLOCK_SWEET_BERRY_BUSH_PICK_BERRIES, SoundCategory.BLOCKS, 1.0F, 0.8F + world.random.nextFloat() * 0.4F);
BlockState blockState = (BlockState)state.with(AGE, 1);
world.setBlockState(pos, blockState, 2);
world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Emitter.of(player, blockState));
return ActionResult.success(world.isClient);
} else {
return super.onUse(state, world, pos, player, hit);
}
}

protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(new Property[]{AGE});
}

public boolean isFertilizable(WorldView world, BlockPos pos, BlockState state) {
return (Integer)state.get(AGE) < 3;
}

public boolean canGrow(World world, Random random, BlockPos pos, BlockState state) {
return true;
}

public void grow(ServerWorld world, Random random, BlockPos pos, BlockState state) {
int i = Math.min(3, (Integer)state.get(AGE) + 1);
world.setBlockState(pos, (BlockState)state.with(AGE, i), 2);
}

static {
AGE = Properties.AGE_3;
SMALL_SHAPE = Block.createCuboidShape((double)3.0F, (double)0.0F, (double)3.0F, (double)13.0F, (double)8.0F, (double)13.0F);
LARGE_SHAPE = Block.createCuboidShape((double)1.0F, (double)0.0F, (double)1.0F, (double)15.0F, (double)16.0F, (double)15.0F);
}

@Override
protected boolean canPlantOnTop(BlockState floor, BlockView world, BlockPos pos) {
return floor.isIn(BlockTags.DIRT) || floor.isOf(Blocks.FARMLAND) || floor.isOf(ModBlocks.CRUMBLING_DIRT);
}
}
7 changes: 7 additions & 0 deletions src/main/java/net/ugi/sculk_depths/item/ModItems.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package net.ugi.sculk_depths.item;

import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.block.Blocks;
import net.minecraft.component.type.FoodComponents;
import net.minecraft.item.*;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
Expand Down Expand Up @@ -122,6 +124,10 @@ public class ModItems {
public static final Item CRUX_RESONATOR = registerItem("crux_resonator",
(new CruxResonator(new Item.Settings())));

public static final Item QELDRY_BERRY = registerItem("qeldry_berry",
(new AliasedBlockItem(ModBlocks.QELDRY_BERRY_BUSH, (new Item.Settings()).food(FoodComponents.SWEET_BERRIES))));


private static Item registerItem(String name, Item item) {
return Registry.register(Registries.ITEM, SculkDepths.identifier( name), item);
}
Expand All @@ -132,6 +138,7 @@ public static void addItemsToItemGroup() {
addToItemGroup(ModItemGroup.SCULK_DEPTHS_ITEMS, KRYSLUM_BUCKET);
addToItemGroup(ModItemGroup.SCULK_DEPTHS_ITEMS, ENERGY_ESSENCE);
addToItemGroup(ModItemGroup.SCULK_DEPTHS_ITEMS, CRUX_RESONATOR);
addToItemGroup(ModItemGroup.SCULK_DEPTHS_ITEMS, QELDRY_BERRY);

addToItemGroup(ModItemGroup.SCULK_DEPTHS_ITEMS, GLOMPER_GLUX);
addToItemGroup(ModItemGroup.SCULK_DEPTHS_ITEMS, GLOMPER_SPAWN_EGG);
Expand Down

0 comments on commit 876a0c5

Please sign in to comment.