net.minecraft.util.math.Direction Java Examples

The following examples show how to use net.minecraft.util.math.Direction. 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: ConfigurableElectricMachineBlockEntityRenderer.java    From Galacticraft-Rewoven with MIT License 7 votes vote down vote up
public BakedModel bakeModel(JsonUnbakedModel model, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings settings, Identifier id, boolean hasDepth) {
    Sprite sprite = textureGetter.apply(model.resolveSprite("particle"));
    if (model.getRootModel() == ModelLoader.BLOCK_ENTITY_MARKER) {
        return new BuiltinBakedModel(model.getTransformations(), ModelOverrideList.EMPTY, sprite, model.getGuiLight().isSide());
    } else {
        BasicBakedModel.Builder builder = (new BasicBakedModel.Builder(model, ModelOverrideList.EMPTY, hasDepth)).setParticle(sprite);

        for (ModelElement modelElement : model.getElements()) {
            for (Direction direction : modelElement.faces.keySet()) {
                ModelElementFace modelElementFace = modelElement.faces.get(direction);
                Sprite sprite2 = textureGetter.apply(model.resolveSprite(modelElementFace.textureId));
                if (modelElementFace.cullFace == null) {
                    builder.addQuad(createQuad(modelElement, modelElementFace, sprite2, direction, settings, id));
                } else {
                    builder.addQuad(Direction.transform(settings.getRotation().getMatrix(), modelElementFace.cullFace), createQuad(modelElement, modelElementFace, sprite2, direction, settings, id));
                }
            }
        }

        return builder.build();
    }
}
 
Example #2
Source File: CarpetDispenserBehaviours.java    From carpet-extra with GNU Lesser General Public License v3.0 7 votes vote down vote up
@Override
protected ItemStack dispenseSilently(BlockPointer source, ItemStack stack) {
    if(!CarpetExtraSettings.dispensersToggleThings) {
        return super.dispenseSilently(source, stack);
    }

    World world = source.getWorld();
    Direction direction = (Direction) source.getBlockState().get(DispenserBlock.FACING);
    BlockPos pos = source.getBlockPos().offset(direction);
    BlockState state = world.getBlockState(pos);  
    if(toggleable.contains(state.getBlock())) {
        ActionResult result = state.onUse(
            world, 
            null,
            Hand.MAIN_HAND,
            new BlockHitResult(
                new Vec3d(new Vec3i(pos.getX(), pos.getY(), pos.getZ())), 
                direction, 
                pos,
                false
            )
        );
        if(result.isAccepted()) return stack; // success or consume
    }
    return super.dispenseSilently(source, stack);
}
 
Example #3
Source File: AluminumWireBlock.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
private BooleanProperty getPropForDirection(Direction dir) {
    switch (dir) {
        case SOUTH:
            return ATTACHED_SOUTH;
        case EAST:
            return ATTACHED_EAST;
        case WEST:
            return ATTACHED_WEST;
        case NORTH:
            return ATTACHED_NORTH;
        case UP:
            return ATTACHED_UP;
        case DOWN:
            return ATTACHED_DOWN;
        default:
            throw new IllegalArgumentException("cannot be null");
    }
}
 
Example #4
Source File: BlockValue.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Override
public Direction[] getPlacementDirections() {
    switch(this.facing) {
        case DOWN:
        default:
            return new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.UP};
        case UP:
            return new Direction[]{Direction.DOWN, Direction.UP, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST};
        case NORTH:
            return new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.SOUTH};
        case SOUTH:
            return new Direction[]{Direction.DOWN, Direction.SOUTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.NORTH};
        case WEST:
            return new Direction[]{Direction.DOWN, Direction.WEST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.EAST};
        case EAST:
            return new Direction[]{Direction.DOWN, Direction.EAST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.WEST};
    }
}
 
Example #5
Source File: MixinBlockItem.java    From multiconnect with MIT License 6 votes vote down vote up
@Inject(method = "canPlace", at = @At("HEAD"), cancellable = true)
private void onCanPlace(ItemPlacementContext context, BlockState state, CallbackInfoReturnable<Boolean> ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2) {
        Block block = state.getBlock();
        if (block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST) {
            World world = context.getWorld();
            BlockPos pos = context.getBlockPos();
            boolean foundAdjChest = false;
            for (Direction dir : Direction.Type.HORIZONTAL) {
                BlockState otherState = world.getBlockState(pos.offset(dir));
                if (otherState.getBlock() == block) {
                    if (foundAdjChest) {
                        ci.setReturnValue(false);
                        return;
                    }
                    foundAdjChest = true;
                    if (otherState.get(ChestBlock.CHEST_TYPE) != ChestType.SINGLE) {
                        ci.setReturnValue(false);
                        return;
                    }
                }
            }
        }
    }
}
 
Example #6
Source File: CoalGeneratorBlockEntityRenderer.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
@Nonnull
@Override
public SpriteIdentifier getDefaultSpriteId(@Nonnull CoalGeneratorBlockEntity entity, @Nonnull Direction direction) {
    if (direction == Direction.NORTH) {
        return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/coal_generator"));
    }
    return super.getDefaultSpriteId(entity, direction);
}
 
Example #7
Source File: CarpetDispenserBehaviours.java    From carpet-extra with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected ItemStack dispenseSilently(BlockPointer source, ItemStack stack)
{
    if (!CarpetExtraSettings.dispensersPlayRecords)
        return super.dispenseSilently(source, stack);
    
    Direction direction = source.getBlockState().get(DispenserBlock.FACING);
    BlockPos pos = source.getBlockPos().offset(direction);
    World world = source.getWorld();
    BlockState state = world.getBlockState(pos);
    
    if (state.getBlock() == Blocks.JUKEBOX)
    {
        JukeboxBlockEntity jukebox = (JukeboxBlockEntity) world.getBlockEntity(pos);
        if (jukebox != null)
        {
            ItemStack itemStack = jukebox.getRecord();
            ((JukeboxBlock) state.getBlock()).setRecord(world, pos, state, stack);
            world.playLevelEvent(null, 1010, pos, Item.getRawId(stack.getItem()));
            
            return itemStack;
        }
    }
    
    return super.dispenseSilently(source, stack);
}
 
Example #8
Source File: BasicSolarPanelBlockEntityRenderer.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
@Override
@Nonnull
public SpriteIdentifier getDefaultSpriteId(@Nonnull BasicSolarPanelBlockEntity entity, @Nonnull Direction direction) {
    switch (direction) {
        case NORTH:
            return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/basic_solar_panel"));
        case SOUTH:
            new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine_side"));
        case EAST:
            new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine_side"));
        case WEST:
            new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine_side"));
        case UP:
            new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/solar_panel"));
        case DOWN:
            new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine"));
    }
    return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine"));
}
 
Example #9
Source File: RefineryBlockEntityRenderer.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
@Nonnull
@Override
public SpriteIdentifier getDefaultSpriteId(@Nonnull RefineryBlockEntity entity, @Nonnull Direction direction) {
    switch (direction) {
        case NORTH:
            return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/refinery_front"));
        case SOUTH:
            return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/refinery_side"));
        case EAST:
        case WEST:
            return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine_side"));
        case UP:
        case DOWN:
            return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine"));
    }
    return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine"));
}
 
Example #10
Source File: PonySkullRenderer.java    From MineLittlePony with MIT License 6 votes vote down vote up
static void handleRotation(MatrixStack stack, @Nullable Direction direction) {
    if (direction == null) {
        stack.translate(0.5, 0, 0.5);
        return;
    }

    switch (direction) {
        case NORTH:
            stack.translate(0.5, 0.25, 0.74);
            break;
        case SOUTH:
            stack.translate(0.5, 0.25, 0.26);
            break;
        case WEST:
            stack.translate(0.74, 0.25, 0.5);
            break;
        case EAST:
        default:
            stack.translate(0.26, 0.25, 0.5);
            break;
    }
}
 
Example #11
Source File: IForgeBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Re-colors this block in the world.
 *
 * @param state   The current state
 * @param world   The world
 * @param pos     Block position
 * @param facing  ??? (this method has no usages)
 * @param color   Color to recolor to.
 * @return if the block was affected
 */
@SuppressWarnings("unchecked")
default boolean recolorBlock(BlockState state, IWorld world, BlockPos pos, Direction facing, DyeColor color) {
	for (Property<?> prop : state.getProperties()) {
		if (prop.getName().equals("color") && prop.getType() == DyeColor.class) {
			DyeColor current = (DyeColor) state.get(prop);

			if (current != color && prop.getValues().contains(color)) {
				world.setBlockState(pos, state.with(((Property<DyeColor>) prop), color), 3);
				return true;
			}
		}
	}

	return false;
}
 
