Java Code Examples for net.minecraft.world.WorldAccess#setBlockState()
The following examples show how to use
net.minecraft.world.WorldAccess#setBlockState() .
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 |
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: FluidLoggableBlock.java From Galacticraft-Rewoven with MIT License | 5 votes |
@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 3
Source File: FluidLoggableBlock.java From Galacticraft-Rewoven with MIT License | 5 votes |
@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 4
Source File: ChunkUpgrader.java From multiconnect with MIT License | 5 votes |
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: GCOreFeature.java From Galacticraft-Rewoven with MIT License | 4 votes |
@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; }