com.parzivail.util.block.rotating.WaterloggableRotating3BlockWithGuiEntity Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pswg Show documentation
Show all versions of pswg Show documentation
Explore the galaxy with Galaxies: Parzi's Star Wars Mod!
package com.parzivail.util.block.rotating;
import com.parzivail.util.ParziUtil;
import java.util.function.BiFunction;
import net.minecraft.class_1309;
import net.minecraft.class_1799;
import net.minecraft.class_1936;
import net.minecraft.class_1937;
import net.minecraft.class_2246;
import net.minecraft.class_2248;
import net.minecraft.class_2338;
import net.minecraft.class_2350;
import net.minecraft.class_2586;
import net.minecraft.class_2680;
import net.minecraft.class_2689;
import net.minecraft.class_2754;
import net.minecraft.class_3542;
import net.minecraft.class_3545;
import net.minecraft.class_4538;
public class WaterloggableRotating3BlockWithGuiEntity extends WaterloggableRotatingBlockWithGuiEntity
{
public enum Side implements class_3542
{
LEFT("left"),
MIDDLE("middle"),
RIGHT("right");
private final String name;
Side(String name)
{
this.name = name;
}
@Override
public String method_15434()
{
return name;
}
}
public static final class_2754 SIDE = class_2754.method_11850("side", Side.class);
public WaterloggableRotating3BlockWithGuiEntity(class_2251 settings, BiFunction blockEntityBiFunction)
{
super(settings, blockEntityBiFunction);
this.method_9590(this.method_9564().method_11657(SIDE, Side.MIDDLE));
}
@Override
protected void method_9515(class_2689.class_2690 builder)
{
super.method_9515(builder);
builder.method_11667(SIDE);
}
@Override
protected class_2338 getBlockEntityUsePos(class_2680 state, class_2338 pos)
{
if (state.method_11654(SIDE) != Side.MIDDLE)
return getControllerPos(pos, state);
return pos;
}
@Override
public class_2680 method_9559(class_2680 state, class_2350 direction, class_2680 neighborState, class_1936 world, class_2338 pos, class_2338 neighborPos)
{
if (!neighborState.method_27852(this))
{
if (state.method_11654(SIDE) == Side.MIDDLE)
{
var peripheral = getPeripheralPos(pos, state);
if (neighborPos.equals(peripheral.method_15442()) || neighborPos.equals(peripheral.method_15441()))
return class_2246.field_10124.method_9564();
}
else
{
var controllerPos = getControllerPos(pos, state);
if (neighborPos.equals(controllerPos))
return class_2246.field_10124.method_9564();
}
}
return state;
}
@Override
public void method_9567(class_1937 world, class_2338 pos, class_2680 state, class_1309 placer, class_1799 itemStack)
{
var rotation = state.method_11654(FACING);
switch (rotation)
{
case field_11043 ->
{
world.method_8652(pos.method_10067(), state.method_11657(SIDE, Side.LEFT), class_2248.field_31036);
world.method_8652(pos.method_10078(), state.method_11657(SIDE, Side.RIGHT), class_2248.field_31036);
return;
}
case field_11035 ->
{
world.method_8652(pos.method_10067(), state.method_11657(SIDE, Side.RIGHT), class_2248.field_31036);
world.method_8652(pos.method_10078(), state.method_11657(SIDE, Side.LEFT), class_2248.field_31036);
return;
}
case field_11034 ->
{
world.method_8652(pos.method_10095(), state.method_11657(SIDE, Side.LEFT), class_2248.field_31036);
world.method_8652(pos.method_10072(), state.method_11657(SIDE, Side.RIGHT), class_2248.field_31036);
return;
}
case field_11039 ->
{
world.method_8652(pos.method_10095(), state.method_11657(SIDE, Side.RIGHT), class_2248.field_31036);
world.method_8652(pos.method_10072(), state.method_11657(SIDE, Side.LEFT), class_2248.field_31036);
return;
}
}
ParziUtil.LOG.error("Invalid rotation for 3-block: %s @ %s", rotation, pos);
}
@Override
public boolean method_9558(class_2680 state, class_4538 world, class_2338 pos)
{
var peripheral = getPeripheralPos(pos, state);
return world.method_22347(peripheral.method_15442()) && world.method_22347(peripheral.method_15441());
}
private class_3545 getPeripheralPos(class_2338 controller, class_2680 state)
{
switch (state.method_11654(FACING))
{
case field_11043, field_11035 ->
{
return new class_3545<>(controller.method_10078(), controller.method_10067());
}
case field_11039, field_11034 ->
{
return new class_3545<>(controller.method_10095(), controller.method_10072());
}
}
ParziUtil.LOG.error("Invalid rotation for 3-block: %s @ %s", state.method_11654(FACING), controller);
return new class_3545<>(controller, controller);
}
private class_2338 getControllerPos(class_2338 self, class_2680 state)
{
var side = state.method_11654(SIDE);
if (side == Side.MIDDLE)
return self;
var rotation = state.method_11654(FACING);
switch (rotation)
{
case field_11043 ->
{
if (side == Side.LEFT)
return self.method_10078();
return self.method_10067();
}
case field_11035 ->
{
if (side == Side.RIGHT)
return self.method_10078();
return self.method_10067();
}
case field_11039 ->
{
if (side == Side.LEFT)
return self.method_10095();
return self.method_10072();
}
case field_11034 ->
{
if (side == Side.RIGHT)
return self.method_10095();
return self.method_10072();
}
}
ParziUtil.LOG.error("Invalid rotation for 3-block: %s @ %s", rotation, self);
return self;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy