-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update salt biome
- Loading branch information
Showing
9 changed files
with
334 additions
and
5 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
src/main/java/com/megatrex4/ukrainian_dlight/block/DrinkBottleBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/main/java/com/megatrex4/ukrainian_dlight/block/FoodJarBlocks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
src/main/java/com/megatrex4/ukrainian_dlight/block/custom/BottleBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/megatrex4/ukrainian_dlight/block/custom/CustomSaltBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
169 changes: 169 additions & 0 deletions
169
src/main/java/com/megatrex4/ukrainian_dlight/block/custom/JarBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters