Skip to content

Commit

Permalink
update salt biome
Browse files Browse the repository at this point in the history
update salt biome
  • Loading branch information
MEGATREX4 committed Jun 30, 2024
1 parent 1ac2db2 commit 485cb0a
Show file tree
Hide file tree
Showing 9 changed files with 334 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.megatrex4.ukrainian_dlight.block;

import com.megatrex4.ukrainian_dlight.UkrainianDelight;
import com.megatrex4.ukrainian_dlight.block.custom.BottleBlock;
import com.megatrex4.ukrainian_dlight.item.DrinkBlockItem;
import net.minecraft.block.Block;
import net.minecraft.entity.effect.StatusEffectInstance;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.megatrex4.ukrainian_dlight.block;

import com.megatrex4.ukrainian_dlight.UkrainianDelight;
import com.megatrex4.ukrainian_dlight.block.custom.JarBlock;
import com.megatrex4.ukrainian_dlight.item.FoodBlockItem;
import net.minecraft.block.Block;
import net.minecraft.item.BlockItem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.megatrex4.ukrainian_dlight.block;

import com.megatrex4.ukrainian_dlight.UkrainianDelight;
import com.megatrex4.ukrainian_dlight.block.custom.CustomSaltBlock;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
Expand All @@ -14,7 +15,7 @@
public class ModBlock {

public static final Block SALT_BLOCK = registerBlock("salt_block",
new Block(FabricBlockSettings.copyOf(Blocks.STONE).sounds(BlockSoundGroup.STONE)));
new CustomSaltBlock(Block.Settings.copy(Blocks.STONE).sounds(BlockSoundGroup.STONE)));

public static final Block SALT_BAG = registerBlock("salt_bag",
new Block(FabricBlockSettings.copyOf(Blocks.WHITE_WOOL).sounds(BlockSoundGroup.WOOL)));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package com.megatrex4.ukrainian_dlight.block.custom;

import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.ShapeContext;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
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 java.util.HashMap;
import java.util.Map;

public class BottleBlock extends Block {
public static final IntProperty BOTTLES = IntProperty.of("bottles", 1, 6);
public static final DirectionProperty FACING = DirectionProperty.of("facing", Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST);
private static final Map<Integer, VoxelShape> SHAPES = new HashMap<>();
private static final ThreadLocal<Boolean> isRemovingBottle = ThreadLocal.withInitial(() -> false);

static {
// Define shapes for different number of bottles here
SHAPES.put(1, Block.createCuboidShape(6, 0, 6, 10, 15, 10));
SHAPES.put(2, Block.createCuboidShape(1, 0, 3, 14, 15, 12));
SHAPES.put(3, Block.createCuboidShape(1, 0, 1, 14, 15, 14));
SHAPES.put(4, Block.createCuboidShape(1, 0, 1, 14, 15, 14));
SHAPES.put(5, Block.createCuboidShape(0, 0, 0, 14, 15, 14));
SHAPES.put(6, Block.createCuboidShape(0, 0, 0, 14, 15, 14));
}

public BottleBlock() {
super(FabricBlockSettings.copyOf(Blocks.GLASS).strength(0.2F).nonOpaque().sounds(BlockSoundGroup.GLASS));
this.setDefaultState(this.stateManager.getDefaultState().with(BOTTLES, 1).with(FACING, Direction.NORTH));
setRenderLayer();
}

private void setRenderLayer() {
BlockRenderLayerMap.INSTANCE.putBlock(this, RenderLayer.getCutout());
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(BOTTLES, FACING);
}

@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) {
return SHAPES.get(state.get(BOTTLES));
}

@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
Direction facing = ctx.getHorizontalPlayerFacing().getOpposite();
return this.getDefaultState().with(BOTTLES, 1).with(FACING, facing);
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
int currentBottles = state.get(BOTTLES);
ItemStack heldItem = player.getStackInHand(hand);

// Check if the player is using an empty hand to remove a bottle
if (heldItem.isEmpty() && currentBottles > 0) {
if (currentBottles == 1) {
isRemovingBottle.set(true);
world.setBlockState(pos, Blocks.AIR.getDefaultState()); // Break the block when the last bottle is removed
isRemovingBottle.set(false);
} else {
world.setBlockState(pos, state.with(BOTTLES, currentBottles - 1)); // Reduce bottles by 1
}
dropBottleItem(world, pos, 1); // Drop 1 bottle
world.playSound(null, pos, SoundEvents.BLOCK_GLASS_STEP, SoundCategory.BLOCKS, 2f, 0.7f); // Glass step sound
return ActionResult.SUCCESS;
}