Example #12
Source File: LargeSkeletalTreeFeature.java    From the-hallow with MIT License 6 votes vote down vote up
protected boolean generateBranch(Set<BlockPos> set, ModifiableTestableWorld world, Random random, BlockPos pos, BlockBox mibb, int maxBranchouts, Direction lastDir) {
	int baseHeight = random.nextInt(4) + 2;
	
	for (int int_4 = 0; int_4 < baseHeight; ++int_4) {
		BlockPos blockPos = pos.up(int_4 + 1);
		if (!isSurroundedByAir(world, blockPos, null)) {
			return true;
		}
		addLog(set, world, blockPos, Direction.Axis.Y, mibb);
	}
	
	int int_5 = random.nextInt(4) + 1;
	int int_1 = 8;
	
	if (maxBranchouts > 0)
		for (int int_6 = 0; int_6 < int_5; ++int_6) {
			Direction direction_1 = Direction.Type.HORIZONTAL.random(random);
			if (direction_1 == lastDir) continue;
			BlockPos blockPos_4 = pos.up(baseHeight).offset(direction_1);
			if (Math.abs(blockPos_4.getX() - pos.getX()) < int_1 && Math.abs(blockPos_4.getZ() - pos.getZ()) < int_1 && isAir(world, blockPos_4) && isAir(world, blockPos_4.down()) && isSurroundedByAir(world, blockPos_4, direction_1.getOpposite())) {
				addLog(set, world, blockPos_4, direction_1.getAxis(), mibb);
				generateBranch(set, world, random, blockPos_4, mibb, maxBranchouts - 1, direction_1.getOpposite());
			}
		}
	return true;
}
 
Example #13
Source File: CarpetDispenserBehaviours.java    From carpet-extra with GNU Lesser General Public License v3.0 6 votes vote down vote up
private ItemStack defaultBehaviour(BlockPointer source, ItemStack stack)
{
    if (this.minecartType == AbstractMinecartEntity.Type.TNT)
    {
        World world = source.getWorld();
        BlockPos pos = source.getBlockPos().offset((Direction) source.getBlockState().get(DispenserBlock.FACING));
        TntEntity tntEntity = new TntEntity(world, (double)pos.getX() + 0.5D, (double)pos.getY(), (double)pos.getZ() + 0.5D, (LivingEntity)null);
        world.spawnEntity(tntEntity);
        world.playSound((PlayerEntity)null, tntEntity.getX(), tntEntity.getY(), tntEntity.getZ(), SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F);
        stack.decrement(1);
        return stack;
    }
    else
    {
        return super.dispenseSilently(source, stack);
    }
}
 
Example #14
Source File: Walkway.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
protected int getShapeIndex(BlockState state) {
    return this.SHAPE_INDEX_CACHE.computeIntIfAbsent(state, (blockState) -> {
        int i = 0;
        if (blockState.get(NORTH)) {
            i |= getDirectionMask(Direction.NORTH);
        }

        if (blockState.get(EAST)) {
            i |= getDirectionMask(Direction.EAST);
        }

        if (blockState.get(SOUTH)) {
            i |= getDirectionMask(Direction.SOUTH);
        }

        if (blockState.get(WEST)) {
            i |= getDirectionMask(Direction.WEST);
        }

        return i;
    });
}
 
Example #15
Source File: PistonHandler_movableTEMixin.java    From fabric-carpet with MIT License 6 votes vote down vote up
/**
 * Handles blocks besides the slimeblock that are sticky. Currently only supports blocks that are sticky on one side.
 * Currently the only additional sticky block is the double chest, which sticks to its other chest half.
 * @param blockPos_1 location of a block that moves and needs to stick other blocks to it
 * @author 2No2Name
 */
