This commit is contained in:
Jörg Henke 2020-11-03 22:59:35 +01:00
parent 4dd73c0e78
commit 6e67d3f422
3 changed files with 43 additions and 13 deletions

View File

@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.16.3
yarn_mappings=1.16.3+build.1
loader_version=0.9.3+build.207
minecraft_version=1.16.4
yarn_mappings=1.16.4+build.3
loader_version=0.10.6+build.214
# Mod Properties
mod_version = 1.16.3.9
mod_version = 1.16.4.0
maven_group = de.jottyfan.minecraft
archives_base_name = quickiefabric
# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.20.2+build.402-1.16
fabric_version=0.25.1+build.416-1.16

View File

@ -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);
}

View File

@ -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