mirror of
				https://github.com/Theta-Dev/ConstructionWand.git
				synced 2025-11-03 20:53:49 +01:00 
			
		
		
		
	Compare commits
	
		
			3 commits
		
	
	
		
			
				489e050a7f
			
			...
			
				ce17d53f4b
			
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| ce17d53f4b | |||
| 2cfc4fe790 | |||
| 1e1847d5a3 | 
					 5 changed files with 38 additions and 35 deletions
				
			
		| 
						 | 
				
			
			@ -11,4 +11,4 @@ mcp_mappings=20200723-1.16.1
 | 
			
		|||
botania=1.16.2-405
 | 
			
		||||
 | 
			
		||||
version_major=2
 | 
			
		||||
version_minor=2
 | 
			
		||||
version_minor=4
 | 
			
		||||
| 
						 | 
				
			
			@ -7,12 +7,9 @@ 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.Item;
 | 
			
		||||
import net.minecraft.item.ItemStack;
 | 
			
		||||
import net.minecraft.state.Property;
 | 
			
		||||
import net.minecraft.state.properties.BlockStateProperties;
 | 
			
		||||
import net.minecraft.state.properties.SlabType;
 | 
			
		||||
import net.minecraft.item.Items;
 | 
			
		||||
import net.minecraft.stats.Stats;
 | 
			
		||||
import net.minecraft.util.Direction;
 | 
			
		||||
import net.minecraft.util.EntityPredicates;
 | 
			
		||||
