类net.minecraft.world.WorldAccess源码实例Demo

下面列出了怎么用net.minecraft.world.WorldAccess的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Galacticraft-Rewoven   文件: StandardWrenchItem.java
private void use(PlayerEntity player, BlockState state, WorldAccess iWorld, BlockPos pos, ItemStack stack) {
    Block block = state.getBlock();
    if (block instanceof Rotatable) {
        StateManager<Block, BlockState> manager = block.getStateManager();
        Collection<Property<?>> collection = manager.getProperties();
        String string_1 = Registry.BLOCK.getId(block).toString();
        if (!collection.isEmpty()) {
            CompoundTag compoundTag_1 = stack.getOrCreateSubTag("wrenchProp");
            String string_2 = compoundTag_1.getString(string_1);
            Property<?> property = manager.getProperty(string_2);
            if (property == null) {
                property = collection.iterator().next();
            }
            if (property.getName().equals("facing")) {
                BlockState blockState_2 = cycle(state, property, player.isSneaking());
                iWorld.setBlockState(pos, blockState_2, 18);
                stack.damage(2, player, (playerEntity) -> playerEntity.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND));
            }
        }
    }
}
 
@Nonnull
@Override
public WireConnectionType canWireConnect(WorldAccess world, Direction opposite, BlockPos connectionSourcePos, BlockPos connectionTargetPos) {
    BlockState state = world.getBlockState(connectionTargetPos);

    SideOption option = getOption(state, BlockFace.toFace(state.get(FACING), opposite));

    if (option == SideOption.POWER_INPUT) {
        return WireConnectionType.ENERGY_INPUT;
    } else if (option == SideOption.POWER_OUTPUT) {
        return WireConnectionType.ENERGY_OUTPUT;
    }

    return WireConnectionType.NONE;
}
 
源代码3 项目: Galacticraft-Rewoven   文件: FluidLoggableBlock.java
@Override
default boolean tryFillWithFluid(WorldAccess world, BlockPos pos, BlockState state, FluidState fluidState) {
    if (state.get(FLUID).equals(new Identifier("empty"))) {
        if (!world.isClient()) {
            world.setBlockState(pos, state.with(FLUID, Registry.FLUID.getId(fluidState.getFluid()))
                    .with(FlowableFluid.LEVEL, Math.max(fluidState.getLevel(), 1)), 3);
            world.getFluidTickScheduler().schedule(pos, fluidState.getFluid(), fluidState.getFluid().getTickRate(world));
        }
        return true;
    } else {
        return false;
    }
}
 
源代码4 项目: Galacticraft-Rewoven   文件: FluidLoggableBlock.java
@Override
default Fluid tryDrainFluid(WorldAccess world, BlockPos pos, BlockState state) {
    if (!state.get(FLUID).equals(new Identifier("empty"))) {
        world.setBlockState(pos, state.with(FLUID, new Identifier("empty")), 3);
        if (Registry.FLUID.get(state.get(FLUID)).getDefaultState().isStill()) {
            return Registry.FLUID.get(state.get(FLUID));
        }
    }
    return Fluids.EMPTY;
}
 
源代码5 项目: Galacticraft-Rewoven   文件: WireBlock.java
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction dir, BlockState otherState, WorldAccess world, BlockPos pos, BlockPos updated) {
    WireConnectionType type = WireConnectionType.NONE;
    if (otherState.getBlock() instanceof WireConnectable) {
        type = ((WireConnectable) otherState.getBlock()).canWireConnect(world, dir.getOpposite(), pos, updated);
    }

    if (!world.isClient() && type != WireConnectionType.NONE) {
        if (world.getBlockState(updated).getBlock() instanceof WireConnectable) {
            WireNetwork network = ((ServerWorldAccessor) world).getNetworkManager().getNetwork(pos);
            if (network == null) network = new WireNetwork(pos, ((ServerWorld) world));
            if (type == WireConnectionType.WIRE) {
                WireNetwork network1 = ((ServerWorldAccessor) world).getNetworkManager().getNetwork(updated);
                if (network1 != network) {
                    if (network1 != null) {
                        network1.merge(network); // prefer other network rather than this one
                    } else {
                        network.addWire(updated);
                    }
                    state.method_30101(world, pos, 3);
                }
            } else if (type == WireConnectionType.ENERGY_INPUT) {
                network.addConsumer(updated);
            } else {
                network.addProducer(updated);
            }

        }
    }
    return state;
}
 
