Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[1.20.1]How does i make the output be true when both input1 and input2 are true

Featured Replies

Posted

I have this code for a AND Gate block

public class BlockAndGate extends HorizontalDirectionalBlock {

	public static DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
	public static BooleanProperty POWERED = BlockStateProperties.POWERED;
	public static BooleanProperty INPUT1 = BooleanProperty.create("input1");
	public static BooleanProperty INPUT2 = BooleanProperty.create("input2");

	public BlockAndGate() {
		super(createBlockProperties());
	}

	private static Properties createBlockProperties() {
		Properties props = Properties.of();
		props.isValidSpawn((state, getter, pos, entityType) -> {
			return false;
		});
		props.sound(SoundType.STONE);
		props.pushReaction(PushReaction.BLOCK);
		props.strength(0.0f, 2.0f);
		return props;
	}

	@Override
	public boolean propagatesSkylightDown(BlockState state, BlockGetter getter, BlockPos pos) {
		return false;
	}

	@Override
	protected void createBlockStateDefinition(Builder<Block, BlockState> builder) {
		builder.add(FACING);
		builder.add(POWERED);
		builder.add(INPUT1);
		builder.add(INPUT2);
	}

	@Override
	public BlockState getStateForPlacement(BlockPlaceContext context) {
		return defaultBlockState().setValue(FACING, context.getHorizontalDirection()).setValue(POWERED, false)
				.setValue(INPUT1, false).setValue(INPUT2, false);
	}

	@Override
	public boolean shouldCheckWeakPower(BlockState state, SignalGetter level, BlockPos pos, Direction side) {
		return !(side.equals(state.getValue(FACING).getOpposite()) || side.equals(state.getValue(FACING)));
	}

	@Override
	public boolean canConnectRedstone(BlockState state, BlockGetter level, BlockPos pos,
			@Nullable Direction direction) {
		return !direction.equals(state.getValue(FACING));
	}

	@Override
	public void neighborChanged(BlockState state, Level level, BlockPos blockPos, Block block, BlockPos updatePos,
			boolean moving) {
		if (!level.isClientSide()) {
			boolean sigI1, stI1, sigI2, stI2,outputSt;
			Direction i1Side = state.getValue(FACING).getCounterClockWise();
			Direction i2Side = state.getValue(FACING).getClockWise();
			boolean input1, input2,side1,side2,state1,state2, output;
			
			if ((updatePos.relative(i1Side).equals(blockPos) || updatePos.relative(i2Side).equals(blockPos))) {
				side1 = level.hasNeighborSignal(blockPos.relative(i1Side));
				side2 = level.hasNeighborSignal(blockPos.relative(i2Side));
				output = side1 && side2;
				level.setBlock(blockPos, state.setValue(INPUT1, side1).setValue(INPUT2, side2).setValue(POWERED, output), UPDATE_CLIENTS);
			}
		}
	}

	
	
	@Override
	public boolean isSignalSource(BlockState state) {
		return state.getValue(POWERED);
	}

	@Override
	public int getSignal(BlockState state, BlockGetter getter, BlockPos pos, Direction direction) {
		return (state.getValue(POWERED) && state.getValue(FACING).getOpposite().equals(direction)) ? 15 : 0;
	}

	@Override
	public int getDirectSignal(BlockState state, BlockGetter getter, BlockPos pos, Direction direction) {
		return (state.getValue(FACING).getOpposite().equals(direction)) ? this.getSignal(state, getter, pos, direction) : 0;
	}

	@Override
	public VoxelShape getShape(BlockState state, BlockGetter getter, BlockPos pos, CollisionContext context) {
		return Block.box(0, 0, 0, 16, 4, 16);
	}

}

And for some reason when the property input1 and input2 both become true. I can't turn off the powered state. And i can't see how can i make the block detect both weak and strong signal from the side inputs

Block Image below

G6S3rQK.png

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.