private boolean stickToStickySide(BlockPos blockPos_1){
    if(!CarpetSettings.movableBlockEntities)
        return true;

    BlockState blockState_1 = this.world.getBlockState(blockPos_1);
    Block block = blockState_1.getBlock();
    Direction stickyDirection  = null;
    if(block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST) {
        stickyDirection = getDirectionToOtherChestHalf(blockState_1);
    }

    //example how you could make sticky pistons have a sticky side:
    //else if(block == Blocks.STICKY_PISTON){
    //    stickyDirection = blockState_1.get(FacingBlock.FACING);
    //}

    return stickyDirection == null || this.tryMove(blockPos_1.offset(stickyDirection), stickyDirection);
}
 
Example #16
Source File: AbstractRedstoneGateBlockMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Redirect(
        method = "isTargetNotAligned",
        at = @At(value = "INVOKE",
                target = "Lnet/minecraft/util/math/Direction;getOpposite()Lnet/minecraft/util/math/Direction;")
)
private Direction onIsTargetNotAligned(Direction direction)
{
    if (CarpetExtraSettings.repeaterPriorityFix)
        return direction;
    else
        return direction.getOpposite();
}
 
Example #17
Source File: MixinFarmlandBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "hasCrop", cancellable = true, at = @At("HEAD"))
private static void onHasCrop(BlockView world, BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
	final BlockState ourState = world.getBlockState(pos);
	final BlockState cropState = world.getBlockState(pos.up());

	if (cropState.getBlock() instanceof IPlantable && ((IForgeBlockState) ourState).canSustainPlant(world, pos, Direction.UP, (IPlantable) cropState.getBlock())) {
		cir.setReturnValue(true);
		cir.cancel();
	}
}
 
Example #18
Source File: ConfigurableElectricMachineBlockEntityRenderer.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
private static List<ModelElement> generateCube() {
    Map<Direction, ModelElementFace> faces = new HashMap<>();
    for (Direction direction : Direction.values()) {
        faces.put(direction, new ModelElementFace(null, -1, direction.getName(), new ModelElementTexture(null, 0)));
    }
    return Collections.singletonList(new ModelElement(new Vector3f(0, 0, 0), new Vector3f(16, 16, 16), faces, null, true));
}
 
Example #19
Source File: ConfigurableElectricMachineBlockEntityRenderer.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Nonnull
public SpriteIdentifier getDefaultSpriteId(@Nonnull T entity, @Nonnull Direction direction) {
    switch (direction) {
        case NORTH:
        case SOUTH:
        case EAST:
        case WEST:
            return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine_side"));
        case UP:
        case DOWN:
            return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine"));
    }
    return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine"));
}
 
Example #20
Source File: ConfigurableElectricMachineBlockEntityRenderer.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
public float getDegrees(Direction dir) {
    switch (dir) {
        case NORTH:
            return 0;
        case SOUTH:
            return 180;
        case EAST:
            return 270;
        case WEST:
            return 90;
    }
    return 0;
}
 
Example #21
Source File: ConfigurableElectricMachineBlockEntity.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
protected int[] getAvailableSlots(Direction side) {
    int[] ints = new int[getInventorySize()];

    for (int i = 0; i < getInventorySize(); i++) {
        ints[i] = i;
    }

    return ints;
}
 
Example #22
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 #23
Source File: BlockRotator.java    From fabric-carpet with MIT License 5 votes vote down vote up
private static Direction rotateYClockwise(Direction dir) {
    switch(dir) {
        case NORTH:
            return Direction.EAST;
        case EAST:
            return Direction.SOUTH;
        case SOUTH:
            return Direction.WEST;
        case WEST:
            return Direction.NORTH;
        default:
            throw new IllegalStateException("Unable to get Y-rotated facing of " + dir);
    }
}
 
Example #24
Source File: MixinFluidRenderer.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "isSideCovered", at = @At("HEAD"), cancellable = true)
private static void isSideCovered(BlockView blockView_1, BlockPos blockPos_1, Direction direction_1, float float_1, CallbackInfoReturnable<Boolean> callbackInfo) {
    Xray xray = (Xray) ModuleManager.getModule(Xray.class);
    if (xray.getSettings().get(0).toToggle().state) return;
    if (xray.isToggled() && xray.isVisible(blockView_1.getBlockState(blockPos_1).getBlock())) {
        callbackInfo.setReturnValue(false);
        callbackInfo.cancel();
    }
}
 
Example #25
Source File: TinyPumpkinBlockEntity.java    From the-hallow with MIT License 5 votes vote down vote up
public ActionResult use(PlayerEntity player, Hand hand, BlockHitResult hit) {
	Direction facing = getCachedState().get(HorizontalFacingBlock.FACING);
	Direction hitSide = hit.getSide();
	if (hitSide != facing.rotateYClockwise() && hitSide != facing.rotateYCounterclockwise()) {
		return ActionResult.PASS;
	}
	
	if (!world.isClient) {
		ItemStack handStack = player.getStackInHand(hand);
		boolean isLeft = hitSide == facing.rotateYCounterclockwise();
		ItemStack heldItem = isLeft ? leftItem : rightItem;
		if (!heldItem.isEmpty()) {
			ItemScatterer.spawn(world, pos, DefaultedList.copyOf(ItemStack.EMPTY, heldItem));
			if (isLeft) {
				leftItem = ItemStack.EMPTY;
			} else {
				rightItem = ItemStack.EMPTY;
			}
			sync();
			markDirty();
		} else if (!handStack.isEmpty()) {
			if (isLeft) {
				leftItem = handStack.copy();
				leftItem.setCount(1);
			} else {
				rightItem = handStack.copy();
				rightItem.setCount(1);
			}
			handStack.decrement(1);
			sync();
			markDirty();
		}
	}
	
	return ActionResult.SUCCESS;
}
 
Example #26
Source File: AutoBuildHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
private void buildInstantly()
{
	Vec3d eyesPos = RotationUtils.getEyesPos();
	IClientPlayerInteractionManager im = IMC.getInteractionManager();
	double rangeSq = Math.pow(range.getValue(), 2);
	
	for(BlockPos pos : remainingBlocks)
	{
		if(!BlockUtils.getState(pos).getMaterial().isReplaceable())
			continue;
		
		Vec3d posVec = Vec3d.ofCenter(pos);
		
		for(Direction side : Direction.values())
		{
			BlockPos neighbor = pos.offset(side);
			
			// check if neighbor can be right-clicked
			if(!BlockUtils.canBeClicked(neighbor))
				continue;
			
			Vec3d sideVec = Vec3d.of(side.getVector());
			Vec3d hitVec = posVec.add(sideVec.multiply(0.5));
			
			// check if hitVec is within range
			if(eyesPos.squaredDistanceTo(hitVec) > rangeSq)
				continue;
			
			// place block
			im.rightClickBlock(neighbor, side.getOpposite(), hitVec);
			
			break;
		}
	}
	
	remainingBlocks.clear();
}
 
Example #27
Source File: CircuitFabricatorBlockEntityRenderer.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Nonnull
@Override
public SpriteIdentifier getDefaultSpriteId(@Nonnull CircuitFabricatorBlockEntity entity, @Nonnull Direction direction) {
    if (direction == Direction.NORTH) {
        return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/circuit_fabricator"));
    }
    return super.getDefaultSpriteId(entity, direction);
}
 
Example #28
Source File: MixinSugarCaneBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "canPlaceAt", at = @At("HEAD"), cancellable = true)
private void onCanPlaceAt(BlockState state, CollisionView world, BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
	BlockState soil = world.getBlockState(pos.down());

	if (((IForgeBlockState) soil).canSustainPlant(world, pos.down(), Direction.UP, this)) {
		cir.cancel();
		cir.setReturnValue(true);
	}
}
 
Example #29
Source File: BlockWrapper.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public BlockState getStateForNeighborUpdate(BlockState blockState_1, Direction direction_1, BlockState blockState_2, IWorld iWorld_1, BlockPos blockPos_1, BlockPos blockPos_2) {
    return WrappingUtil.convert(block.updateOnNeighborChanged(
            (org.sandboxpowered.sandbox.api.state.BlockState) blockState_1,
            WrappingUtil.convert(direction_1),
            (org.sandboxpowered.sandbox.api.state.BlockState) blockState_2,
            (org.sandboxpowered.sandbox.api.world.World) iWorld_1.getWorld(), (Position) blockPos_1,
            (Position) blockPos_2
    ));
}
 
Example #30
Source File: Walkway.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
private BooleanProperty getPropForDir(Direction direction) {
    switch (direction) {
        case NORTH:
            return NORTH;
        case WEST:
            return WEST;
        case EAST:
            return EAST;
        case SOUTH:
            return SOUTH;
    }
    throw new IllegalArgumentException();
}