net.minecraft.world.WorldAccess Java Examples

The following examples show how to use net.minecraft.world.WorldAccess. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardWrenchItem.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
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));
            }
        }
    }
}
 
Example #2
Source File: AluminumWireBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@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)
    ));
}
 
Example #3
Source File: MixinBlock.java    From multiconnect with MIT License 5 votes vote down vote up
@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();
    }
}
 
Example #4
Source File: ChunkUpgrader.java    From multiconnect with MIT License 5 votes vote down vote up
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());
}
 
Example #5
Source File: FluidPipeBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@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.)
    ));
}
 
Example #6
Source File: GratingBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@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);
}
 
Example #7
Source File: CavernousVineBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@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);
}
 
Example #8
Source File: WireBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@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;
}
 
Example #9
Source File: FluidLoggableBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@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;
}
 
Example #10
Source File: FluidLoggableBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@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;
    }
}
 
Example #11
Source File: ConfigurableElectricMachineBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@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;
}
 
Example #12
Source File: WireBlock.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Override
@Nonnull
public WireConnectionType canWireConnect(WorldAccess world, Direction opposite, BlockPos connectionSourcePos, BlockPos connectionTargetPos) {
    return WireConnectionType.WIRE;
}
 
Example #13
Source File: GCOreFeature.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@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;
}
 
Example #14
Source File: Walkway.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
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);
}
 
Example #15
Source File: CrudeOilFluid.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@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);
}
 
Example #16
Source File: FuelFluid.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@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);
}
 
Example #17
Source File: WireConnectable.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Nonnull
WireConnectionType canWireConnect(WorldAccess world, Direction opposite, BlockPos connectionSourcePos, BlockPos connectionTargetPos);
 
Example #18
Source File: ChunkUpgrader.java    From multiconnect with MIT License 4 votes vote down vote up
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);
}
 
Example #19
Source File: UpgradeDataAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Invoker
static BlockState callApplyAdjacentBlock(BlockState oldState, Direction dir, WorldAccess world, BlockPos currentPos, BlockPos otherPos) {
    return MixinHelper.fakeInstance();
}