mirror of
https://github.com/Theta-Dev/ConstructionWand.git
synced 2024-11-22 22:27:49 +01:00
Compare commits
No commits in common. "cd3a451e5458883aabfb9dffa97a17cf21d92a5d" and "61a570709403c6fc5e59bdfca4de8c0f4581ef50" have entirely different histories.
cd3a451e54
...
61a5707094
4 changed files with 13 additions and 25 deletions
|
@ -11,4 +11,4 @@ mcp_mappings=20200723-1.16.1
|
||||||
botania=1.16-398
|
botania=1.16-398
|
||||||
|
|
||||||
version_major=2
|
version_major=2
|
||||||
version_minor=4
|
version_minor=2
|
|
@ -7,9 +7,12 @@ import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
|
import net.minecraft.item.BlockItemUseContext;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.state.Property;
|
||||||
|
import net.minecraft.state.properties.BlockStateProperties;
|
||||||
|
import net.minecraft.state.properties.SlabType;
|
||||||
import net.minecraft.stats.Stats;
|
import net.minecraft.stats.Stats;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.EntityPredicates;
|
import net.minecraft.util.EntityPredicates;
|
||||||
|
@ -205,23 +208,17 @@ public class WandUtil
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests if a wand can place a block at a certain position.
|
* Tests if a wand can place a block at a certain position.
|
||||||
* This check is independent of the used block.
|
* This check is independent from the used block.
|
||||||
*/
|
*/
|
||||||
public static boolean isPositionPlaceable(World world, PlayerEntity player, BlockPos pos, boolean replace) {
|
public static boolean isPositionPlaceable(World world, PlayerEntity player, BlockPos pos, boolean replace) {
|
||||||
if(!isPositionModifiable(world, player, pos)) return false;
|
if(!isPositionModifiable(world,player, pos)) return false;
|
||||||
|
|
||||||
// If replace mode is off, target has to be air
|
// If replace mode is off, target has to be air
|
||||||
if(world.isAirBlock(pos)) return true;
|
return replace || world.isAirBlock(pos);
|
||||||
|
|
||||||
// Otherwise, check if the block can be replaced by a generic block
|
|
||||||
return replace && world.getBlockState(pos).isReplaceable(
|
|
||||||
new WandItemUseContext(world, player,
|
|
||||||
new BlockRayTraceResult(new Vector3d(0, 0, 0), Direction.DOWN, pos, false),
|
|
||||||
pos, (BlockItem) Items.STONE));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isBlockRemovable(World world, PlayerEntity player, BlockPos pos) {
|
public static boolean isBlockRemovable(World world, PlayerEntity player, BlockPos pos) {
|
||||||
if(!isPositionModifiable(world, player, pos)) return false;
|
if(!isPositionModifiable(world,player, pos)) return false;
|
||||||
|
|
||||||
if(!player.isCreative()) {
|
if(!player.isCreative()) {
|
||||||
return !(world.getBlockState(pos).getBlockHardness(world, pos) <= -1) && world.getTileEntity(pos) == null;
|
return !(world.getBlockState(pos).getBlockHardness(world, pos) <= -1) && world.getTileEntity(pos) == null;
|
||||||
|
@ -229,10 +226,6 @@ public class WandUtil
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isBlockPermeable(World world, BlockPos pos) {
|
|
||||||
return world.isAirBlock(pos) || world.getBlockState(pos).getCollisionShape(world, pos).isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean entitiesCollidingWithBlock(World world, BlockState blockState, BlockPos pos) {
|
public static boolean entitiesCollidingWithBlock(World world, BlockState blockState, BlockPos pos) {
|
||||||
VoxelShape shape = blockState.getCollisionShape(world, pos);
|
VoxelShape shape = blockState.getCollisionShape(world, pos);
|
||||||
if(!shape.isEmpty()) {
|
if(!shape.isEmpty()) {
|
||||||
|
|
|
@ -39,14 +39,14 @@ public class ActionDestruction implements IWandAction
|
||||||
HashSet<BlockPos> allCandidates = new HashSet<>();
|
HashSet<BlockPos> allCandidates = new HashSet<>();
|
||||||
|
|
||||||
// Block face the wand was pointed at
|
// Block face the wand was pointed at
|
||||||
Direction breakFace = rayTraceResult.getFace();
|
Direction breakDirection = rayTraceResult.getFace();
|
||||||
// Block the wand was pointed at
|
// Block the wand was pointed at
|
||||||
BlockPos startingPoint = rayTraceResult.getPos();
|
BlockPos startingPoint = rayTraceResult.getPos();
|
||||||
BlockState targetBlock = world.getBlockState(rayTraceResult.getPos());
|
BlockState targetBlock = world.getBlockState(rayTraceResult.getPos());
|
||||||
|
|
||||||
// Is break direction allowed by lock?
|
// Is break direction allowed by lock?
|
||||||
// Tried to break blocks from top/bottom face, so the wand should allow breaking in NS/EW direction
|
// Tried to break blocks from top/bottom face, so the wand should allow breaking in NS/EW direction
|
||||||
if(breakFace == Direction.UP || breakFace == Direction.DOWN) {
|
if(breakDirection == Direction.UP || breakDirection == Direction.DOWN) {
|
||||||
if(options.testLock(WandOptions.LOCK.NORTHSOUTH) || options.testLock(WandOptions.LOCK.EASTWEST))
|
if(options.testLock(WandOptions.LOCK.NORTHSOUTH) || options.testLock(WandOptions.LOCK.EASTWEST))
|
||||||
candidates.add(startingPoint);
|
candidates.add(startingPoint);
|
||||||
}
|
}
|
||||||
|
@ -57,10 +57,6 @@ public class ActionDestruction implements IWandAction
|
||||||
// Process current candidates, stop when none are avaiable or block limit is reached
|
// Process current candidates, stop when none are avaiable or block limit is reached
|
||||||
while(!candidates.isEmpty() && destroySnapshots.size() < limit) {
|
while(!candidates.isEmpty() && destroySnapshots.size() < limit) {
|
||||||
BlockPos currentCandidate = candidates.removeFirst();
|
BlockPos currentCandidate = candidates.removeFirst();
|
||||||
|
|
||||||
// Only break blocks facing the player, with no collidable blocks in between
|
|
||||||
if(!WandUtil.isBlockPermeable(world, currentCandidate.offset(breakFace))) continue;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
BlockState candidateBlock = world.getBlockState(currentCandidate);
|
BlockState candidateBlock = world.getBlockState(currentCandidate);
|
||||||
|
|
||||||
|
@ -71,7 +67,7 @@ public class ActionDestruction implements IWandAction
|
||||||
if(snapshot == null) continue;
|
if(snapshot == null) continue;
|
||||||
destroySnapshots.add(snapshot);
|
destroySnapshots.add(snapshot);
|
||||||
|
|
||||||
switch(breakFace) {
|
switch(breakDirection) {
|
||||||
case DOWN:
|
case DOWN:
|
||||||
case UP:
|
case UP:
|
||||||
if(options.testLock(WandOptions.LOCK.NORTHSOUTH)) {
|
if(options.testLock(WandOptions.LOCK.NORTHSOUTH)) {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.BlockRayTraceResult;
|
import net.minecraft.util.math.BlockRayTraceResult;
|
||||||
|
@ -52,7 +51,7 @@ public class SupplierInventory implements IWandSupplier
|
||||||
addBlockItem((BlockItem) offhandStack.getItem());
|
addBlockItem((BlockItem) offhandStack.getItem());
|
||||||
}
|
}
|
||||||
// Otherwise use target block
|
// Otherwise use target block
|
||||||
else if(target != null && target != Items.AIR) {
|
else {
|
||||||
addBlockItem(target);
|
addBlockItem(target);
|
||||||
|
|
||||||
// Add replacement items
|
// Add replacement items
|
||||||
|
|
Loading…
Reference in a new issue