源代码6 项目: Galacticraft-Rewoven   文件: CavernousVineBlock.java
@Override
public BlockState getStateForNeighborUpdate(BlockState blockState, Direction direction, BlockState neighborBlockState, WorldAccess world, BlockPos blockPos, BlockPos neighborBlockPos) {
    if (blockState.get(WATERLOGGED)) {
        world.getFluidTickScheduler().schedule(blockPos, Fluids.WATER, Fluids.WATER.getTickRate(world));
    }

    return super.getStateForNeighborUpdate(blockState, direction, neighborBlockState, world, blockPos, neighborBlockPos);
}
 
源代码7 项目: Galacticraft-Rewoven   文件: GratingBlock.java
@Override
public BlockState getStateForNeighborUpdate(BlockState blockState, Direction direction, BlockState neighborBlockState, WorldAccess world, BlockPos blockPos, BlockPos neighborBlockPos) {
    if (!blockState.get(FLUID).equals(new Identifier("empty"))) {
        world.getFluidTickScheduler().schedule(blockPos, Registry.FLUID.get(blockState.get(FLUID)), Registry.FLUID.get(blockState.get(FLUID)).getTickRate(world));
    }

    return super.getStateForNeighborUpdate(blockState, direction, neighborBlockState, world, blockPos, neighborBlockPos);
}
 
源代码8 项目: Galacticraft-Rewoven   文件: FluidPipeBlock.java
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction_1, BlockState blockState_2, WorldAccess world, BlockPos thisWire, BlockPos otherConnectable) {
    return state.with(getPropForDirection(direction_1), (
            !(blockState_2).isAir()
                    && blockState_2.getBlock() instanceof FluidPipeBlock //todo fluid things (network etc.)
    ));
}
 
源代码9 项目: Galacticraft-Rewoven   文件: AluminumWireBlock.java
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction_1, BlockState blockState_2, WorldAccess world, BlockPos thisWire, BlockPos otherConnectable) {
    return state.with(getPropForDirection(direction_1), (
            !(blockState_2).isAir()
                    && blockState_2.getBlock() instanceof WireConnectable
                    // get opposite of direction so the WireConnectable can check from its perspective.
                    && (((WireConnectable) blockState_2.getBlock()).canWireConnect(world, direction_1.getOpposite(), thisWire, otherConnectable) != WireConnectionType.NONE)
    ));
}
 
源代码10 项目: multiconnect   文件: ChunkUpgrader.java
private static void doFix(WorldAccess world, BlockPos pos, int flags) {
    BlockState state = world.getBlockState(pos);
    for (Direction dir : Direction.values()) {
        BlockPos otherPos = pos.offset(dir);
        state = applyAdjacentBlock(state, dir, world, pos, otherPos);
    }
    world.setBlockState(pos, state, flags | 16);

    inPlaceFix(world.getChunk(pos), state, pos, new BlockPos.Mutable());
}
 
源代码11 项目: multiconnect   文件: MixinBlock.java
@Inject(method = "updateNeighbors", at = @At("HEAD"), cancellable = true)
private void onUpdateNeighborStates(WorldAccess world, BlockPos pos, int flags, int limit, CallbackInfo ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2) {
        ChunkUpgrader.fix(world, pos, flags);
        ci.cancel();
    }
}
 