| 
						 | 
				
			
			@ -208,17 +205,23 @@ public class WandUtil
 | 
			
		|||
 | 
			
		||||
    /**
 | 
			
		||||
     * Tests if a wand can place a block at a certain position.
 | 
			
		||||
     * This check is independent from the used block.
 | 
			
		||||
     * This check is independent of the used block.
 | 
			
		||||
     */
 | 
			
		||||
    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
 | 
			
		||||
        return replace || world.isAirBlock(pos);
 | 
			
		||||
        if(world.isAirBlock(pos)) return true;
 | 
			
		||||
 | 
			
		||||
        // 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) {
 | 
			
		||||
        if(!isPositionModifiable(world,player, pos)) return false;
 | 
			
		||||
        if(!isPositionModifiable(world, player, pos)) return false;
 | 
			
		||||
 | 
			
		||||
        if(!player.isCreative()) {
 | 
			
		||||
            return !(world.getBlockState(pos).getBlockHardness(world, pos) <= -1) && world.getTileEntity(pos) == null;
 | 
			
		||||
| 
						 | 
				
			
			@ -226,6 +229,10 @@ public class WandUtil
 | 
			
		|||
        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) {
 | 
			
		||||
        VoxelShape shape = blockState.getCollisionShape(world, pos);
 | 
			
		||||
        if(!shape.isEmpty()) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,14 +2,13 @@ package thetadev.constructionwand.containers.handlers;
 | 
			
		|||
 | 
			
		||||
import net.minecraft.entity.player.PlayerEntity;
 | 
			
		||||
import net.minecraft.item.ItemStack;
 | 
			
		||||
import net.minecraftforge.common.util.LazyOptional;
 | 
			
		||||
import net.minecraftforge.items.CapabilityItemHandler;
 | 
			
		||||
import net.minecraftforge.items.IItemHandler;
 | 
			
		||||
import thetadev.constructionwand.api.IContainerHandler;
 | 
			
		||||
import thetadev.constructionwand.basics.WandUtil;
 | 
			
		||||
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Created by james on 28/12/16.
 | 
			
		||||
 */
 | 
			
		||||
public class HandlerCapability implements IContainerHandler
 | 
			
		||||
{
 | 
			
		||||
    @Override
 | 
			
		||||
| 
						 | 
				
			
			@ -19,43 +18,35 @@ public class HandlerCapability implements IContainerHandler
 | 
			
		|||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int countItems(PlayerEntity player, ItemStack itemStack, ItemStack inventoryStack) {
 | 
			
		||||
        LazyOptional<IItemHandler> itemHandlerLazyOptional = inventoryStack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
 | 
			
		||||
        if(!itemHandlerLazyOptional.isPresent()) return 0;
 | 
			
		||||
        Optional<IItemHandler> itemHandlerOptional = inventoryStack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).resolve();
 | 
			
		||||
        if(!itemHandlerOptional.isPresent()) return 0;
 | 
			
		||||
 | 
			
		||||
        int total = 0;
 | 
			
		||||
 | 
			
		||||
        IItemHandler itemHandler = itemHandlerLazyOptional.orElse(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.getDefaultInstance());
 | 
			
		||||
        IItemHandler itemHandler = itemHandlerOptional.get();
 | 
			
		||||
 | 
			
		||||
        for(int i = 0; i < itemHandler.getSlots(); i++) {
 | 
			
		||||
            ItemStack containerStack = itemHandler.getStackInSlot(i);
 | 
			
		||||
            if(containerStack != null && itemStack.isItemEqual(containerStack)) {
 | 
			
		||||
            if(WandUtil.stackEquals(itemStack, containerStack)) {
 | 
			
		||||
                total += Math.max(0, containerStack.getCount());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Already in a container. Don't inception this thing.
 | 
			
		||||
        }
 | 
			
		||||
        return total;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int useItems(PlayerEntity player, ItemStack itemStack, ItemStack inventoryStack, int count) {
 | 
			
		||||
        int toUse = itemStack.getCount();
 | 
			
		||||
        Optional<IItemHandler> itemHandlerOptional = inventoryStack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).resolve();
 | 
			
		||||
        if(!itemHandlerOptional.isPresent()) return 0;
 | 
			
		||||
 | 
			
		||||
        LazyOptional<IItemHandler> itemHandlerLazyOptional = inventoryStack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
 | 
			
		||||
        if(!itemHandlerLazyOptional.isPresent()) return 0;
 | 
			
		||||
 | 
			
		||||
        IItemHandler itemHandler = itemHandlerLazyOptional.orElse(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.getDefaultInstance());
 | 
			
		||||
        IItemHandler itemHandler = itemHandlerOptional.get();
 | 
			
		||||
 | 
			
		||||
        for(int i = 0; i < itemHandler.getSlots(); i++) {
 | 
			
		||||
            ItemStack handlerStack = itemHandler.getStackInSlot(i);
 | 
			
		||||
            if(handlerStack != null && handlerStack.isItemEqual(itemStack)) {
 | 
			
		||||
            if(WandUtil.stackEquals(itemStack, handlerStack)) {
 | 
			
		||||
                ItemStack extracted = itemHandler.extractItem(i, count, false);
 | 
			
		||||
                if(extracted != null) {
 | 
			
		||||
                    count -= extracted.getCount();
 | 
			
		||||
                }
 | 
			
		||||
                if(count <= 0) {
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
                count -= extracted.getCount();
 | 
			
		||||
                if(count <= 0) break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return count;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -39,14 +39,14 @@ public class ActionDestruction implements IWandAction
 | 
			
		|||
        HashSet<BlockPos> allCandidates = new HashSet<>();
 | 
			
		||||
 | 
			
		||||
        // Block face the wand was pointed at
 | 
			
		||||
        Direction breakDirection = rayTraceResult.getFace();
 | 
			
		||||
        Direction breakFace = rayTraceResult.getFace();
 | 
			
		||||
        // Block the wand was pointed at
 | 
			
		||||
        BlockPos startingPoint = rayTraceResult.getPos();
 | 
			
		||||
        BlockState targetBlock = world.getBlockState(rayTraceResult.getPos());
 | 
			
		||||
 | 
			
		||||
        // Is break direction allowed by lock?
 | 
			
		||||
        // Tried to break blocks from top/bottom face, so the wand should allow breaking in NS/EW direction
 | 
			
		||||
        if(breakDirection == Direction.UP || breakDirection == Direction.DOWN) {
 | 
			
		||||
        if(breakFace == Direction.UP || breakFace == Direction.DOWN) {
 | 
			
		||||
            if(options.testLock(WandOptions.LOCK.NORTHSOUTH) || options.testLock(WandOptions.LOCK.EASTWEST))
 | 
			
		||||
                candidates.add(startingPoint);
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -57,6 +57,10 @@ public class ActionDestruction implements IWandAction
 | 
			
		|||
        // Process current candidates, stop when none are avaiable or block limit is reached
 | 
			
		||||
        while(!candidates.isEmpty() && destroySnapshots.size() < limit) {
 | 
			
		||||
            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 {
 | 
			
		||||
                BlockState candidateBlock = world.getBlockState(currentCandidate);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -67,7 +71,7 @@ public class ActionDestruction implements IWandAction
 | 
			
		|||
                    if(snapshot == null) continue;
 | 
			
		||||
                    destroySnapshots.add(snapshot);
 | 
			
		||||
 | 
			
		||||
                    switch(breakDirection) {
 | 
			
		||||
                    switch(breakFace) {
 | 
			
		||||
                        case DOWN:
 | 
			
		||||
                        case UP:
 | 
			
		||||
                            if(options.testLock(WandOptions.LOCK.NORTHSOUTH)) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,7 @@ import net.minecraft.entity.player.PlayerEntity;
 | 
			
		|||
import net.minecraft.item.BlockItem;
 | 
			
		||||
import net.minecraft.item.Item;
 | 
			
		||||
import net.minecraft.item.ItemStack;
 | 
			
		||||
import net.minecraft.item.Items;
 | 
			
		||||
import net.minecraft.util.Hand;
 | 
			
		||||
import net.minecraft.util.math.BlockPos;
 | 
			
		||||
import net.minecraft.util.math.BlockRayTraceResult;
 | 
			
		||||
| 
						 | 
				
			
			@ -51,7 +52,7 @@ public class SupplierInventory implements IWandSupplier
 | 
			
		|||
            addBlockItem((BlockItem) offhandStack.getItem());
 | 
			
		||||
        }
 | 
			
		||||
        // Otherwise use target block
 | 
			
		||||
        else {
 | 
			
		||||
        else if(target != null && target != Items.AIR) {
 | 
			
		||||
            addBlockItem(target);
 | 
			
		||||
 | 
			
		||||
            // Add replacement items
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue