All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.parzivail.util.block.rotating.WaterloggableRotatingBlockWithBounds Maven / Gradle / Ivy

There is a newer version: 0.0.114+1.20.2
Show newest version
package com.parzivail.util.block.rotating;

import com.parzivail.util.block.VoxelShapeUtil;
import net.minecraft.class_1922;
import net.minecraft.class_1936;
import net.minecraft.class_2246;
import net.minecraft.class_2338;
import net.minecraft.class_2350;
import net.minecraft.class_265;
import net.minecraft.class_2680;
import net.minecraft.class_2741;
import net.minecraft.class_3612;
import net.minecraft.class_3726;
import net.minecraft.class_4538;

public class WaterloggableRotatingBlockWithBounds extends WaterloggableRotatingBlock
{
	public enum Substrate
	{
		BEHIND,
		BELOW,
		NONE
	}

	private final class_265 shape;
	private final Substrate requiresSubstrate;

	public WaterloggableRotatingBlockWithBounds(class_265 shape, Substrate requiresSubstrate, class_2251 settings)
	{
		super(settings.method_9624());
		this.shape = shape;
		this.requiresSubstrate = requiresSubstrate;
	}

	@Override
	public class_265 method_9530(class_2680 state, class_1922 world, class_2338 pos, class_3726 context)
	{
		return VoxelShapeUtil.rotateToFace(shape, state.method_11654(FACING));
	}

	@Override
	public boolean method_9558(class_2680 state, class_4538 world, class_2338 pos)
	{
		if (requiresSubstrate == Substrate.NONE)
			return super.method_9558(state, world, pos);

		var substrateDirection = getSubstrateDirection(state);

		switch (requiresSubstrate)
		{
			case BEHIND -> {
				class_2338 blockPos = pos.method_10093(substrateDirection);
				return method_20044(world, blockPos, substrateDirection.method_10153());
			}
			case BELOW -> {
				class_2338 blockPos = pos.method_10074();
				return method_16361(world, blockPos) || method_20044(world, blockPos, class_2350.field_11036);
			}
			default -> throw new IllegalStateException("Unexpected value: " + requiresSubstrate);
		}
	}

	@Override
	public class_2680 method_9559(class_2680 state, class_2350 direction, class_2680 newState, class_1936 world, class_2338 pos, class_2338 posFrom)
	{
		if (state.method_11654(class_2741.field_12508))
			world.method_39281(pos, class_3612.field_15910, class_3612.field_15910.method_15789(world));

		if (requiresSubstrate == Substrate.NONE)
			return state;

		var substrateDirection = getSubstrateDirection(state);

		return direction == substrateDirection && !state.method_26184(world, pos) ? class_2246.field_10124.method_9564() : state;
	}

	private class_2350 getSubstrateDirection(class_2680 state)
	{
		if (requiresSubstrate == Substrate.BELOW)
			return class_2350.field_11033;

		return state.method_11654(FACING).method_10153();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy