mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-21 23:13:28 +01:00
Added leaf blower logic :D
This commit is contained in:
parent
c1bad8ba33
commit
8b525252a5
3 changed files with 93 additions and 3 deletions
|
@ -3,6 +3,7 @@ package de.ellpeck.actuallyadditions.common.items;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
|
||||
import de.ellpeck.actuallyadditions.common.items.useables.AllInOneTool;
|
||||
import de.ellpeck.actuallyadditions.common.items.useables.LeafBlowerItem;
|
||||
import de.ellpeck.actuallyadditions.common.items.useables.ManualItem;
|
||||
import de.ellpeck.actuallyadditions.common.items.useables.TeleportStaffItem;
|
||||
import de.ellpeck.actuallyadditions.common.materials.ArmorMaterials;
|
||||
|
@ -171,8 +172,8 @@ public final class ActuallyItems {
|
|||
public static final RegistryObject<Item> CRUSHED_COAL = ITEMS.register("crushed_coal", basicItem());
|
||||
public static final RegistryObject<Item> CRUSHED_BLACK_QUARTZ = ITEMS.register("crushed_black_quartz", basicItem());
|
||||
public static final RegistryObject<Item> SOLIDIFIED_EXPERIENCE = ITEMS.register("solidified_experience", basicItem());
|
||||
public static final RegistryObject<Item> LEAF_BLOWER = ITEMS.register("leaf_blower", basicItem());
|
||||
public static final RegistryObject<Item> ADVANCED_LEAF_BLOWER = ITEMS.register("advanced_leaf_blower", basicItem());
|
||||
public static final RegistryObject<Item> LEAF_BLOWER = ITEMS.register("leaf_blower", () -> new LeafBlowerItem(false));
|
||||
public static final RegistryObject<Item> ADVANCED_LEAF_BLOWER = ITEMS.register("advanced_leaf_blower", () -> new LeafBlowerItem(true));
|
||||
public static final RegistryObject<Item> RING_OF_GROWTH = ITEMS.register("ring_of_growth", basicItem());
|
||||
public static final RegistryObject<Item> RING_OF_MAGNETIZING = ITEMS.register("ring_of_magnetizing", basicItem());
|
||||
public static final RegistryObject<Item> RING_OF_SPEED = ITEMS.register("ring_of_speed", basicItem());
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
package de.ellpeck.actuallyadditions.common.items.useables;
|
||||
|
||||
import de.ellpeck.actuallyadditions.common.items.ActuallyItem;
|
||||
import de.ellpeck.actuallyadditions.common.items.IUseItem;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BushBlock;
|
||||
import net.minecraft.block.LeavesBlock;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IForgeShearable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
public class LeafBlowerItem extends ActuallyItem implements IUseItem {
|
||||
private final boolean isAdvanced;
|
||||
|
||||
public LeafBlowerItem(boolean isAdvanced) {
|
||||
super(baseProps().maxStackSize(0));
|
||||
this.isAdvanced = isAdvanced;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
|
||||
playerIn.setActiveHand(handIn);
|
||||
return ActionResult.resultSuccess(playerIn.getHeldItem(handIn));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUsingTick(ItemStack stack, LivingEntity player, int count) {
|
||||
World world = player.world;
|
||||
BlockPos pos = player.getPosition();
|
||||
|
||||
if (!world.isRemote) {
|
||||
if (count <= this.getUseDuration(stack) && (this.isAdvanced || count % 3 == 0)) {
|
||||
// Breaks the Blocks
|
||||
this.findAndDestroy(world, pos);
|
||||
|
||||
// Plays a Minecart sounds (It really sounds like a Leaf Blower!)
|
||||
player.playSound(SoundEvents.ENTITY_MINECART_RIDING, 0.3F, 0.001F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void findAndDestroy(World world, BlockPos pos) {
|
||||
ArrayList<BlockPos> breakPositions = new ArrayList<>();
|
||||
|
||||
int rangeSides = 5;
|
||||
int rangeUp = 1;
|
||||
for (int reachX = -rangeSides; reachX < rangeSides + 1; reachX++) {
|
||||
for (int reachZ = -rangeSides; reachZ < rangeSides + 1; reachZ++) {
|
||||
for (int reachY = this.isAdvanced ? -rangeSides : -rangeUp; reachY < (this.isAdvanced ? rangeSides : rangeUp) + 1; reachY++) {
|
||||
//The current Block to break
|
||||
BlockPos currentPos = new BlockPos(pos.getX() + reachX, pos.getY() + reachY, pos.getZ() + reachZ);
|
||||
Block block = world.getBlockState(currentPos).getBlock();
|
||||
|
||||
if ((block instanceof BushBlock || block instanceof IForgeShearable) && (this.isAdvanced || !(world.getBlockState(currentPos).getBlock() instanceof LeavesBlock))) {
|
||||
breakPositions.add(currentPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (breakPositions.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Collections.shuffle(breakPositions);
|
||||
BlockPos theCoord = breakPositions.get(0);
|
||||
|
||||
world.destroyBlock(theCoord, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUseDuration(ItemStack stack) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(ItemStack stack) {
|
||||
return true; // todo: add energy logic
|
||||
}
|
||||
}
|
|
@ -74,6 +74,6 @@ public class TeleportStaffItem extends ActuallyItem implements IUseItem {
|
|||
|
||||
@Override
|
||||
public boolean canUse(ItemStack stack) {
|
||||
return true;
|
||||
return true; // todo: add energy logic
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue