Search in sources :

Example 1 with DoorBlock

use of net.minecraft.block.DoorBlock in project Arclight by IzzelAliz.

the class InteractWithDoorTaskMixin method func_220434_a.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
private void func_220434_a(ServerWorld serverWorld, List<BlockPos> blockPosList, Set<BlockPos> blockPosSet, int i, LivingEntity livingEntity, Brain<?> brain) {
    blockPosSet.forEach((blockPos) -> {
        int j = blockPosList.indexOf(blockPos);
        BlockState blockstate = serverWorld.getBlockState(blockPos);
        Block block = blockstate.getBlock();
        if (BlockTags.WOODEN_DOORS.contains(block) && block instanceof DoorBlock) {
            boolean flag = j >= i;
            // CraftBukkit start - entities opening doors
            EntityInteractEvent event = new EntityInteractEvent(((LivingEntityBridge) livingEntity).bridge$getBukkitEntity(), CraftBlock.at(livingEntity.world, blockPos));
            Bukkit.getPluginManager().callEvent(event);
            if (event.isCancelled()) {
                return;
            }
            // CaftBukkit end
            ((DoorBlock) block).toggleDoor(serverWorld, blockPos, flag);
            GlobalPos globalpos = GlobalPos.of(serverWorld.getDimension().getType(), blockPos);
            if (!brain.getMemory(MemoryModuleType.field_225462_q).isPresent() && flag) {
                brain.setMemory(MemoryModuleType.field_225462_q, Sets.newHashSet(globalpos));
            } else {
                brain.getMemory(MemoryModuleType.field_225462_q).ifPresent((globalPosSet) -> {
                    if (flag) {
                        globalPosSet.add(globalpos);
                    } else {
                        globalPosSet.remove(globalpos);
                    }
                });
            }
        }
    });
    InteractWithDoorTask.func_225449_a(serverWorld, blockPosList, i, livingEntity, brain);
}
Also used : GlobalPos(net.minecraft.util.math.GlobalPos) BlockState(net.minecraft.block.BlockState) DoorBlock(net.minecraft.block.DoorBlock) Block(net.minecraft.block.Block) CraftBlock(org.bukkit.craftbukkit.v.block.CraftBlock) EntityInteractEvent(org.bukkit.event.entity.EntityInteractEvent) DoorBlock(net.minecraft.block.DoorBlock) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with DoorBlock

use of net.minecraft.block.DoorBlock in project Arclight by IzzelAliz.

the class PlayerInteractionManagerMixin_1_15 method func_219441_a.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public ActionResultType func_219441_a(PlayerEntity playerIn, World worldIn, ItemStack stackIn, Hand handIn, BlockRayTraceResult blockRaytraceResultIn) {
    BlockPos blockpos = blockRaytraceResultIn.getPos();
    BlockState blockstate = worldIn.getBlockState(blockpos);
    ActionResultType resultType = ActionResultType.PASS;
    boolean cancelledBlock = false;
    if (this.gameType == GameType.SPECTATOR) {
        INamedContainerProvider provider = blockstate.getContainer(worldIn, blockpos);
        cancelledBlock = !(provider instanceof INamedContainerProvider);
    }
    if (playerIn.getCooldownTracker().hasCooldown(stackIn.getItem())) {
        cancelledBlock = true;
    }
    PlayerInteractEvent bukkitEvent = CraftEventFactory.callPlayerInteractEvent(playerIn, Action.RIGHT_CLICK_BLOCK, blockpos, blockRaytraceResultIn.getFace(), stackIn, cancelledBlock, handIn);
    bridge$setFiredInteract(true);
    bridge$setInteractResult(bukkitEvent.useItemInHand() == Event.Result.DENY);
    if (bukkitEvent.useInteractedBlock() == Event.Result.DENY) {
        if (blockstate.getBlock() instanceof DoorBlock) {
            boolean bottom = blockstate.get(DoorBlock.HALF) == DoubleBlockHalf.LOWER;
            ((ServerPlayerEntity) playerIn).connection.sendPacket(new SChangeBlockPacket(this.world, bottom ? blockpos.up() : blockpos.down()));
        } else if (blockstate.getBlock() instanceof CakeBlock) {
            ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().sendHealthUpdate();
        }
        ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory();
        resultType = ((bukkitEvent.useItemInHand() != Event.Result.ALLOW) ? ActionResultType.SUCCESS : ActionResultType.PASS);
    } else if (this.gameType == GameType.SPECTATOR) {
        INamedContainerProvider inamedcontainerprovider = blockstate.getContainer(worldIn, blockpos);
        if (inamedcontainerprovider != null) {
            playerIn.openContainer(inamedcontainerprovider);
            return ActionResultType.SUCCESS;
        } else {
            return ActionResultType.PASS;
        }
    } else {
        net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(playerIn, handIn, blockpos, blockRaytraceResultIn.getFace());
        if (event.isCanceled())
            return event.getCancellationResult();
        ItemUseContext itemusecontext = new ItemUseContext(playerIn, handIn, blockRaytraceResultIn);
        if (event.getUseItem() != net.minecraftforge.eventbus.api.Event.Result.DENY) {
            ActionResultType result = stackIn.onItemUseFirst(itemusecontext);
            if (result != ActionResultType.PASS)
                return result;
        }
        boolean flag = !playerIn.getHeldItemMainhand().isEmpty() || !playerIn.getHeldItemOffhand().isEmpty();
        boolean flag1 = (playerIn.isSecondaryUseActive() && flag) && !(playerIn.getHeldItemMainhand().doesSneakBypassUse(worldIn, blockpos, playerIn) && playerIn.getHeldItemOffhand().doesSneakBypassUse(worldIn, blockpos, playerIn));
        if (event.getUseBlock() != net.minecraftforge.eventbus.api.Event.Result.DENY && !flag1) {
            resultType = blockstate.onBlockActivated(worldIn, playerIn, handIn, blockRaytraceResultIn);
            if (resultType.isSuccessOrConsume()) {
                return resultType;
            }
        }
        if (!stackIn.isEmpty() && resultType != ActionResultType.SUCCESS && !bridge$getInteractResult()) {
            if (event.getUseItem() == net.minecraftforge.eventbus.api.Event.Result.DENY) {
                return ActionResultType.PASS;
            }
            if (this.isCreative()) {
                int i = stackIn.getCount();
                resultType = stackIn.onItemUse(itemusecontext);
                stackIn.setCount(i);
                return resultType;
            } else {
                return stackIn.onItemUse(itemusecontext);
            }
        } else {
            return resultType;
        }
    }
    return resultType;
}
Also used : ItemUseContext(net.minecraft.item.ItemUseContext) ActionResultType(net.minecraft.util.ActionResultType) SChangeBlockPacket(net.minecraft.network.play.server.SChangeBlockPacket) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) CakeBlock(net.minecraft.block.CakeBlock) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) DoorBlock(net.minecraft.block.DoorBlock) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 3 with DoorBlock

use of net.minecraft.block.DoorBlock in project MCMOD-Industria by M-Marvin.

the class Events method onBlockBurn.

