1.16.4.0
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package de.jottyfan.minecraft.quickiefabric.blocks;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import de.jottyfan.minecraft.quickiefabric.items.QuickieItems;
|
||||
@ -10,6 +11,7 @@ import net.minecraft.block.CropBlock;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemConvertible;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContext.Builder;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ItemScatterer;
|
||||
@ -24,6 +26,32 @@ public class BlockCottonplant extends CropBlock {
|
||||
super(FabricBlockSettings.copy(Blocks.WHEAT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDroppedStacks(BlockState state, Builder builder) {
|
||||
DefaultedList<ItemStack> list = DefaultedList.of();
|
||||
list.add(new ItemStack(getSeedsItem())); // the one from the seed
|
||||
if (isMature(state)) {
|
||||
list.add(new ItemStack(getSeedsItem(), new Random().nextInt(3)));
|
||||
list.add(new ItemStack(QuickieItems.COTTON, new Random().nextFloat() > 0.9f ? 2 : 1));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private void spawnHarvested(World world, BlockPos pos, BlockState state) {
|
||||
DefaultedList<ItemStack> list = DefaultedList.of();
|
||||
getDroppedStacks(state, null).forEach(itemStack -> {
|
||||
list.add(itemStack);
|
||||
});
|
||||
ItemScatterer.spawn(world, pos, list);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
|
||||
spawnHarvested(world, pos, state);
|
||||
super.onBreak(world, pos, state, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemConvertible getSeedsItem() {
|
||||
return QuickieItems.COTTONSEED;
|
||||
@ -33,11 +61,8 @@ public class BlockCottonplant extends CropBlock {
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand,
|
||||
BlockHitResult hitResult) {
|
||||
if (!world.isClient && isMature(state)) {
|
||||
DefaultedList<ItemStack> list = DefaultedList.of();
|
||||
list.add(new ItemStack(getSeedsItem(), new Random().nextInt(3) + 1));
|
||||
list.add(new ItemStack(QuickieItems.COTTON, new Random().nextFloat() > 0.9f ? 2 : 1));
|
||||
spawnHarvested(world, pos, state);
|
||||
world.setBlockState(pos, state.with(AGE, 0));
|
||||
ItemScatterer.spawn(world, pos, list);
|
||||
}
|
||||
return super.onUse(state, world, pos, player, hand, hitResult);
|
||||
}
|
||||
|
@ -1,10 +1,15 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shapeless",
|
||||
"ingredients": [
|
||||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"pattern": [
|
||||
"c",
|
||||
"c",
|
||||
"c"
|
||||
],
|
||||
"key": {
|
||||
"c": {
|
||||
"item": "quickiefabric:cotton"
|
||||
}
|
||||
],
|
||||
},
|
||||
"result": {
|
||||
"item": "minecraft:string",
|
||||
"count": 1
|
||||
|
Reference in New Issue
Block a user