mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
More things
This commit is contained in:
parent
fc0bff23b4
commit
ca68c2703a
3 changed files with 49 additions and 57 deletions
|
@ -17,8 +17,6 @@ import de.ellpeck.actuallyadditions.mod.config.CommonConfig;
|
||||||
import de.ellpeck.actuallyadditions.mod.inventory.ContainerDrill;
|
import de.ellpeck.actuallyadditions.mod.inventory.ContainerDrill;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
|
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
|
||||||
import de.ellpeck.actuallyadditions.mod.util.Util;
|
|
||||||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
|
@ -40,13 +38,10 @@ import net.minecraft.world.item.Tiers;
|
||||||
import net.minecraft.world.item.component.ItemAttributeModifiers;
|
import net.minecraft.world.item.component.ItemAttributeModifiers;
|
||||||
import net.minecraft.world.item.component.ItemContainerContents;
|
import net.minecraft.world.item.component.ItemContainerContents;
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
import net.minecraft.world.item.context.UseOnContext;
|
||||||
import net.minecraft.world.item.enchantment.Enchantments;
|
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
import net.minecraft.world.phys.HitResult;
|
|
||||||
import net.neoforged.neoforge.common.CommonHooks;
|
|
||||||
import net.neoforged.neoforge.common.ItemAbilities;
|
import net.neoforged.neoforge.common.ItemAbilities;
|
||||||
import net.neoforged.neoforge.common.ItemAbility;
|
import net.neoforged.neoforge.common.ItemAbility;
|
||||||
import net.neoforged.neoforge.items.IItemHandler;
|
import net.neoforged.neoforge.items.IItemHandler;
|
||||||
|
@ -217,42 +212,42 @@ public class DrillItem extends ItemEnergy {
|
||||||
: 0.1F;
|
: 0.1F;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override TODO: Check if CommonEvents.onBlockBreaking works
|
||||||
public boolean onBlockStartBreak(@Nonnull ItemStack stack, @Nonnull BlockPos pos, @Nonnull Player player) {
|
// public boolean onBlockStartBreak(@Nonnull ItemStack stack, @Nonnull BlockPos pos, @Nonnull Player player) {
|
||||||
boolean toReturn = false;
|
// boolean toReturn = false;
|
||||||
int use = this.getEnergyUsePerBlock(stack);
|
// int use = this.getEnergyUsePerBlock(stack);
|
||||||
if (this.getEnergyStored(stack) >= use) {
|
// if (this.getEnergyStored(stack) >= use) {
|
||||||
//Enchants the Drill depending on the Upgrades it has
|
// //Enchants the Drill depending on the Upgrades it has
|
||||||
if (this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SILK_TOUCH)) {
|
// if (this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SILK_TOUCH)) {
|
||||||
ItemUtil.addEnchantment(stack, Enchantments.SILK_TOUCH, 1);
|
// ItemUtil.addEnchantment(stack, Enchantments.SILK_TOUCH, 1);
|
||||||
} else {
|
// } else {
|
||||||
if (this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE)) {
|
// if (this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE)) {
|
||||||
ItemUtil.addEnchantment(stack, Enchantments.BLOCK_FORTUNE, this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE_II)
|
// ItemUtil.addEnchantment(stack, Enchantments.BLOCK_FORTUNE, this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE_II)
|
||||||
? 3
|
// ? 3
|
||||||
: 1);
|
// : 1);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
//Block hit
|
// //Block hit
|
||||||
HitResult ray = player.pick(Util.getReachDistance(player), 1f, false);
|
// HitResult ray = player.pick(Util.getReachDistance(player), 1f, false);
|
||||||
if (ray instanceof BlockHitResult trace) {
|
// if (ray instanceof BlockHitResult trace) {
|
||||||
//Breaks the Blocks
|
// //Breaks the Blocks
|
||||||
if (!player.isShiftKeyDown() && this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.THREE_BY_THREE)) {
|
// if (!player.isShiftKeyDown() && this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.THREE_BY_THREE)) {
|
||||||
if (this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FIVE_BY_FIVE)) {
|
// if (this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FIVE_BY_FIVE)) {
|
||||||
toReturn = this.breakBlocks(stack, 2, player.level(), pos, trace.getDirection(), player);
|
// toReturn = this.breakBlocks(stack, 2, player.level(), pos, trace.getDirection(), player);
|
||||||
} else {
|
// } else {
|
||||||
toReturn = this.breakBlocks(stack, 1, player.level(), pos, trace.getDirection(), player);
|
// toReturn = this.breakBlocks(stack, 1, player.level(), pos, trace.getDirection(), player);
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
toReturn = this.breakBlocks(stack, 0, player.level(), pos, trace.getDirection(), player);
|
// toReturn = this.breakBlocks(stack, 0, player.level(), pos, trace.getDirection(), player);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
//Removes Enchantments added above
|
// //Removes Enchantments added above
|
||||||
ItemUtil.removeEnchantment(stack, Enchantments.SILK_TOUCH);
|
// ItemUtil.removeEnchantment(stack, Enchantments.SILK_TOUCH);
|
||||||
ItemUtil.removeEnchantment(stack, Enchantments.BLOCK_FORTUNE);
|
// ItemUtil.removeEnchantment(stack, Enchantments.BLOCK_FORTUNE);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return toReturn;
|
// return toReturn;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/* @Override //TODO old one
|
/* @Override //TODO old one
|
||||||
public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) {
|
public boolean isCorrectToolForDrops(ItemStack stack, BlockState state) {
|
||||||
|
@ -544,7 +539,7 @@ public class DrillItem extends ItemEnergy {
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
float hardness = state.getDestroySpeed(world, pos);
|
float hardness = state.getDestroySpeed(world, pos);
|
||||||
|
|
||||||
boolean canHarvest = (CommonHooks.isCorrectToolForDrops(state, player) || this.isCorrectToolForDrops(stack, state)) && (!isExtra || this.getDestroySpeed(stack, world.getBlockState(pos)) > 1.0F);
|
boolean canHarvest = (player.hasCorrectToolForDrops(state) || this.isCorrectToolForDrops(stack, state)) && (!isExtra || this.getDestroySpeed(stack, world.getBlockState(pos)) > 1.0F);
|
||||||
if (hardness >= 0.0F && (!isExtra || canHarvest && !state.hasBlockEntity())) {
|
if (hardness >= 0.0F && (!isExtra || canHarvest && !state.hasBlockEntity())) {
|
||||||
if (!player.isCreative()) {
|
if (!player.isCreative()) {
|
||||||
this.extractEnergyInternal(stack, use, false);
|
this.extractEnergyInternal(stack, use, false);
|
||||||
|
|
|
@ -38,6 +38,7 @@ import net.minecraft.world.level.storage.loot.LootParams;
|
||||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.neoforged.neoforge.common.SpecialPlantable;
|
import net.neoforged.neoforge.common.SpecialPlantable;
|
||||||
|
import net.neoforged.neoforge.common.Tags;
|
||||||
import net.neoforged.neoforge.common.util.FakePlayerFactory;
|
import net.neoforged.neoforge.common.util.FakePlayerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -76,8 +77,17 @@ public class DefaultFarmerBehavior implements IFarmerBehavior {
|
||||||
public FarmerResult tryPlantSeed(ItemStack seed, Level world, BlockPos pos, IFarmer farmer) {
|
public FarmerResult tryPlantSeed(ItemStack seed, Level world, BlockPos pos, IFarmer farmer) {
|
||||||
int use = 350;
|
int use = 350;
|
||||||
if (farmer.getEnergy() >= use * 2) {
|
if (farmer.getEnergy() >= use * 2) {
|
||||||
if (defaultPlant(world, pos, this.getPlantablePlantFromStack(seed, world, pos), farmer, use)) {
|
var plantable = getPlantableFromStack(seed); //TODO: Should figure out what else to call in here (Farmland stuff etc)
|
||||||
|
if (plantable != null && plantable.canPlacePlantAtPosition(seed, world, pos, Direction.DOWN)) {
|
||||||
|
plantable.spawnPlantAtPosition(seed, world, pos, Direction.DOWN);
|
||||||
|
farmer.extractEnergy(use);
|
||||||
return FarmerResult.SUCCESS;
|
return FarmerResult.SUCCESS;
|
||||||
|
} else {
|
||||||
|
if (seed.is(Tags.Items.SEEDS) && seed.getItem() instanceof BlockItem blockItem) {
|
||||||
|
if (defaultPlant(world, pos, blockItem.getBlock().defaultBlockState(), farmer, use)) {
|
||||||
|
return FarmerResult.SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FarmerResult.FAIL;
|
return FarmerResult.FAIL;
|
||||||
|
@ -147,19 +157,6 @@ public class DefaultFarmerBehavior implements IFarmerBehavior {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlockState getPlantablePlantFromStack(ItemStack stack, Level world, BlockPos pos) {
|
|
||||||
if (!stack.isEmpty()) {
|
|
||||||
SpecialPlantable plantable = this.getPlantableFromStack(stack);
|
|
||||||
if (plantable != null) {
|
|
||||||
BlockState state = plantable.getPlantType(world, pos);
|
|
||||||
if (state != null && state.getBlock() instanceof BonemealableBlock) {
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private SpecialPlantable getPlantableFromStack(ItemStack stack) {
|
private SpecialPlantable getPlantableFromStack(ItemStack stack) {
|
||||||
Item item = stack.getItem();
|
Item item = stack.getItem();
|
||||||
if (item instanceof SpecialPlantable plantable) {
|
if (item instanceof SpecialPlantable plantable) {
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class NetherWartFarmerBehavior implements IFarmerBehavior {
|
||||||
int use = 500;
|
int use = 500;
|
||||||
if (farmer.getEnergy() >= use) {
|
if (farmer.getEnergy() >= use) {
|
||||||
if (seed.getItem() == Items.NETHER_WART) {
|
if (seed.getItem() == Items.NETHER_WART) {
|
||||||
if (world.getBlockState(pos.below()).getBlock().canSustainPlant(world.getBlockState(pos.below()), world, pos.below(), Direction.UP, (IPlantable) Items.NETHER_WART)) {
|
if (world.getBlockState(pos.below()).getBlock().canSustainPlant(world.getBlockState(pos), world, pos.below(), Direction.UP, Blocks.NETHER_WART.defaultBlockState()).isTrue()) {
|
||||||
world.setBlock(pos, Blocks.NETHER_WART.defaultBlockState(), 2);
|
world.setBlock(pos, Blocks.NETHER_WART.defaultBlockState(), 2);
|
||||||
farmer.extractEnergy(use);
|
farmer.extractEnergy(use);
|
||||||
return FarmerResult.SUCCESS;
|
return FarmerResult.SUCCESS;
|
||||||
|
|
Loading…
Reference in a new issue