@SubscribeEvent
public static void onBlockBurn(net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent event) {
    BlockState state = event.getState();
    if (state.getBlock() == Blocks.FIRE || state.getBlock() == Blocks.SOUL_FIRE) {
        BlockPos pos = event.getPos();
        BooleanProperty[] fireStates = new BooleanProperty[] { null, FireBlock.UP, FireBlock.NORTH, FireBlock.SOUTH, FireBlock.WEST, FireBlock.EAST };
        for (Direction d : Direction.values()) {
            BooleanProperty fireProp = fireStates[d.get3DDataValue()];
            if (fireProp != null ? state.getValue(fireProp) : true) {
                BlockPos fireCatchingBlockPos = pos.relative(d);
                BlockState fireCatchingBlockState = event.getWorld().getBlockState(fireCatchingBlockPos);
                if (!fireCatchingBlockState.isFlammable(event.getWorld(), fireCatchingBlockPos, d.getOpposite()))
                    return;
                if (fireCatchingBlockState.getBlock() instanceof DoorBlock) {
                    boolean otherLower = fireCatchingBlockState.getValue(BlockStateProperties.DOUBLE_BLOCK_HALF) == DoubleBlockHalf.LOWER;
                    BlockPos otherHalf = otherLower ? fireCatchingBlockPos.above() : fireCatchingBlockPos.below();
                    BlockState otherState = event.getWorld().getBlockState(otherHalf);
                    BlockState[] burnedStates = BlockBurnManager.getBurnedVariants(new BlockState[] { fireCatchingBlockState, otherState }, event.getWorld(), fireCatchingBlockPos);
                    if (fireCatchingBlockState != burnedStates[0]) {
                        event.getWorld().setBlock(!otherLower ? otherHalf : fireCatchingBlockPos, Blocks.AIR.defaultBlockState(), 0);
                        event.getWorld().setBlock(otherLower ? otherHalf : fireCatchingBlockPos, Blocks.AIR.defaultBlockState(), 0);
                        event.getWorld().setBlock(fireCatchingBlockPos, burnedStates[0], 2);
                        event.getWorld().setBlock(otherHalf, burnedStates[1], 2);
                    }
                } else {
                    BlockState burnedBlockState = BlockBurnManager.getBurnedVariant(fireCatchingBlockState, event.getWorld(), fireCatchingBlockPos);
                    if (fireCatchingBlockState != burnedBlockState) {
                        event.getWorld().setBlock(fireCatchingBlockPos, burnedBlockState, 3);
                    }
                }
            }
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) BooleanProperty(net.minecraft.state.BooleanProperty) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction) DoorBlock(net.minecraft.block.DoorBlock) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 4 with DoorBlock

use of net.minecraft.block.DoorBlock in project ChocolateQuestRepoured by TeamChocoQuest.

the class PathNavigateGroundCQR method getPathFinder.

@Override
protected PathFinder getPathFinder() {
    this.nodeProcessor = new WalkNodeProcessor() {

        @Override
        public PathNodeType getPathNodeType(IBlockAccess p_193577_1_, int x, int y, int z, int xSize, int ySize, int zSize, boolean canOpenDoorsIn, boolean canEnterDoorsIn, EnumSet<PathNodeType> p_193577_10_, PathNodeType p_193577_11_, BlockPos p_193577_12_) {
            for (int i = 0; i < xSize; ++i) {
                for (int j = 0; j < ySize; ++j) {
                    for (int k = 0; k < zSize; ++k) {
                        int l = i + x;
                        int i1 = j + y;
                        int j1 = k + z;
                        PathNodeType pathnodetype = this.getPathNodeType(p_193577_1_, l, i1, j1);
                        if (pathnodetype == PathNodeType.DOOR_WOOD_CLOSED && canOpenDoorsIn && canEnterDoorsIn) {
                            pathnodetype = PathNodeType.WALKABLE;
                        }
                        // TODO better method for calculating the facing from which the door will be entered
                        if (pathnodetype == PathNodeType.DOOR_IRON_CLOSED && canOpenDoorsIn && canEnterDoorsIn && EntityAIOpenCloseDoor.canMoveThroughDoor(p_193577_1_, new BlockPos(l, i1, j1), Direction.getFacingFromVector(l - p_193577_12_.getX(), i1 - p_193577_12_.getY(), j1 - p_193577_12_.getZ()).getOpposite(), true)) {
                            pathnodetype = PathNodeType.WALKABLE;
                        }
                        if (pathnodetype == PathNodeType.DOOR_OPEN && !canEnterDoorsIn) {
                            pathnodetype = PathNodeType.BLOCKED;
                        }
                        if (pathnodetype == PathNodeType.RAIL && !(p_193577_1_.getBlockState(p_193577_12_).getBlock() instanceof AbstractRailBlock) && !(p_193577_1_.getBlockState(p_193577_12_.down()).getBlock() instanceof AbstractRailBlock)) {
                            pathnodetype = PathNodeType.FENCE;
                        }
                        if (i == 0 && j == 0 && k == 0) {
                            p_193577_11_ = pathnodetype;
                        }
                        p_193577_10_.add(pathnodetype);
                    }
                }
            }
            return p_193577_11_;
        }

        @Override
        protected PathNodeType getPathNodeTypeRaw(IBlockAccess p_189553_1_, int p_189553_2_, int p_189553_3_, int p_189553_4_) {
            BlockPos blockpos = new BlockPos(p_189553_2_, p_189553_3_, p_189553_4_);
            BlockState iblockstate = p_189553_1_.getBlockState(blockpos);
            Block block = iblockstate.getBlock();
            Material material = iblockstate.getMaterial();
            PathNodeType type = block.getAiPathNodeType(iblockstate, p_189553_1_, blockpos, this.currentEntity);
            if (type != null) {
                return type;
            }
            if (material == Material.AIR) {
                return PathNodeType.OPEN;
            } else if (block != Blocks.TRAPDOOR && block != Blocks.IRON_TRAPDOOR && block != Blocks.WATERLILY) {
                if (block == Blocks.FIRE) {
                    return PathNodeType.DAMAGE_FIRE;
                } else if (block == Blocks.CACTUS) {
                    return PathNodeType.DAMAGE_CACTUS;
                } else if (block instanceof DoorBlock && material == Material.WOOD && !iblockstate.getActualState(p_189553_1_, blockpos).getValue(DoorBlock.OPEN)) {
                    return PathNodeType.DOOR_WOOD_CLOSED;
                } else if (block instanceof DoorBlock && material == Material.IRON && !iblockstate.getActualState(p_189553_1_, blockpos).getValue(DoorBlock.OPEN)) {
                    return PathNodeType.DOOR_IRON_CLOSED;
                } else if (block instanceof DoorBlock && iblockstate.getActualState(p_189553_1_, blockpos).getValue(DoorBlock.OPEN)) {
                    return PathNodeType.DOOR_OPEN;
                } else if (block instanceof AbstractRailBlock) {
                    return PathNodeType.RAIL;
                } else if (!(block instanceof FenceBlock) && !(block instanceof WallBlock) && (!(block instanceof FenceGateBlock) || iblockstate.getValue(FenceGateBlock.OPEN).booleanValue())) {
                    if (material == Material.WATER) {
                        return PathNodeType.WATER;
                    } else if (material == Material.LAVA) {
                        return PathNodeType.LAVA;
                    } else {
                        return block.isPassable(p_189553_1_, blockpos) ? PathNodeType.OPEN : PathNodeType.BLOCKED;
                    }
                } else {
                    return PathNodeType.FENCE;
                }
            } else {
                return PathNodeType.TRAPDOOR;
            }
        }
    };
    this.nodeProcessor.setCanEnterDoors(true);
    this.pathFinder = new PathFinder(this.nodeProcessor);
    return this.pathFinder;
}
Also used : IBlockAccess(net.minecraft.world.IBlockAccess) PathNodeType(net.minecraft.pathfinding.PathNodeType) Material(net.minecraft.block.material.Material) PathFinder(net.minecraft.pathfinding.PathFinder) AbstractRailBlock(net.minecraft.block.AbstractRailBlock) PathPoint(net.minecraft.pathfinding.PathPoint) WalkNodeProcessor(net.minecraft.pathfinding.WalkNodeProcessor) FenceBlock(net.minecraft.block.FenceBlock) BlockState(net.minecraft.block.BlockState) WallBlock(net.minecraft.block.WallBlock) DoorBlock(net.minecraft.block.DoorBlock) AbstractRailBlock(net.minecraft.block.AbstractRailBlock) FenceBlock(net.minecraft.block.FenceBlock) WallBlock(net.minecraft.block.WallBlock) BlockPos(net.minecraft.util.math.BlockPos) DoorBlock(net.minecraft.block.DoorBlock)

Example 5 with DoorBlock

use of net.minecraft.block.DoorBlock in project ChocolateQuestRepoured by TeamChocoQuest.

the class EntityAIOpenCloseDoor method closeDoor.

private boolean closeDoor() {
    BlockState state = this.world.getBlockState(this.doorPos);
    if (!(state.getBlock() instanceof DoorBlock)) {
        return false;
    }
    if (state.getMaterial() != Material.WOOD) {
        return false;
    }
    boolean shouldCloseDoor = true;
    double x = this.entity.posX;
    double y = this.entity.posY;
    double z = this.entity.posZ;
    double r = 4.0D;
    AxisAlignedBB aabb = new AxisAlignedBB(x - r, y - r * 0.5D, z - r, x + r, y + r * 0.5D, z + r);
    List<AbstractEntityCQR> allies = this.world.getEntitiesWithinAABB(AbstractEntityCQR.class, aabb, e -> TargetUtil.isAllyCheckingLeaders(this.entity, e));
    for (AbstractEntityCQR ally : allies) {
        if (ally == this.entity) {
            continue;
        }
        if (!ally.hasPath()) {
            continue;
        }
        if (ally.getDistanceSq(this.entity) >= r * r) {
            continue;
        }
        if (MathHelper.floor(ally.posX) == this.doorPos.getX() && MathHelper.floor(ally.posY) == this.doorPos.getY() && MathHelper.floor(ally.posZ) == this.doorPos.getZ()) {
            shouldCloseDoor = false;
            break;
        }
        Path path = ally.getNavigation().getPath();
        int end = Math.min(path.getCurrentPathIndex() + 2, path.getCurrentPathLength());
        for (int i = path.getCurrentPathIndex(); i < end; i++) {
            PathPoint pathPoint = path.getPathPointFromIndex(i);
            if (pathPoint.x == this.doorPos.getX() && pathPoint.y == this.doorPos.getY() && pathPoint.z == this.doorPos.getZ()) {
                shouldCloseDoor = false;
                break;
            }
        }
    }
    if (shouldCloseDoor) {
        this.doorBlock.toggleDoor(this.world, this.doorPos, false);
        return true;
    }
    return false;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Path(net.minecraft.pathfinding.Path) PathPoint(net.minecraft.pathfinding.PathPoint) BlockState(net.minecraft.block.BlockState) AbstractEntityCQR(team.cqr.cqrepoured.entity.bases.AbstractEntityCQR) PathPoint(net.minecraft.pathfinding.PathPoint) DoorBlock(net.minecraft.block.DoorBlock)

Aggregations

BlockState (net.minecraft.block.BlockState)13 DoorBlock (net.minecraft.block.DoorBlock)13 BlockPos (net.minecraft.util.math.BlockPos)9 Direction (net.minecraft.util.Direction)6 FenceBlock (net.minecraft.block.FenceBlock)4 TrapDoorBlock (net.minecraft.block.TrapDoorBlock)4 Overwrite (org.spongepowered.asm.mixin.Overwrite)4 SChangeBlockPacket (net.minecraft.network.play.server.SChangeBlockPacket)3 PathPoint (net.minecraft.pathfinding.PathPoint)3 PlayerInteractEvent (org.bukkit.event.player.PlayerInteractEvent)3 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)2 CakeBlock (net.minecraft.block.CakeBlock)2 INamedContainerProvider (net.minecraft.inventory.container.INamedContainerProvider)2 ItemUseContext (net.minecraft.item.ItemUseContext)2 Path (net.minecraft.pathfinding.Path)2 ActionResultType (net.minecraft.util.ActionResultType)2 AbstractRailBlock (net.minecraft.block.AbstractRailBlock)1 Block (net.minecraft.block.Block)1 WallBlock (net.minecraft.block.WallBlock)1 Material (net.minecraft.block.material.Material)1