// Check if the player is holding a bottle block item to add a bottle and it matches the current block
if (!heldItem.isEmpty() && currentBottles < 6 && heldItem.getItem() == this.asItem()) {
world.setBlockState(pos, state.with(BOTTLES, currentBottles + 1));
if (!player.isCreative()) {
heldItem.decrement(1);
}
world.playSound(null, pos, SoundEvents.BLOCK_GLASS_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F); // Glass place sound
return ActionResult.SUCCESS;
}

return ActionResult.PASS;
}

@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if (state.getBlock() != newState.getBlock()) {
super.onStateReplaced(state, world, pos, newState, moved);
if (!isRemovingBottle.get() && state.get(BOTTLES) > 0 && (newState.isAir() || newState.getBlock() != this)) {
dropBottleItem(world, pos, state.get(BOTTLES));
}
}
}

private void dropBottleItem(World world, BlockPos pos, int count) {
if (!world.isClient) {
ItemStack bottleItemStack = new ItemStack(this.asItem(), count);
Block.dropStack(world, pos, bottleItemStack);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.megatrex4.ukrainian_dlight.block.custom;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.mob.SlimeEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;

public class CustomSaltBlock extends Block {
private static final int SCHEDULED_TICK_DELAY = 20;

public CustomSaltBlock(Settings settings) {
super(settings);
}

@Override
public void onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity) {
if (entity instanceof SlimeEntity) {
entity.damage(world.getDamageSources().generic(), 2.0F);
}
super.onSteppedOn(world, pos, state, entity);
}

@Override
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
// Custom scheduled tick behavior, if needed
}

@Override
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) {
world.scheduleBlockTick(pos, this, SCHEDULED_TICK_DELAY);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package com.megatrex4.ukrainian_dlight.block.custom;

import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.ShapeContext;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.ZombieEntity;
import net.minecraft.entity.mob.ZombifiedPiglinEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.BlockStateParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
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 java.util.HashMap;
import java.util.Map;

import static com.megatrex4.ukrainian_dlight.UkrainianDelight.GLASS_DAMAGE;

public class JarBlock extends Block {
public static final IntProperty JARS = IntProperty.of("jars", 1, 4);
public static final DirectionProperty FACING = DirectionProperty.of("facing", Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST);
private static final Map<Integer, VoxelShape> SHAPES = new HashMap<>();
private static final ThreadLocal<Boolean> isRemovingJar = ThreadLocal.withInitial(() -> false);

static {
SHAPES.put(1, Block.createCuboidShape(6, 0, 6, 10, 8, 10));
SHAPES.put(2, Block.createCuboidShape(1, 0, 3, 14, 8, 12));
SHAPES.put(3, Block.createCuboidShape(1, 0, 1, 15, 8, 14));
SHAPES.put(4, Block.createCuboidShape(1, 0, 1, 15, 8, 15));
}

public JarBlock() {
super(FabricBlockSettings.copyOf(Blocks.GLASS).strength(0.2F).nonOpaque().sounds(BlockSoundGroup.GLASS));
this.setDefaultState(this.stateManager.getDefaultState().with(JARS, 1).with(FACING, Direction.NORTH)); // Start with 1 jar facing north
setRenderLayer();
}

private void setRenderLayer() {
BlockRenderLayerMap.INSTANCE.putBlock(this, RenderLayer.getCutout());
}


@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(JARS, FACING);
}

@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) {
return SHAPES.get(state.get(JARS));
}

@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
Direction facing = ctx.getHorizontalPlayerFacing().getOpposite();
return ctx.getPlayer().isSneaking() ? this.getDefaultState().with(JARS, 1).with(FACING, facing) : null; // Set the facing direction based on player placement
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
int currentJars = state.get(JARS);
ItemStack heldItem = player.getStackInHand(hand);

// Check if the player is using an empty hand to remove a jar
if (heldItem.isEmpty() && currentJars > 0) {
if (currentJars == 1) {
isRemovingJar.set(true); // Set flag to indicate the jar is being removed
world.setBlockState(pos, Blocks.AIR.getDefaultState()); // Break the block when the last jar is removed
isRemovingJar.set(false); // Reset flag after removing
} else {
world.setBlockState(pos, state.with(JARS, currentJars - 1)); // Reduce jars by 1
}
dropJarItem(world, pos, 1); // Drop 1 jar
world.playSound(null, pos, SoundEvents.BLOCK_GLASS_STEP, SoundCategory.BLOCKS, 2f, 0.7f); // Glass step sound
return ActionResult.SUCCESS;
}

// Check if the player is holding a jar block item to add a jar and it matches the current block
if (!heldItem.isEmpty() && currentJars < 4 && heldItem.getItem() == this.asItem()) {
world.setBlockState(pos, state.with(JARS, currentJars + 1));
if (!player.isCreative()) {
heldItem.decrement(1);
}
world.playSound(null, pos, SoundEvents.BLOCK_GLASS_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F); // Glass place sound
return ActionResult.SUCCESS;
}

