too much assist

- add a configurable range to placement helpers i.e. the pole helper specifically
This commit is contained in:
zelophed 2021-03-12 03:47:36 +01:00
parent 154000290e
commit 51c919e4d8
11 changed files with 90 additions and 146 deletions

View file

@ -1,13 +1,5 @@
package com.simibubi.create.content.contraptions.components.structureMovement.bearing;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import javax.annotation.Nullable;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllShapes;
import com.simibubi.create.foundation.block.ProperDirectionalBlock;
@ -16,18 +8,13 @@ import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.placement.IPlacementHelper;
import com.simibubi.create.foundation.utility.placement.PlacementHelpers;
import com.simibubi.create.foundation.utility.placement.PlacementOffset;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.DyeColor;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ShearsItem;
import net.minecraft.item.*;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
@ -40,6 +27,13 @@ import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
public class SailBlock extends ProperDirectionalBlock {
public static SailBlock frame(Properties properties) {
@ -71,7 +65,7 @@ public class SailBlock extends ProperDirectionalBlock {
IPlacementHelper placementHelper = PlacementHelpers.get(placementHelperId);
if (placementHelper.matchesItem(heldItem))
return placementHelper.getOffset(world, state, pos, ray).placeInWorld(world, (BlockItem) heldItem.getItem(), player, hand, ray);
return placementHelper.getOffset(player, world, state, pos, ray).placeInWorld(world, (BlockItem) heldItem.getItem(), player, hand, ray);
if (heldItem.getItem() instanceof ShearsItem) {
if (!world.isRemote)
@ -209,7 +203,7 @@ public class SailBlock extends ProperDirectionalBlock {
}
@Override
public PlacementOffset getOffset(World world, BlockState state, BlockPos pos, BlockRayTraceResult ray) {
public PlacementOffset getOffset(PlayerEntity player, World world, BlockState state, BlockPos pos, BlockRayTraceResult ray) {
List<Direction> directions = IPlacementHelper.orderedByDistanceExceptAxis(pos, ray.getHitVec(), state.get(SailBlock.FACING).getAxis(), dir -> world.getBlockState(pos.offset(dir)).getMaterial().isReplaceable());
if (directions.isEmpty())
@ -218,11 +212,5 @@ public class SailBlock extends ProperDirectionalBlock {
return PlacementOffset.success(pos.offset(directions.get(0)), s -> s.with(FACING, state.get(FACING)));
}
}
@Override
public void renderAt(BlockPos pos, BlockState state, BlockRayTraceResult ray, PlacementOffset offset) {
//IPlacementHelper.renderArrow(VecHelper.getCenterOf(pos), VecHelper.getCenterOf(offset.getPos()), state.get(FACING));
displayGhost(offset);
}
}
}

View file

@ -1,20 +1,13 @@
package com.simibubi.create.content.contraptions.components.structureMovement.piston;
import static com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isExtensionPole;
import static com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isPiston;
import static com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isPistonHead;
import java.util.function.Predicate;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllShapes;
import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.PistonState;
import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.*;
import com.simibubi.create.content.contraptions.wrench.IWrenchable;
import com.simibubi.create.foundation.block.ProperDirectionalBlock;
import com.simibubi.create.foundation.utility.placement.IPlacementHelper;
import com.simibubi.create.foundation.utility.placement.PlacementHelpers;
import com.simibubi.create.foundation.utility.placement.util.PoleHelper;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
@ -41,6 +34,10 @@ import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import java.util.function.Predicate;
import static com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.*;
public class PistonExtensionPoleBlock extends ProperDirectionalBlock implements IWrenchable, IWaterLoggable {
private static final int placementHelperId = PlacementHelpers.register(PlacementHelper.get());
@ -119,7 +116,7 @@ public class PistonExtensionPoleBlock extends ProperDirectionalBlock implements
IPlacementHelper placementHelper = PlacementHelpers.get(placementHelperId);
if (placementHelper.matchesItem(heldItem) && !player.isSneaking())
return placementHelper.getOffset(world, state, pos, ray).placeInWorld(world, (BlockItem) heldItem.getItem(), player, hand, ray);
return placementHelper.getOffset(player, world, state, pos, ray).placeInWorld(world, (BlockItem) heldItem.getItem(), player, hand, ray);
return ActionResultType.PASS;
}

View file

@ -1,9 +1,5 @@
package com.simibubi.create.content.contraptions.relays.advanced;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllShapes;
import com.simibubi.create.AllTileEntities;
@ -15,7 +11,6 @@ import com.simibubi.create.foundation.utility.placement.IPlacementHelper;
import com.simibubi.create.foundation.utility.placement.PlacementHelpers;
import com.simibubi.create.foundation.utility.placement.PlacementOffset;
import com.simibubi.create.foundation.utility.placement.util.PoleHelper;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
@ -44,6 +39,10 @@ import net.minecraft.world.IWorld;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
public class GantryShaftBlock extends DirectionalKineticBlock {
public static final IProperty<Part> PART = EnumProperty.create("part", Part.class);
@ -73,7 +72,7 @@ public class GantryShaftBlock extends DirectionalKineticBlock {
if (!placementHelper.matchesItem(heldItem))
return ActionResultType.PASS;
return placementHelper.getOffset(world, state, pos, ray).placeInWorld(world, ((BlockItem) heldItem.getItem()), player, hand, ray);
return placementHelper.getOffset(player, world, state, pos, ray).placeInWorld(world, ((BlockItem) heldItem.getItem()), player, hand, ray);
}
@Override
@ -283,12 +282,10 @@ public class GantryShaftBlock extends DirectionalKineticBlock {
}
@Override
public PlacementOffset getOffset(World world, BlockState state, BlockPos pos, BlockRayTraceResult ray) {
PlacementOffset offset = super.getOffset(world, state, pos, ray);
if (!offset.isSuccessful())
return offset;
return PlacementOffset.success(offset.getPos(), offset.getTransform()
.andThen(s -> s.with(POWERED, state.get(POWERED))));
public PlacementOffset getOffset(PlayerEntity player, World world, BlockState state, BlockPos pos, BlockRayTraceResult ray) {
PlacementOffset offset = super.getOffset(player, world, state, pos, ray);
offset.withTransform(offset.getTransform().andThen(s -> s.with(POWERED, state.get(POWERED))));
return offset;
}
}

View file

@ -1,7 +1,5 @@
package com.simibubi.create.content.contraptions.relays.advanced;
import java.util.function.Predicate;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllShapes;
import com.simibubi.create.AllTileEntities;
@ -12,7 +10,6 @@ import com.simibubi.create.foundation.block.ITE;
import com.simibubi.create.foundation.utility.placement.IPlacementHelper;
import com.simibubi.create.foundation.utility.placement.PlacementHelpers;
import com.simibubi.create.foundation.utility.placement.PlacementOffset;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
@ -31,6 +28,8 @@ import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import java.util.function.Predicate;
public class SpeedControllerBlock extends HorizontalAxisKineticBlock implements ITE<SpeedControllerTileEntity> {
private static final int placementHelperId = PlacementHelpers.register(new PlacementHelper());
@ -69,7 +68,7 @@ public class SpeedControllerBlock extends HorizontalAxisKineticBlock implements
ItemStack heldItem = player.getHeldItem(hand);
IPlacementHelper helper = PlacementHelpers.get(placementHelperId);
if (helper.matchesItem(heldItem))
return helper.getOffset(world, state, pos, ray).placeInWorld(world, (BlockItem) heldItem.getItem(), player, hand, ray);
return helper.getOffset(player, world, state, pos, ray).placeInWorld(world, (BlockItem) heldItem.getItem(), player, hand, ray);
return ActionResultType.PASS;
}
@ -92,7 +91,7 @@ public class SpeedControllerBlock extends HorizontalAxisKineticBlock implements
}
@Override
public PlacementOffset getOffset(World world, BlockState state, BlockPos pos, BlockRayTraceResult ray) {
public PlacementOffset getOffset(PlayerEntity player, World world, BlockState state, BlockPos pos, BlockRayTraceResult ray) {
BlockPos newPos = pos.up();
if (!world.getBlockState(newPos)
.getMaterial()
@ -107,15 +106,6 @@ public class SpeedControllerBlock extends HorizontalAxisKineticBlock implements
return PlacementOffset.success(newPos, s -> s.with(CogWheelBlock.AXIS, newAxis));
}
@Override
public void renderAt(BlockPos pos, BlockState state, BlockRayTraceResult ray, PlacementOffset offset) {
//IPlacementHelper.renderArrow(VecHelper.getCenterOf(pos), VecHelper.getCenterOf(offset.getPos()),
// Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE,
// state.get(HORIZONTAL_AXIS) == Axis.X ? Axis.Z : Axis.X));
displayGhost(offset);
}
}
@Override

View file

@ -1,10 +1,5 @@
package com.simibubi.create.content.contraptions.relays.elementary;
import static com.simibubi.create.content.contraptions.base.RotatedPillarKineticBlock.AXIS;
import java.util.List;
import java.util.function.Predicate;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllShapes;
import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock;
@ -15,7 +10,6 @@ import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.placement.IPlacementHelper;
import com.simibubi.create.foundation.utility.placement.PlacementHelpers;
import com.simibubi.create.foundation.utility.placement.PlacementOffset;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
@ -31,6 +25,11 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.World;
import java.util.List;
import java.util.function.Predicate;
import static com.simibubi.create.content.contraptions.base.RotatedPillarKineticBlock.AXIS;
public class CogwheelBlockItem extends BlockItem {
boolean large;
@ -56,14 +55,14 @@ public class CogwheelBlockItem extends BlockItem {
PlayerEntity player = context.getPlayer();
BlockRayTraceResult ray = new BlockRayTraceResult(context.getHitVec(), context.getFace(), pos, true);
if (helper.matchesState(state) && player != null && !player.isSneaking()) {
return helper.getOffset(world, state, pos, ray).placeInWorld(world, this, player, context.getHand(), ray);
return helper.getOffset(player, world, state, pos, ray).placeInWorld(world, this, player, context.getHand(), ray);
}
if (integratedCogHelperId != -1) {
helper = PlacementHelpers.get(integratedCogHelperId);
if (helper.matchesState(state) && player != null && !player.isSneaking()) {
return helper.getOffset(world, state, pos, ray).placeInWorld(world, this, player, context.getHand(), ray);
return helper.getOffset(player, world, state, pos, ray).placeInWorld(world, this, player, context.getHand(), ray);
}
}
@ -119,7 +118,7 @@ public class CogwheelBlockItem extends BlockItem {
}
@Override
public PlacementOffset getOffset(World world, BlockState state, BlockPos pos, BlockRayTraceResult ray) {
public PlacementOffset getOffset(PlayerEntity player, World world, BlockState state, BlockPos pos, BlockRayTraceResult ray) {
if (hitOnShaft(state, ray))
return PlacementOffset.fail();
@ -145,16 +144,7 @@ public class CogwheelBlockItem extends BlockItem {
return PlacementOffset.fail();
}
return super.getOffset(world, state, pos, ray);
}
@Override
public void renderAt(BlockPos pos, BlockState state, BlockRayTraceResult ray, PlacementOffset offset) {
//IPlacementHelper.renderArrow(VecHelper.getCenterOf(pos), VecHelper.getCenterOf(offset.getPos()),
// Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, state.get(AXIS)),
// ((CogWheelBlock) state.getBlock()).isLarge ? 1.5D : 0.75D);
displayGhost(offset);
return super.getOffset(player, world, state, pos, ray);
}
}
@ -167,7 +157,7 @@ public class CogwheelBlockItem extends BlockItem {
}
@Override
public PlacementOffset getOffset(World world, BlockState state, BlockPos pos, BlockRayTraceResult ray) {
public PlacementOffset getOffset(PlayerEntity player, World world, BlockState state, BlockPos pos, BlockRayTraceResult ray) {
if (hitOnShaft(state, ray))
return PlacementOffset.fail();
@ -190,7 +180,7 @@ public class CogwheelBlockItem extends BlockItem {
return PlacementOffset.fail();
}
return super.getOffset(world, state, pos, ray);
return super.getOffset(player, world, state, pos, ray);
}
}
@ -203,7 +193,7 @@ public class CogwheelBlockItem extends BlockItem {
}
@Override
public PlacementOffset getOffset(World world, BlockState state, BlockPos pos, BlockRayTraceResult ray) {
public PlacementOffset getOffset(PlayerEntity player, World world, BlockState state, BlockPos pos, BlockRayTraceResult ray) {
// diagonal gears of different size
Direction closest = IPlacementHelper.orderedByDistanceExceptAxis(pos, ray.getHitVec(), state.get(AXIS))
.get(0);
@ -227,14 +217,6 @@ public class CogwheelBlockItem extends BlockItem {
return PlacementOffset.fail();
}
@Override
public void renderAt(BlockPos pos, BlockState state, BlockRayTraceResult ray, PlacementOffset offset) {
//IPlacementHelper.renderArrow(VecHelper.getCenterOf(pos), VecHelper.getCenterOf(offset.getPos()),
// Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, state.get(AXIS)), 1D);
displayGhost(offset);
}
protected boolean hitOnShaft(BlockState state, BlockRayTraceResult ray) {
return AllShapes.SIX_VOXEL_POLE.get(state.get(AXIS))
.getBoundingBox()
@ -284,7 +266,7 @@ public class CogwheelBlockItem extends BlockItem {
}
@Override
public PlacementOffset getOffset(World world, BlockState state, BlockPos pos, BlockRayTraceResult ray) {
public PlacementOffset getOffset(PlayerEntity player, World world, BlockState state, BlockPos pos, BlockRayTraceResult ray) {
Direction face = ray.getFace();
Axis newAxis;
@ -321,15 +303,5 @@ public class CogwheelBlockItem extends BlockItem {
return PlacementOffset.fail();
}
@Override
public void renderAt(BlockPos pos, BlockState state, BlockRayTraceResult ray, PlacementOffset offset) {
//IPlacementHelper.renderArrow(VecHelper.getCenterOf(pos), VecHelper.getCenterOf(offset.getPos()),
// Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, offset.getTransform()
// .apply(AllBlocks.LARGE_COGWHEEL.getDefaultState())
// .get(AXIS)));
displayGhost(offset);
}
}
}

View file

@ -1,7 +1,5 @@
package com.simibubi.create.content.contraptions.relays.elementary;
import java.util.function.Predicate;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllShapes;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
@ -10,7 +8,6 @@ import com.simibubi.create.foundation.advancement.AllTriggers;
import com.simibubi.create.foundation.utility.placement.IPlacementHelper;
import com.simibubi.create.foundation.utility.placement.PlacementHelpers;
import com.simibubi.create.foundation.utility.placement.util.PoleHelper;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
@ -26,6 +23,8 @@ import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import java.util.function.Predicate;
public class ShaftBlock extends AbstractShaftBlock {
private static final int placementHelperId = PlacementHelpers.register(new PlacementHelper());
@ -78,7 +77,7 @@ public class ShaftBlock extends AbstractShaftBlock {
IPlacementHelper helper = PlacementHelpers.get(placementHelperId);
if (helper.matchesItem(heldItem))
return helper.getOffset(world, state, pos, ray).placeInWorld(world, (BlockItem) heldItem.getItem(), player, hand, ray);
return helper.getOffset(player, world, state, pos, ray).placeInWorld(world, (BlockItem) heldItem.getItem(), player, hand, ray);
return ActionResultType.PASS;
}

View file

@ -1,14 +1,11 @@
package com.simibubi.create.content.curiosities.tools;
import java.util.UUID;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.simibubi.create.AllItems;
import com.simibubi.create.foundation.advancement.AllTriggers;
import com.simibubi.create.foundation.networking.AllPackets;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.entity.Entity;
@ -36,24 +33,25 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import java.util.UUID;
@EventBusSubscriber
public class ExtendoGripItem extends Item {
public static final AttributeModifier singleRangeAttributeModifier = new AttributeModifier(UUID.fromString("7f7dbdb2-0d0d-458a-aa40-ac7633691f66"), "Range modifier", 3, AttributeModifier.Operation.ADDITION);
public static final AttributeModifier doubleRangeAttributeModifier = new AttributeModifier(UUID.fromString("8f7dbdb2-0d0d-458a-aa40-ac7633691f66"), "Range modifier", 5, AttributeModifier.Operation.ADDITION);
static Multimap<String, AttributeModifier> rangeModifier;
static Multimap<String, AttributeModifier> doubleRangeModifier;
static {
// Holding an ExtendoGrip
rangeModifier = HashMultimap.create();
rangeModifier.put(PlayerEntity.REACH_DISTANCE.getName(),
new AttributeModifier(UUID.fromString("7f7dbdb2-0d0d-458a-aa40-ac7633691f66"), "Range modifier", 3,
AttributeModifier.Operation.ADDITION));
rangeModifier.put(PlayerEntity.REACH_DISTANCE.getName(), singleRangeAttributeModifier);
// Holding two ExtendoGrips o.O
doubleRangeModifier = HashMultimap.create();
doubleRangeModifier.put(PlayerEntity.REACH_DISTANCE.getName(),
new AttributeModifier(UUID.fromString("8f7dbdb2-0d0d-458a-aa40-ac7633691f66"), "Range modifier", 5,
AttributeModifier.Operation.ADDITION));
doubleRangeModifier.put(PlayerEntity.REACH_DISTANCE.getName(), doubleRangeAttributeModifier);
}
public ExtendoGripItem(Properties properties) {

View file

@ -3,6 +3,7 @@ package com.simibubi.create.foundation.config;
public class CCuriosities extends ConfigBase {
public ConfigInt maxSymmetryWandRange = i(50, 10, "maxSymmetryWandRange", Comments.symmetryRange);
public ConfigInt placementAssistRange = i(12, 3, "placementAssistRange", Comments.placementRange);
// public ConfigInt zapperUndoLogLength = i(10, 0, "zapperUndoLogLength", Comments.zapperUndoLogLength); NYI
@Override
@ -12,6 +13,7 @@ public class CCuriosities extends ConfigBase {
private static class Comments {
static String symmetryRange = "The Maximum Distance to an active mirror for the symmetry wand to trigger.";
static String placementRange = "The Maximum Distance a Block placed by Create's placement assist will have to its interaction point.";
// static String zapperUndoLogLength = "The maximum amount of operations, a blockzapper can remember for undoing. (0 to disable undo)";
}

View file

@ -1,19 +1,13 @@
package com.simibubi.create.foundation.utility.placement;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import com.simibubi.create.CreateClient;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.Pair;
import com.simibubi.create.foundation.utility.VecHelper;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
@ -22,6 +16,12 @@ import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@MethodsReturnNonnullByDefault
public interface IPlacementHelper {
@ -46,11 +46,11 @@ public interface IPlacementHelper {
* @return PlacementOffset.fail() if no valid offset could be found.
* PlacementOffset.success(newPos) with newPos being the new position the block should be placed at
*/
PlacementOffset getOffset(World world, BlockState state, BlockPos pos, BlockRayTraceResult ray);
PlacementOffset getOffset(PlayerEntity player, World world, BlockState state, BlockPos pos, BlockRayTraceResult ray);
//overrides the default ghost state of the helper with the actual state of the held block item, this is used in PlacementHelpers and can be ignored in most cases
default PlacementOffset getOffset(World world, BlockState state, BlockPos pos, BlockRayTraceResult ray, ItemStack heldItem) {
PlacementOffset offset = getOffset(world, state, pos, ray);
//sets the offset's ghost state with the default state of the held block item, this is used in PlacementHelpers and can be ignored in most cases
default PlacementOffset getOffset(PlayerEntity player, World world, BlockState state, BlockPos pos, BlockRayTraceResult ray, ItemStack heldItem) {
PlacementOffset offset = getOffset(player, world, state, pos, ray);
if (heldItem.getItem() instanceof BlockItem) {
BlockItem blockItem = (BlockItem) heldItem.getItem();
offset = offset.withGhostState(blockItem.getBlock().getDefaultState());
@ -60,11 +60,10 @@ public interface IPlacementHelper {
//only gets called when placementOffset is successful
default void renderAt(BlockPos pos, BlockState state, BlockRayTraceResult ray, PlacementOffset offset) {
//IPlacementHelper.renderArrow(VecHelper.getCenterOf(pos), VecHelper.getCenterOf(offset.getPos()), ray.getFace());
displayGhost(offset);
}
//RIP
static void renderArrow(Vec3d center, Vec3d target, Direction arrowPlane) {
renderArrow(center, target, arrowPlane, 1D);
}

View file

@ -1,11 +1,5 @@
package com.simibubi.create.foundation.utility.placement;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.lwjgl.opengl.GL11;
import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.gui.AllGuiTextures;
@ -13,7 +7,6 @@ import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingAngle;
import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingValue;
import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.VecHelper;
import net.minecraft.block.BlockState;
import net.minecraft.client.MainWindow;
import net.minecraft.client.Minecraft;
@ -32,6 +25,11 @@ import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Mod.EventBusSubscriber
public class PlacementHelpers {
@ -106,7 +104,7 @@ public class PlacementHelpers {
boolean atLeastOneMatch = false;
for (IPlacementHelper h : filteredForState) {
PlacementOffset offset = h.getOffset(world, state, pos, ray, heldItem);
PlacementOffset offset = h.getOffset(mc.player, world, state, pos, ray, heldItem);
if (offset.isSuccessful()) {
h.renderAt(pos, state, ray, offset);

View file

@ -1,20 +1,23 @@
package com.simibubi.create.foundation.utility.placement.util;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import com.simibubi.create.content.curiosities.tools.ExtendoGripItem;
import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.utility.placement.IPlacementHelper;
import com.simibubi.create.foundation.utility.placement.PlacementOffset;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.block.BlockState;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.state.IProperty;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.World;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
@MethodsReturnNonnullByDefault
public abstract class PoleHelper<T extends Comparable<T>> implements IPlacementHelper {
@ -53,10 +56,19 @@ public abstract class PoleHelper<T extends Comparable<T>> implements IPlacementH
}
@Override
public PlacementOffset getOffset(World world, BlockState state, BlockPos pos, BlockRayTraceResult ray) {
public PlacementOffset getOffset(PlayerEntity player, World world, BlockState state, BlockPos pos, BlockRayTraceResult ray) {
List<Direction> directions = IPlacementHelper.orderedByDistance(pos, ray.getHitVec(), dir -> dir.getAxis() == axisFunction.apply(state));
for (Direction dir : directions) {
int range = AllConfigs.SERVER.curiosities.placementAssistRange.get();
if (player != null) {
IAttributeInstance reach = player.getAttribute(PlayerEntity.REACH_DISTANCE);
if (reach.hasModifier(ExtendoGripItem.singleRangeAttributeModifier))
range += 4;
}
int poles = attachedPoles(world, pos, dir);
if (poles >= range)
continue;
BlockPos newPos = pos.offset(dir, poles + 1);
BlockState newState = world.getBlockState(newPos);
@ -67,12 +79,4 @@ public abstract class PoleHelper<T extends Comparable<T>> implements IPlacementH
return PlacementOffset.fail();
}
@Override
public void renderAt(BlockPos pos, BlockState state, BlockRayTraceResult ray, PlacementOffset offset) {
//Vec3d centerOffset = new Vec3d(ray.getFace().getDirectionVec()).scale(.3);
//IPlacementHelper.renderArrow(VecHelper.getCenterOf(pos).add(centerOffset), VecHelper.getCenterOf(offset.getPos()).add(centerOffset), ray.getFace(), 0.75D);
displayGhost(offset);
}
}