corrected drops on harvesting with special tools
This commit is contained in:
@@ -12,7 +12,7 @@ loader_version=0.18.4
|
||||
loom_version=1.15-SNAPSHOT
|
||||
|
||||
# Mod Properties
|
||||
mod_version=26.1.6
|
||||
mod_version=26.1.6.1
|
||||
maven_group=de.jottyfan.minecraft
|
||||
archives_base_name=quickly
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package de.jottyfan.minecraft.block;
|
||||
|
||||
import de.jottyfan.minecraft.item.QuicklyItems;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.world.Containers;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
@@ -24,13 +23,13 @@ import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
*/
|
||||
public class BlockPlant extends CropBlock {
|
||||
|
||||
private Identifier seedName;
|
||||
private Identifier fruitName;
|
||||
private DropDefinition seedDefinition;
|
||||
private DropDefinition fruitDefinition;
|
||||
|
||||
public BlockPlant(Properties properties, Identifier seedName, Identifier fruitName) {
|
||||
public BlockPlant(Properties properties, DropDefinition seedDefinition, DropDefinition fruitDefinition) {
|
||||
super(properties.noOcclusion().dynamicShape());
|
||||
this.seedName = seedName;
|
||||
this.fruitName = fruitName;
|
||||
this.seedDefinition = seedDefinition;
|
||||
this.fruitDefinition = fruitDefinition;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,11 +48,11 @@ public class BlockPlant extends CropBlock {
|
||||
}
|
||||
|
||||
public ItemLike getSeed() {
|
||||
return QuicklyItems.of(seedName);
|
||||
return QuicklyItems.of(seedDefinition.getIdentifier());
|
||||
}
|
||||
|
||||
public ItemLike getFruit() {
|
||||
return QuicklyItems.of(fruitName);
|
||||
return QuicklyItems.of(fruitDefinition.getIdentifier());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package de.jottyfan.minecraft.block;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class DropDefinition {
|
||||
private Identifier identifier;
|
||||
private Integer minValue;
|
||||
private Integer maxValue;
|
||||
|
||||
/**
|
||||
* defines the drop definition; the item or block from identifier should be
|
||||
* dropped x times (minValue <= x <= maxValue)
|
||||
*
|
||||
* @param identifier the identifier of the item or block
|
||||
* @param minValue the minimum of dropped items or blocks
|
||||
* @param maxValue the maximum of dropped items or blocks
|
||||
*/
|
||||
public static final DropDefinition of(Identifier identifier, Integer minValue, Integer maxValue) {
|
||||
DropDefinition bean = new DropDefinition();
|
||||
bean.setIdentifier(identifier);
|
||||
bean.setMinValue(minValue);
|
||||
bean.setMaxValue(maxValue);
|
||||
return bean;
|
||||
}
|
||||
|
||||
public int getRandomSize() {
|
||||
if (maxValue - minValue < 1) {
|
||||
return new Random().nextInt(maxValue);
|
||||
} else {
|
||||
return minValue + new Random().nextInt(maxValue - minValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the identifier
|
||||
*/
|
||||
public Identifier getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param identifier the identifier to set
|
||||
*/
|
||||
public void setIdentifier(Identifier identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the minValue
|
||||
*/
|
||||
public Integer getMinValue() {
|
||||
return minValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param minValue the minValue to set
|
||||
*/
|
||||
public void setMinValue(Integer minValue) {
|
||||
this.minValue = minValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the maxValue
|
||||
*/
|
||||
public Integer getMaxValue() {
|
||||
return maxValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maxValue the maxValue to set
|
||||
*/
|
||||
public void setMaxValue(Integer maxValue) {
|
||||
this.maxValue = maxValue;
|
||||
}
|
||||
}
|
||||
@@ -32,9 +32,11 @@ public class QuicklyBlocks {
|
||||
public static final Block OREDEEPSLATETURQUOISE = registerBlock(ID.OREDEEPSLATETURQUOISE,
|
||||
properties -> new BlockOre(properties, SoundEvents.AMETHYST_BLOCK_CHIME, ID.RAWTURQUOISE));
|
||||
public static final Block COTTONPLANT = registerBlock(ID.BLOCKCOTTONPLANT, Properties.ofFullCopy(Blocks.WHEAT),
|
||||
properties -> new BlockPlant(properties, ID.COTTONSEED, ID.COTTON));
|
||||
properties -> new BlockPlant(properties, DropDefinition.of(ID.COTTONSEED, 1, 1),
|
||||
DropDefinition.of(ID.COTTON, 1, 1)));
|
||||
public static final Block CANOLAPLANT = registerBlock(ID.BLOCKCANOLAPLANT, Properties.ofFullCopy(Blocks.WHEAT),
|
||||
properties -> new BlockPlant(properties, ID.CANOLASEED, ID.CANOLA));
|
||||
properties -> new BlockPlant(properties, DropDefinition.of(ID.CANOLASEED, 1, 1),
|
||||
DropDefinition.of(ID.CANOLA, 1, 1)));
|
||||
public static final Block LAVAHOARDER = registerBlock(ID.LAVAHOARDER,
|
||||
Properties.of().strength(2.5f).lightLevel(state -> state.getValue(Lavahoarder.FILLED) ? 15 : 0),
|
||||
Lavahoarder::new);
|
||||
|
||||
@@ -6,8 +6,10 @@ import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.Containers;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.item.HoeItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@@ -18,6 +20,8 @@ import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.CropBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.storage.loot.LootParams;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
|
||||
/**
|
||||
@@ -26,18 +30,19 @@ import net.minecraft.world.phys.BlockHitResult;
|
||||
*
|
||||
*/
|
||||
public class QHoe extends HoeItem implements ToolRangeable {
|
||||
|
||||
public QIP properties;
|
||||
|
||||
public QHoe(QIP properties) {
|
||||
super(new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, properties.getDurability(), 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS), 7f, 3.1f, properties);
|
||||
super(new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, properties.getDurability(), 7f, 1f, 15,
|
||||
ItemTags.DIAMOND_TOOL_MATERIALS), 7f, 3.1f, properties);
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult useOn(UseOnContext context) {
|
||||
InteractionResult res = super.useOn(context);
|
||||
boolean isCrop = context.getLevel().getBlockState(context.getClickedPos()).getBlock() instanceof CropBlock;
|
||||
Block block = context.getLevel().getBlockState(context.getClickedPos()).getBlock();
|
||||
boolean isCrop = block instanceof CropBlock;
|
||||
if (!InteractionResult.PASS.equals(res) || isCrop) {
|
||||
HarvestRange range = properties.getHarvestRange();
|
||||
for (int x = -range.getxRange(); x <= range.getxRange(); x++) {
|
||||
@@ -55,6 +60,7 @@ public class QHoe extends HoeItem implements ToolRangeable {
|
||||
}
|
||||
}
|
||||
}
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -69,16 +75,24 @@ public class QHoe extends HoeItem implements ToolRangeable {
|
||||
}
|
||||
|
||||
private void harvestIfPossible(BlockPos pos, Level level) {
|
||||
if (!level.isClientSide()) {
|
||||
BlockState blockState = level.getBlockState(pos);
|
||||
Block block = blockState.getBlock();
|
||||
if (block instanceof CropBlock) {
|
||||
CropBlock cBlock = (CropBlock) block;
|
||||
if (block instanceof CropBlock cBlock) {
|
||||
if (cBlock.isMaxAge(blockState)) {
|
||||
Block.dropResources(blockState, level, pos);
|
||||
LootParams.Builder builder = new LootParams.Builder((ServerLevel) level)
|
||||
.withParameter(LootContextParams.ORIGIN, pos.getCenter())
|
||||
.withParameter(LootContextParams.BLOCK_STATE, blockState)
|
||||
.withOptionalParameter(LootContextParams.BLOCK_ENTITY, level.getBlockEntity(pos))
|
||||
.withParameter(LootContextParams.TOOL, ItemStack.EMPTY);
|
||||
for (ItemStack stack : blockState.getDrops(builder)) {
|
||||
Containers.dropItemStack(level, pos.getX(), pos.getY(), pos.getZ(), stack);
|
||||
}
|
||||
level.setBlockAndUpdate(pos, cBlock.defaultBlockState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreakNeighbors(BlockState blockState) {
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"name": "quickly:canola",
|
||||
"functions": [
|
||||
{
|
||||
"function": "minecraft:set_count",
|
||||
"count": {
|
||||
"min": 1,
|
||||
"max": 2
|
||||
},
|
||||
"add": false
|
||||
}
|
||||
],
|
||||
"conditions": [
|
||||
{
|
||||
"condition": "minecraft:location_check",
|
||||
"predicate": {
|
||||
"block": {
|
||||
"properties": {
|
||||
"age": "7"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"name": "quickly:canolaseed",
|
||||
"functions": [
|
||||
{
|
||||
"function": "minecraft:apply_bonus",
|
||||
"enchantment": "minecraft:fortune",
|
||||
"formula": "minecraft:binomial_with_bonus_count",
|
||||
"parameters": {
|
||||
"extra": 2,
|
||||
"probability": 0.5
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"name": "quickly:cotton",
|
||||
"functions": [
|
||||
{
|
||||
"function": "minecraft:set_count",
|
||||
"count": {
|
||||
"min": 1,
|
||||
"max": 3
|
||||
}
|
||||
}
|
||||
],
|
||||
"conditions": [
|
||||
{
|
||||
"condition": "minecraft:location_check",
|
||||
"predicate": {
|
||||
"block": {
|
||||
"properties": {
|
||||
"age": "7"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"name": "quickly:cottonseed",
|
||||
"functions": [
|
||||
{
|
||||
"function": "minecraft:apply_bonus",
|
||||
"enchantment": "minecraft:fortune",
|
||||
"formula": "minecraft:binomial_with_bonus_count",
|
||||
"parameters": {
|
||||
"extra": 2,
|
||||
"probability": 0.5
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user