From 87f61ce5387d46e102ffbfbbae1f1f05583239d7 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Sat, 1 Feb 2020 14:26:19 +0100 Subject: [PATCH] Bug Fixes and Enhancements - Fixed Tree fertilizer spawning grass when growing large spruce trees - Nerfed durability of the Deforester - Items dropped by a tree cut with a Deforester now 'fall' away from the player - Blockzappers can now be used together with the Symmetry Wand - Fixed deployer not looking in the right direction - You can now put items on Crafters directly - Tree cutting is less lenient about whether the trunk was fully cut or not - Fixed filtering not looking past first matched item if said item doesn't have the required amount --- .../create/foundation/item/ItemHelper.java | 18 ++++++++++++--- .../create/foundation/utility/TreeCutter.java | 11 ++++++--- .../foundation/utility/WrappedWorld.java | 5 ++++ .../crafter/MechanicalCrafterBlock.java | 20 +++++++++++++++- .../deployer/DeployerFakePlayer.java | 2 +- .../deployer/DeployerTileEntity.java | 6 +---- .../relays/elementary/CogwheelBlockItem.java | 1 - .../blockzapper/BlockzapperItem.java | 12 ++++++++++ .../deforester/DeforesterItem.java | 23 +++++++++++++++---- .../symmetry/SymmetryWandItem.java | 9 +++++++- .../curiosities/tools/AllToolTiers.java | 2 +- .../modules/gardens/TreeFertilizerItem.java | 6 ++--- 12 files changed, 92 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/item/ItemHelper.java b/src/main/java/com/simibubi/create/foundation/item/ItemHelper.java index 01db1b043..d6ea75998 100644 --- a/src/main/java/com/simibubi/create/foundation/item/ItemHelper.java +++ b/src/main/java/com/simibubi/create/foundation/item/ItemHelper.java @@ -99,17 +99,22 @@ public class ItemHelper { boolean checkHasEnoughItems = amountRequired; boolean hasEnoughItems = !checkHasEnoughItems; int maxExtractionCount = hasEnoughItems ? CreateConfig.parameters.extractorAmount.get() : exactAmount; - + boolean potentialOtherMatch = false; + Extraction: do { extracting = ItemStack.EMPTY; for (int slot = 0; slot < inv.getSlots(); slot++) { ItemStack stack = inv.extractItem(slot, maxExtractionCount - extracting.getCount(), true); + if (stack.isEmpty()) + continue; if (!test.test(stack)) continue; - if (!extracting.isEmpty() && !ItemHandlerHelper.canItemStacksStack(stack, extracting)) + if (!extracting.isEmpty() && !ItemHandlerHelper.canItemStacksStack(stack, extracting)) { + potentialOtherMatch = true; continue; + } if (extracting.isEmpty()) extracting = stack.copy(); @@ -129,11 +134,18 @@ public class ItemHelper { } } } - + + if (!extracting.isEmpty() && !hasEnoughItems && potentialOtherMatch) { + ItemStack blackListed = extracting.copy(); + test = test.and(i -> !ItemHandlerHelper.canItemStacksStack(i, blackListed)); + continue; + } + if (checkHasEnoughItems) checkHasEnoughItems = false; else break Extraction; + } while (true); if (amountRequired && extracting.getCount() < exactAmount) diff --git a/src/main/java/com/simibubi/create/foundation/utility/TreeCutter.java b/src/main/java/com/simibubi/create/foundation/utility/TreeCutter.java index a07b5e590..7635aa7bc 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/TreeCutter.java +++ b/src/main/java/com/simibubi/create/foundation/utility/TreeCutter.java @@ -44,7 +44,7 @@ public class TreeCutter { return null; visited.add(pos); - addNeighbours(pos, frontier, visited); + BlockPos.getAllInBox(pos.add(-1, 0, -1), pos.add(1, 1, 1)).forEach(p -> frontier.add(new BlockPos(p))); // Find all logs while (!frontier.isEmpty()) { @@ -105,19 +105,24 @@ public class TreeCutter { private static boolean validateCut(IBlockReader reader, BlockPos pos) { Set visited = new HashSet<>(); List frontier = new LinkedList<>(); + frontier.add(pos); frontier.add(pos.up()); + int posY = pos.getY(); while (!frontier.isEmpty()) { BlockPos currentPos = frontier.remove(0); visited.add(currentPos); + boolean lowerLayer = currentPos.getY() == posY; if (!isLog(reader.getBlockState(currentPos))) continue; - if (!pos.equals(currentPos.down()) && isLog(reader.getBlockState(currentPos.down()))) + if (!lowerLayer && !pos.equals(currentPos.down()) && isLog(reader.getBlockState(currentPos.down()))) return false; for (Direction direction : Direction.values()) { - if (direction.getAxis().isVertical()) + if (direction == Direction.DOWN) + continue; + if (direction == Direction.UP && !lowerLayer) continue; BlockPos offset = currentPos.offset(direction); if (visited.contains(offset)) diff --git a/src/main/java/com/simibubi/create/foundation/utility/WrappedWorld.java b/src/main/java/com/simibubi/create/foundation/utility/WrappedWorld.java index 487138efd..bd5ff8f79 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/WrappedWorld.java +++ b/src/main/java/com/simibubi/create/foundation/utility/WrappedWorld.java @@ -87,6 +87,11 @@ public class WrappedWorld extends World { return null; } + @Override + public boolean addEntity(Entity entityIn) { + return world.addEntity(entityIn); + } + @Override public void registerMapData(MapData mapDataIn) { } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/crafter/MechanicalCrafterBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/components/crafter/MechanicalCrafterBlock.java index 0a76bf009..6bd6c512a 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/crafter/MechanicalCrafterBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/crafter/MechanicalCrafterBlock.java @@ -35,7 +35,11 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorldReader; import net.minecraft.world.World; +import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.items.CapabilityItemHandler; +import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemHandlerHelper; +import net.minecraftforge.items.ItemStackHandler; public class MechanicalCrafterBlock extends HorizontalKineticBlock implements IWithTileEntity, IHaveConnectedTextures { @@ -149,7 +153,7 @@ public class MechanicalCrafterBlock extends HorizontalKineticBlock return ActionResultType.SUCCESS; } - return super.onWrenched(state, context); + return ActionResultType.PASS; } @Override @@ -170,6 +174,20 @@ public class MechanicalCrafterBlock extends HorizontalKineticBlock return true; } + if (crafter.phase == Phase.IDLE && !isHand) { + if (worldIn.isRemote) + return true; + LazyOptional capability = crafter + .getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY); + if (!capability.isPresent()) + return false; + ItemStack remainder = ItemHandlerHelper.insertItem(capability.orElse(new ItemStackHandler()), + heldItem.copy(), false); + if (remainder.getCount() != heldItem.getCount()) + player.setHeldItem(handIn, remainder); + return true; + } + ItemStack inSlot = crafter.inventory.getStackInSlot(0); if (inSlot.isEmpty()) return false; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerFakePlayer.java b/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerFakePlayer.java index 4fa0985f1..d8852fece 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerFakePlayer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerFakePlayer.java @@ -42,7 +42,7 @@ public class DeployerFakePlayer extends FakePlayer { super(world, DEPLOYER_PROFILE); connection = new FakePlayNetHandler(world.getServer(), this); } - + @Override public OptionalInt openContainer(INamedContainerProvider container) { return OptionalInt.empty(); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerTileEntity.java index d4db2f745..e53a29918 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/deployer/DeployerTileEntity.java @@ -252,7 +252,7 @@ public class DeployerTileEntity extends KineticTileEntity { Vec3d rayTarget = center.add(movementVector.scale(5 / 2f - 1 / 64f)); BlockPos clickedPos = pos.offset(direction, 2); - player.rotationYaw = AngleHelper.horizontalAngle(direction) + 180; + player.rotationYaw = AngleHelper.horizontalAngle(direction); player.rotationPitch = direction == Direction.UP ? -90 : direction == Direction.DOWN ? 90 : 0; player.setPosition(rayOrigin.x, rayOrigin.y, rayOrigin.z); @@ -379,10 +379,6 @@ public class DeployerTileEntity extends KineticTileEntity { ActionResultType onItemUse = stack.onItemUse(itemusecontext); if (onItemUse == ActionResultType.SUCCESS) return; - - // some items use hard-coded eye positions - if (item == Items.SNOWBALL || item == Items.EGG) - player.posY -= 1.5f; if (item == Items.ENDER_PEARL) return; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/elementary/CogwheelBlockItem.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/elementary/CogwheelBlockItem.java index 0dd2c8432..ef1f12939 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/elementary/CogwheelBlockItem.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/elementary/CogwheelBlockItem.java @@ -1,7 +1,6 @@ package com.simibubi.create.modules.contraptions.relays.elementary; import com.simibubi.create.AllBlocks; -import com.simibubi.create.foundation.utility.Debug; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.block.Block; diff --git a/src/main/java/com/simibubi/create/modules/curiosities/blockzapper/BlockzapperItem.java b/src/main/java/com/simibubi/create/modules/curiosities/blockzapper/BlockzapperItem.java index 404b35da5..911b88196 100644 --- a/src/main/java/com/simibubi/create/modules/curiosities/blockzapper/BlockzapperItem.java +++ b/src/main/java/com/simibubi/create/modules/curiosities/blockzapper/BlockzapperItem.java @@ -18,6 +18,7 @@ import com.simibubi.create.foundation.utility.BlockHelper; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.NBTHelper; +import net.minecraft.advancements.CriteriaTriggers; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -61,6 +62,8 @@ import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.common.util.BlockSnapshot; +import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.network.PacketDistributor; @@ -253,9 +256,18 @@ public class BlockzapperItem extends Item { world.getBlockState(placed.offset(updateDirection)), world, placed, placed.offset(updateDirection)); + BlockSnapshot blocksnapshot = BlockSnapshot.getBlockSnapshot(world, placed); IFluidState ifluidstate = world.getFluidState(placed); world.setBlockState(placed, ifluidstate.getBlockState(), 18); world.setBlockState(placed, stateToUse); + if (ForgeEventFactory.onBlockPlace(player, blocksnapshot, Direction.UP)) { + blocksnapshot.restore(true, false); + return new ActionResult(ActionResultType.FAIL, item); + } + + if (player instanceof ServerPlayerEntity) + CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayerEntity) player, placed, + new ItemStack(stateToUse.getBlock())); } diff --git a/src/main/java/com/simibubi/create/modules/curiosities/deforester/DeforesterItem.java b/src/main/java/com/simibubi/create/modules/curiosities/deforester/DeforesterItem.java index 1b2dc5bf1..a84c8f6da 100644 --- a/src/main/java/com/simibubi/create/modules/curiosities/deforester/DeforesterItem.java +++ b/src/main/java/com/simibubi/create/modules/curiosities/deforester/DeforesterItem.java @@ -4,15 +4,18 @@ import com.simibubi.create.AllItems; import com.simibubi.create.foundation.utility.BlockHelper; import com.simibubi.create.foundation.utility.TreeCutter; import com.simibubi.create.foundation.utility.TreeCutter.Tree; +import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.modules.curiosities.tools.AllToolTiers; -import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.AxeItem; import net.minecraft.item.ItemStack; import net.minecraft.tags.BlockTags; +import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.IWorld; import net.minecraft.world.World; import net.minecraftforge.event.world.BlockEvent; @@ -40,15 +43,18 @@ public class DeforesterItem extends AxeItem { if (world == null) return; + Vec3d vec = player.getLookVec(); for (BlockPos log : tree.logs) BlockHelper.destroyBlock(world, log, 1 / 2f, item -> { - if (dropBlock) - Block.spawnAsEntity(world, log, item); + if (dropBlock) { + dropItemFromCutTree(world, pos, vec, log, item); + stack.damageItem(1, player, p -> p.sendBreakAnimation(Hand.MAIN_HAND)); + } }); for (BlockPos leaf : tree.leaves) BlockHelper.destroyBlock(world, leaf, 1 / 8f, item -> { if (dropBlock) - Block.spawnAsEntity(world, leaf, item); + dropItemFromCutTree(world, pos, vec, leaf, item); }); } @@ -60,4 +66,13 @@ public class DeforesterItem extends AxeItem { destroyTree(heldItemMainhand, event.getWorld(), event.getState(), event.getPos(), event.getPlayer()); } + public static void dropItemFromCutTree(World world, BlockPos breakingPos, Vec3d fallDirection, BlockPos pos, + ItemStack stack) { + float distance = (float) Math.sqrt(pos.distanceSq(breakingPos)); + Vec3d dropPos = VecHelper.getCenterOf(pos); + ItemEntity entity = new ItemEntity(world, dropPos.x, dropPos.y, dropPos.z, stack); + entity.setMotion(fallDirection.scale(distance / 20f)); + world.addEntity(entity); + } + } diff --git a/src/main/java/com/simibubi/create/modules/curiosities/symmetry/SymmetryWandItem.java b/src/main/java/com/simibubi/create/modules/curiosities/symmetry/SymmetryWandItem.java index ecfa4382a..4b63adbc1 100644 --- a/src/main/java/com/simibubi/create/modules/curiosities/symmetry/SymmetryWandItem.java +++ b/src/main/java/com/simibubi/create/modules/curiosities/symmetry/SymmetryWandItem.java @@ -172,7 +172,8 @@ public class SymmetryWandItem extends Item { Vec3d mirrorPos = symmetry.getPosition(); if (mirrorPos.distanceTo(new Vec3d(pos)) > parameters.maxSymmetryWandRange.get()) return; - if (!player.isCreative() && BlockHelper.findAndRemoveInInventory(block, player, 1) == 0) + if (!player.isCreative() && isHoldingBlock(player, block) + && BlockHelper.findAndRemoveInInventory(block, player, 1) == 0) return; symmetry.process(blockSet); @@ -213,6 +214,12 @@ public class SymmetryWandItem extends Item { new SymmetryEffectPacket(to, targets)); } + private static boolean isHoldingBlock(PlayerEntity player, BlockState block) { + ItemStack itemBlock = BlockHelper.getRequiredItem(block); + return player.getHeldItemMainhand().isItemEqual(itemBlock) + || player.getHeldItemOffhand().isItemEqual(itemBlock); + } + public static void remove(World world, ItemStack wand, PlayerEntity player, BlockPos pos) { BlockState air = Blocks.AIR.getDefaultState(); BlockState ogBlock = world.getBlockState(pos); diff --git a/src/main/java/com/simibubi/create/modules/curiosities/tools/AllToolTiers.java b/src/main/java/com/simibubi/create/modules/curiosities/tools/AllToolTiers.java index 0c5c6e28c..0188f27db 100644 --- a/src/main/java/com/simibubi/create/modules/curiosities/tools/AllToolTiers.java +++ b/src/main/java/com/simibubi/create/modules/curiosities/tools/AllToolTiers.java @@ -23,7 +23,7 @@ public enum AllToolTiers implements IItemTier { return Ingredient.fromItems(AllItems.SHADOW_STEEL.item); }), - RADIANT(4, 2303, 16.0F, 3.5F, 10, () -> { + RADIANT(4, 1024, 16.0F, 3.5F, 10, () -> { return Ingredient.fromItems(AllItems.REFINED_RADIANCE.item); }), diff --git a/src/main/java/com/simibubi/create/modules/gardens/TreeFertilizerItem.java b/src/main/java/com/simibubi/create/modules/gardens/TreeFertilizerItem.java index 00f864cce..801ed6710 100644 --- a/src/main/java/com/simibubi/create/modules/gardens/TreeFertilizerItem.java +++ b/src/main/java/com/simibubi/create/modules/gardens/TreeFertilizerItem.java @@ -52,8 +52,8 @@ public class TreeFertilizerItem extends Item { if (!world.getBlockState(pos).isNormalCube(world, pos) && context.getWorld().getBlockState(actualPos).isNormalCube(context.getWorld(), actualPos)) continue; - if (world.getBlockState(pos).getBlock() == Blocks.PODZOL - && context.getWorld().getBlockState(actualPos).getBlock() != Blocks.GRASS_BLOCK) + if (world.getBlockState(pos).getBlock() == Blocks.GRASS_BLOCK + || world.getBlockState(pos).getBlock() == Blocks.PODZOL) continue; context.getWorld().setBlockState(actualPos, world.getBlockState(pos)); @@ -80,7 +80,7 @@ public class TreeFertilizerItem extends Item { return Blocks.GRASS_BLOCK.getDefaultState(); return super.getBlockState(pos); } - + } }