place sulfor on lava
This commit is contained in:
parent
e56ec4c88c
commit
5396cefbb3
@ -12,15 +12,13 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.CropBlock;
|
||||
import net.minecraft.block.IceBlock;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ai.pathing.NavigationType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.ItemConvertible;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContextParameterSet.Builder;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ItemScatterer;
|
||||
@ -31,6 +29,7 @@ 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;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -41,12 +40,18 @@ public class BlockSulforpad extends CropBlock {
|
||||
|
||||
public BlockSulforpad(AbstractBlock.Settings settings) {
|
||||
super(settings.nonOpaque().blockVision(Blocks::never).solidBlock(Blocks::never));
|
||||
setDefaultState(getDefaultState().with(this.getAgeProperty(), 0));
|
||||
}
|
||||
|
||||
protected BlockSulforpad() {
|
||||
super(FabricBlockSettings.create());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
|
||||
Integer age = this.getAge(state);
|
||||
@ -83,11 +88,22 @@ public class BlockSulforpad extends CropBlock {
|
||||
BlockHitResult hitResult) {
|
||||
if (!world.isClient && isMature(state)) {
|
||||
spawnHarvested(world, pos, state);
|
||||
world.setBlockState(pos, state.with(AGE, 0));
|
||||
Random random = world.getRandom();
|
||||
world.setBlockState(pos, state.with(AGE, random.nextInt(6)));
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
|
||||
// do nothing here
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickStack(WorldView world, BlockPos pos, BlockState state) {
|
||||
return new ItemStack(QuickieItems.SULPHOR, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapCodec<? extends BlockSulforpad> getCodec() {
|
||||
return BlockSulforpad.createCodec(BlockSulforpad::new);
|
||||
|
@ -4,10 +4,18 @@ import de.jottyfan.minecraft.quickiefabric.blocks.QuickieBlocks;
|
||||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.BoatItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.RaycastContext;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
@ -21,17 +29,37 @@ public class ItemSulphor extends Item {
|
||||
super(new FabricItemSettings());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult useOnBlock(ItemUsageContext context) {
|
||||
World world = context.getWorld();
|
||||
BlockPos pos = context.getBlockPos();
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
if (Blocks.LAVA_CAULDRON.equals(block)) {
|
||||
if (world.getBlockState(pos.up()).isAir()) {
|
||||
world.setBlockState(pos.up(), QuickieBlocks.SULFORPAD.getDefaultState());
|
||||
context.getStack().decrement(1);
|
||||
}
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
@Override
|
||||
public ActionResult useOnBlock(ItemUsageContext context) {
|
||||
World world = context.getWorld();
|
||||
BlockPos pos = context.getBlockPos();
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
if (Blocks.LAVA_CAULDRON.equals(block)) {
|
||||
if (world.getBlockState(pos.up()).isAir()) {
|
||||
world.setBlockState(pos.up(), QuickieBlocks.SULFORPAD.getDefaultState());
|
||||
context.getStack().decrement(1);
|
||||
}
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
|
||||
ItemStack itemStack = user.getStackInHand(hand);
|
||||
BlockHitResult hitResult = BoatItem.raycast(world, user, RaycastContext.FluidHandling.SOURCE_ONLY);
|
||||
if (((HitResult) hitResult).getType() == HitResult.Type.MISS) {
|
||||
return TypedActionResult.pass(itemStack);
|
||||
}
|
||||
if (((HitResult) hitResult).getType() == HitResult.Type.BLOCK) {
|
||||
if (!world.isClient) {
|
||||
BlockPos pos = hitResult.getBlockPos();
|
||||
if (world.getBlockState(pos).getBlock().equals(Blocks.LAVA) && world.getBlockState(pos.up()).isAir()) {
|
||||
world.setBlockState(pos.up(), QuickieBlocks.SULFORPAD.getDefaultState());
|
||||
itemStack.decrement(1);
|
||||
}
|
||||
}
|
||||
return TypedActionResult.success(itemStack, world.isClient());
|
||||
}
|
||||
return TypedActionResult.pass(itemStack);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,30 @@
|
||||
{
|
||||
"type": "minecraft:ore",
|
||||
"type": "minecraft:random_patch",
|
||||
"config": {
|
||||
"discard_chance_on_air_exposure": 0.0,
|
||||
"size": 3,
|
||||
"targets": [
|
||||
{
|
||||
"state": {
|
||||
"Name": "quickiefabric:sulforpad"
|
||||
},
|
||||
"target": {
|
||||
"predicate_type": "minecraft:block_match",
|
||||
"block": "minecraft:lava"
|
||||
"feature": {
|
||||
"feature": {
|
||||
"type": "minecraft:simple_block",
|
||||
"config": {
|
||||
"to_place": {
|
||||
"type": "minecraft:simple_state_provider",
|
||||
"state": {
|
||||
"Name": "quickiefabric:sulforpad"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"placement": [
|
||||
{
|
||||
"type": "minecraft:block_predicate_filter",
|
||||
"predicate": {
|
||||
"type": "minecraft:matching_blocks",
|
||||
"blocks": "minecraft:air"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"tries": 10,
|
||||
"xz_spread": 7,
|
||||
"y_spread": 1
|
||||
}
|
||||
}
|
@ -1,18 +1,20 @@
|
||||
{
|
||||
"feature": "quickiefabric:sulforpad",
|
||||
"placement": [
|
||||
{
|
||||
"type": "minecraft:count",
|
||||
"count": 4
|
||||
},
|
||||
{
|
||||
"type": "minecraft:environment_scan",
|
||||
"direction_of_search": "up",
|
||||
"direction_of_search": "down",
|
||||
"max_steps": 1,
|
||||
"target_condition": {
|
||||
"type": "minecraft:true"
|
||||
},
|
||||
"allowed_search_condition": {
|
||||
"type": "minecraft:matching_blocks",
|
||||
"offset": [
|
||||
0,
|
||||
1,
|
||||
0
|
||||
],
|
||||
"blocks": "minecraft:air"
|
||||
"blocks": "minecraft:lava"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user