Java Code Examples for net.minecraft.world.BlockView#getBlockState()

The following examples show how to use net.minecraft.world.BlockView#getBlockState() . 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: ConfigurableElectricMachineBlockEntity.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public <T extends Component> boolean hasComponent(BlockView blockView, BlockPos pos, ComponentType<T> type, @Nullable Direction side) {
    if (type == UniversalComponents.CAPACITOR_COMPONENT) {
        BlockState state = blockView.getBlockState(pos);
        SideOption option = ((ConfigurableElectricMachineBlock) state.getBlock()).getOption(state, ConfigurableElectricMachineBlock.BlockFace.toFace(state.get(ConfigurableElectricMachineBlock.FACING), side));
        return option == SideOption.POWER_INPUT || option == SideOption.POWER_OUTPUT;
    }
    return false;
}
 
Example 2
Source File: ConfigurableElectricMachineBlockEntity.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Nullable
@Override
public <T extends Component> T getComponent(BlockView blockView, BlockPos pos, ComponentType<T> type, @Nullable Direction side) {
    if (type == UniversalComponents.CAPACITOR_COMPONENT) {
        BlockState state = blockView.getBlockState(pos);
        SideOption option = ((ConfigurableElectricMachineBlock) state.getBlock()).getOption(state, ConfigurableElectricMachineBlock.BlockFace.toFace(state.get(ConfigurableElectricMachineBlock.FACING), side));
        if (option == SideOption.POWER_INPUT || option == SideOption.POWER_OUTPUT) {
            SimpleCapacitorComponent cc = new SimpleCapacitorComponent(capacitorComponent.getMaxEnergy(), GalacticraftEnergy.GALACTICRAFT_JOULES) {
                @Override
                public boolean canExtractEnergy() {
                    return option == SideOption.POWER_OUTPUT;
                }

                @Override
                public boolean canInsertEnergy() {
                    return option == SideOption.POWER_INPUT;
                }
            };

            cc.fromTag(capacitorComponent.toTag(new CompoundTag()));
            cc.getListeners().add(() -> capacitorComponent.setCurrentEnergy(cc.getCurrentEnergy()));
            //noinspection unchecked
            return (T) cc;
        }
    }
    return null;
}
 
Example 3
Source File: ConfigurableElectricMachineBlockEntity.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public Set<ComponentType<?>> getComponentTypes(BlockView blockView, BlockPos pos, @Nullable Direction side) {
    Set<ComponentType<?>> set = new HashSet<>();
    BlockState state = blockView.getBlockState(pos);
    SideOption option = ((ConfigurableElectricMachineBlock) state.getBlock()).getOption(state, ConfigurableElectricMachineBlock.BlockFace.toFace(state.get(ConfigurableElectricMachineBlock.FACING), side));
    if (option == SideOption.POWER_OUTPUT || option == SideOption.POWER_INPUT) {
        set.add(UniversalComponents.CAPACITOR_COMPONENT);
    }
    return set;
}
 
Example 4
Source File: WitchWaterBubbleColumnBlock.java    From the-hallow with MIT License 5 votes vote down vote up
private static boolean calculateDrag(BlockView view, BlockPos pos) {
	BlockState state = view.getBlockState(pos);
	Block block = state.getBlock();
	if (block == HallowedBlocks.WITCH_WATER_BUBBLE_COLUMN) {
		return state.get(DRAG);
	} else {
		return block != HallowedBlocks.COARSE_TAINTED_SAND;
	}
}
 
Example 5
Source File: FluidRendererMixin.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(at = {@At("HEAD")},
	method = {
		"isSideCovered(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;F)Z"},
	cancellable = true)
private static void onIsSideCovered(BlockView blockView_1,
	BlockPos blockPos_1, Direction direction_1, float float_1,
	CallbackInfoReturnable<Boolean> cir)
{
	BlockState state = blockView_1.getBlockState(blockPos_1);
	ShouldDrawSideEvent event = new ShouldDrawSideEvent(state);
	WurstClient.INSTANCE.getEventManager().fire(event);
	
	if(event.isRendered() != null)
		cir.setReturnValue(!event.isRendered());
}
 
Example 6
Source File: MixinPlantBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public BlockState getPlant(BlockView world, BlockPos pos) {
	final BlockState blockState = world.getBlockState(pos);

	if (blockState.getBlock() != (Object) this) {
		return ((Block) (Object) this).getDefaultState();
	}

	return blockState;
}
 
Example 7
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();
	}
}