return ActionResult.PASS;
}

@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if (state.getBlock() != newState.getBlock()) {
super.onStateReplaced(state, world, pos, newState, moved);
if (!isRemovingJar.get() && state.get(JARS) > 0 && (newState.isAir() || newState.getBlock() != this)) {
dropJarItem(world, pos, state.get(JARS));
}
}
}

private void dropJarItem(World world, BlockPos pos, int count) {
if (!world.isClient) {
ItemStack jarItemStack = new ItemStack(this.asItem(), count);
Block.dropStack(world, pos, jarItemStack);
}
}

@Override
public void onLandedUpon(World world, BlockState state, BlockPos pos, Entity entity, float fallDistance) {
super.onLandedUpon(world, state, pos, entity, fallDistance);

if (entity instanceof ZombieEntity || entity instanceof ZombifiedPiglinEntity) {
entity.velocityModified = true; // Set velocity modified flag to allow velocity changes
entity.setVelocity(entity.getVelocity().add(0, 0.5, 0)); // Add a vertical boost to simulate a jump
}

this.tryBreakJar(world, state, pos, entity, 0.3); // 30% chance to break the jar
}



private void tryBreakJar(World world, BlockState state, BlockPos pos, Entity entity, double breakChance) {
if (this.breaksJar(world, entity)) {
if (!world.isClient && world.random.nextDouble() < breakChance) {
this.breakJar(world, pos, state);
entity.damage(world.getDamageSources().create(GLASS_DAMAGE), 2.0F);
}
}
}


private void breakJar(World world, BlockPos pos, BlockState state) {
world.playSound(null, pos, SoundEvents.BLOCK_GLASS_BREAK, SoundCategory.BLOCKS, 0.7F, 0.9F + world.random.nextFloat() * 0.2F);
int currentJars = state.get(JARS);
if (currentJars <= 1) {
isRemovingJar.set(true); // Set flag to avoid dropping items
world.breakBlock(pos, false);
isRemovingJar.set(false); // Reset flag after breaking
} else {
world.setBlockState(pos, state.with(JARS, currentJars - 1), 2);
world.syncWorldEvent(2001, pos, Block.getRawIdFromState(state));
world.addParticle(new BlockStateParticleEffect(ParticleTypes.BLOCK, Blocks.GLASS.getDefaultState()), pos.getX() + 0.5, pos.getY() + 1.0, pos.getZ() + 0.5, 0.0, 0.0, 0.0); // Glass break particles
}
}

private boolean breaksJar(World world, Entity entity) {
return entity instanceof LivingEntity; // Damage all living entities, not just players
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static CaveBiome of(ParameterRange temperature, ParameterRange humidity,
private static final MultiNoiseUtil.ParameterRange DEFAULT_PARAMETER = MultiNoiseUtil.ParameterRange.of(-1.0f, 1.0f);
static final ParameterRange ALL_HEIGHT_RANGE = ParameterRange.of(0.2f, 0.9f);
static final ParameterRange ALL_HEIGHT_RANGE_DEEPER = ParameterRange.of(-0.2f, 0.9f);
static final ParameterRange HIGH_RANGE = ParameterRange.of(0.1f, 0.9f);
static final ParameterRange HIGH_RANGE = ParameterRange.of(0.55f, 0.9f);

public final static ImmutableList<CaveBiome> DEFAULT_CAVE_BIOMES = ImmutableList.of(
// Existing biomes
Expand All @@ -42,7 +42,7 @@ public static CaveBiome of(ParameterRange temperature, ParameterRange humidity,
DEFAULT_PARAMETER,
DEFAULT_PARAMETER,
ALL_HEIGHT_RANGE,
ParameterRange.of(-1.0f, 1.0f),
ParameterRange.of(0.5f, 1.0f),
0f,
BiomeKeys.SALT_CAVES
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"_comment1": "groups",
"_comment1": "groups",
"itemgroup.meals_ukrainian_delight": "Ukrainian Delight",
"itemgroup.ingredients_ukrainian_delight": "Ukrainian Delight Ingredients",
"itemgroup.jars_ukrainian_delight": "Ukrainian Delight Jars",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"block.ukrainian_delight.wine_bottle": "Пляшка для вина",

"_comment6": "blocks",
"block.ukrainian_delight.salt_block": "Солевий блок",
"block.ukrainian_delight.salt_block": "Блок солі",
"block.ukrainian_delight.salt_bag": "Мішок солі",

"_comment7": "advancements",
Expand Down

0 comments on commit 485cb0a

Please sign in to comment.