源代码12 项目: Galacticraft-Rewoven   文件: GCOreFeature.java
@SuppressWarnings("PointlessArithmeticExpression")
protected boolean generateVeinPart(WorldAccess world, Random random, GCOreFeatureConfig config, double startX, double endX, double startZ, double endZ, double startY, double endY, int x, int y, int z, int size, int i) {
    int j = 0;
    BitSet bitSet = new BitSet(size * i * size);
    BlockPos.Mutable mutable = new BlockPos.Mutable();
    double[] ds = new double[config.size * 4];

    int m;
    double o;
    double p;
    double q;
    double r;
    for (m = 0; m < config.size; ++m) {
        float f = (float) m / (float) config.size;
        o = MathHelper.lerp(f, startX, endX);
        p = MathHelper.lerp(f, startY, endY);
        q = MathHelper.lerp(f, startZ, endZ);
        r = random.nextDouble() * (double) config.size / 16.0D;
        double l = ((double) (MathHelper.sin(3.1415927F * f) + 1.0F) * r + 1.0D) / 2.0D;
        ds[m * 4 + 0] = o;
        ds[m * 4 + 1] = p;
        ds[m * 4 + 2] = q;
        ds[m * 4 + 3] = l;
    }

    for (m = 0; m < config.size - 1; ++m) {
        if (ds[m * 4 + 3] > 0.0D) {
            for (int n = m + 1; n < config.size; ++n) {
                if (ds[n * 4 + 3] > 0.0D) {
                    o = ds[m * 4 + 0] - ds[n * 4 + 0];
                    p = ds[m * 4 + 1] - ds[n * 4 + 1];
                    q = ds[m * 4 + 2] - ds[n * 4 + 2];
                    r = ds[m * 4 + 3] - ds[n * 4 + 3];
                    if (r * r > o * o + p * p + q * q) {
                        if (r > 0.0D) {
                            ds[n * 4 + 3] = -1.0D;
                        } else {
                            ds[m * 4 + 3] = -1.0D;
                        }
                    }
                }
            }
        }
    }

    for (m = 0; m < config.size; ++m) {
        double t = ds[m * 4 + 3];
        if (t >= 0.0D) {
            double u = ds[m * 4 + 0];
            double v = ds[m * 4 + 1];
            double w = ds[m * 4 + 2];
            int aa = Math.max(MathHelper.floor(u - t), x);
            int ab = Math.max(MathHelper.floor(v - t), y);
            int ac = Math.max(MathHelper.floor(w - t), z);
            int ad = Math.max(MathHelper.floor(u + t), aa);
            int ae = Math.max(MathHelper.floor(v + t), ab);
            int af = Math.max(MathHelper.floor(w + t), ac);

            for (int ag = aa; ag <= ad; ++ag) {
                double ah = ((double) ag + 0.5D - u) / t;
                if (ah * ah < 1.0D) {
                    for (int ai = ab; ai <= ae; ++ai) {
                        double aj = ((double) ai + 0.5D - v) / t;
                        if (ah * ah + aj * aj < 1.0D) {
                            for (int ak = ac; ak <= af; ++ak) {
                                double al = ((double) ak + 0.5D - w) / t;
                                if (ah * ah + aj * aj + al * al < 1.0D) {
                                    int am = ag - x + (ai - y) * size + (ak - z) * size * i;
                                    if (!bitSet.get(am)) {
                                        bitSet.set(am);
                                        mutable.set(ag, ai, ak);
                                        if (config.target.predicate.test(world.getBlockState(mutable))) {
                                            world.setBlockState(mutable, config.state, 2);
                                            ++j;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return j > 0;
}
 
源代码13 项目: Galacticraft-Rewoven   文件: WireBlock.java
@Override
@Nonnull
public WireConnectionType canWireConnect(WorldAccess world, Direction opposite, BlockPos connectionSourcePos, BlockPos connectionTargetPos) {
    return WireConnectionType.WIRE;
}
 
源代码14 项目: Galacticraft-Rewoven   文件: Walkway.java
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
    if (!state.get(FLUID).equals(new Identifier("empty"))) {
        world.getFluidTickScheduler().schedule(pos, Registry.FLUID.get(state.get(FLUID)), Registry.FLUID.get(state.get(FLUID)).getTickRate(world));
    }
    return facing.getAxis().getType() == Direction.Type.HORIZONTAL ? state.with(getPropForDir(facing), this.canConnect(neighborState)) : super.getStateForNeighborUpdate(state, facing, neighborState, world, pos, neighborPos);
}
 
源代码15 项目: Galacticraft-Rewoven   文件: CrudeOilFluid.java
@Override
public void beforeBreakingBlock(WorldAccess iWorld, BlockPos blockPos, BlockState blockState) {
    BlockEntity blockEntity = blockState.getBlock().hasBlockEntity() ? iWorld.getBlockEntity(blockPos) : null;
    Block.dropStacks(blockState, iWorld.getWorld(), blockPos, blockEntity);
}
 
源代码16 项目: Galacticraft-Rewoven   文件: FuelFluid.java
@Override
public void beforeBreakingBlock(WorldAccess iWorld, BlockPos blockPos, BlockState blockState) {
    BlockEntity blockEntity = blockState.getBlock().hasBlockEntity() ? iWorld.getBlockEntity(blockPos) : null;
    Block.dropStacks(blockState, iWorld.getWorld(), blockPos, blockEntity);
}
 
源代码17 项目: Galacticraft-Rewoven   文件: WireConnectable.java
@Nonnull
WireConnectionType canWireConnect(WorldAccess world, Direction opposite, BlockPos connectionSourcePos, BlockPos connectionTargetPos);
 
源代码18 项目: multiconnect   文件: ChunkUpgrader.java
public static void fix(WorldAccess world, BlockPos pos, int flags) {
    doFix(world, pos, flags);
    for (Direction dir : Direction.values())
        doFix(world, pos.offset(dir), flags);
}
 
源代码19 项目: multiconnect   文件: UpgradeDataAccessor.java
@Invoker
static BlockState callApplyAdjacentBlock(BlockState oldState, Direction dir, WorldAccess world, BlockPos currentPos, BlockPos otherPos) {
    return MixinHelper.fakeInstance();
}
 
 类所在包
 类方法
 同包方法