Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extended multi rotation #1358

Merged
merged 26 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
824f175
fix machines not conducting redstone (might fix #1146)
screret Apr 23, 2024
fc6bd6c
try to fix #728
screret Apr 23, 2024
51263b8
implement extended multiblock rotation
screret Apr 23, 2024
9f4138a
Revert "try to fix #728"
screret Apr 23, 2024
0300075
make upwards facing a blockstate property
screret Apr 23, 2024
3a8cef6
make all extended-faceable multis allow all rotations as well
screret Apr 23, 2024
c7894ad
add KJS usability
screret Apr 23, 2024
05a9e08
make all machines use static face baking methods because I discovered…
screret Apr 23, 2024
5d79e6e
try to fix render (didn't work)
screret Apr 23, 2024
8deef5e
start of fixing the machine overlay
YoungOnionMC May 26, 2024
8a54755
more maths
YoungOnionMC May 27, 2024
b00e797
fixes rotations for unformed machines
YoungOnionMC May 31, 2024
b88b7f7
merge to 1.20.1
screret May 31, 2024
9f9dff4
lang handler fix
YoungOnionMC May 31, 2024
f4e6bbf
fix errors
screret May 31, 2024
b59ccf9
Merge branch 'refs/heads/1.20.1' into sc/extended-multi-rotation
screret May 31, 2024
47448de
fix overlay z-fighting
screret May 31, 2024
3780ede
shit's fucked and idk why (it zfights when formed)
screret May 31, 2024
0d344fe
fix the dumbfuck models z-fighting
screret Jun 1, 2024
499cc46
formatting part 1
screret Jun 2, 2024
56c5de2
formatting part 2
screret Jun 2, 2024
48090d5
formatting part 3
screret Jun 2, 2024
e068031
formatting part 4
screret Jun 2, 2024
20dcefa
fuck it we ball
screret Jun 2, 2024
4d41ceb
spotless
screret Jun 3, 2024
e103091
disable spotless in build-on-push check by instead using assemble task
screret Jun 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Build
uses: gradle/gradle-build-action@v2
with:
arguments: build
arguments: assemble

- name: Upload Artifact
uses: actions/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencyResolutionManagement {
def vineFlowerVersion = "1.+"
def macheteVersion = "1.+"
def configurationVersion = "2.2.0"
def ldLibVersion = "1.0.25.j"
def ldLibVersion = "1.0.25.l"
def mixinextrasVersion = "0.2.0"
def shimmerVersion = "0.2.2"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.lowdragmc.lowdraglib.client.renderer.IBlockRendererProvider;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
Expand All @@ -16,6 +17,7 @@
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.DirectionProperty;

import org.jetbrains.annotations.Nullable;

Expand All @@ -26,6 +28,8 @@
*/
public interface IMachineBlock extends IBlockRendererProvider, EntityBlock {

DirectionProperty UPWARDS_FACING_PROPERTY = DirectionProperty.create("upwards_facing", Direction.Plane.HORIZONTAL);

default Block self() {
return (Block) this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.MachineDefinition;
import com.gregtechceu.gtceu.api.machine.MetaMachine;
import com.gregtechceu.gtceu.api.machine.MultiblockMachineDefinition;
import com.gregtechceu.gtceu.api.machine.feature.*;
import com.gregtechceu.gtceu.common.data.GTItems;
import com.gregtechceu.gtceu.utils.GTUtil;
Expand Down Expand Up @@ -60,6 +61,7 @@
* @date 2023/2/17
* @implNote GTBlock
*/
@SuppressWarnings("deprecation")
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class MetaMachineBlock extends AppearanceBlock implements IMachineBlock {
Expand All @@ -74,7 +76,12 @@ public MetaMachineBlock(Properties properties, MachineDefinition definition) {
this.definition = definition;
this.rotationState = RotationState.get();
if (rotationState != RotationState.NONE) {
registerDefaultState(defaultBlockState().setValue(rotationState.property, rotationState.defaultDirection));
BlockState defaultState = this.defaultBlockState().setValue(rotationState.property,
rotationState.defaultDirection);
if (definition instanceof MultiblockMachineDefinition multi && multi.isAllowExtendedFacing()) {
defaultState = defaultState.setValue(IMachineBlock.UPWARDS_FACING_PROPERTY, Direction.NORTH);
}
registerDefaultState(defaultState);
}
}

Expand All @@ -84,6 +91,10 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
RotationState rotationState = RotationState.get();
if (rotationState != RotationState.NONE) {
pBuilder.add(rotationState.property);
if (MachineDefinition.getBuilt() instanceof MultiblockMachineDefinition multi &&
multi.isAllowExtendedFacing()) {
pBuilder.add(IMachineBlock.UPWARDS_FACING_PROPERTY);
}
}
}

Expand Down Expand Up @@ -113,11 +124,6 @@ public void animateTick(BlockState state, Level level, BlockPos pos, RandomSourc
}
}

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

@Override
public void setPlacedBy(Level pLevel, BlockPos pPos, BlockState pState, @Nullable LivingEntity player,
ItemStack pStack) {
Expand Down Expand Up @@ -150,21 +156,29 @@ public BlockState getStateForPlacement(BlockPlaceContext context) {
var blockPos = context.getClickedPos();
var state = defaultBlockState();
if (player != null && rotationState != RotationState.NONE) {
if (rotationState == RotationState.Y_AXIS) {
state = state.setValue(rotationState.property, Direction.UP);
} else {
state = state.setValue(rotationState.property, player.getDirection().getOpposite());
}
Vec3 pos = player.position();
if (Math.abs(pos.x - (double) ((float) blockPos.getX() + 0.5F)) < 2.0D &&
Math.abs(pos.z - (double) ((float) blockPos.getZ() + 0.5F)) < 2.0D) {
double d0 = pos.y + (double) player.getEyeHeight();
if (d0 - (double) blockPos.getY() > 2.0D && rotationState.test(Direction.UP)) {
return state.setValue(rotationState.property, Direction.UP);
state = state.setValue(rotationState.property, Direction.UP);
}
if ((double) blockPos.getY() - d0 > 0.0D && rotationState.test(Direction.DOWN)) {
return state.setValue(rotationState.property, Direction.DOWN);
state = state.setValue(rotationState.property, Direction.DOWN);
}
}
if (rotationState == RotationState.Y_AXIS) {
return state.setValue(rotationState.property, Direction.UP);
} else {
return state.setValue(rotationState.property, player.getDirection().getOpposite());
if (getDefinition() instanceof MultiblockMachineDefinition multi && multi.isAllowExtendedFacing()) {
Direction frontFacing = state.getValue(rotationState.property);
if (frontFacing == Direction.UP) {
state = state.setValue(IMachineBlock.UPWARDS_FACING_PROPERTY, player.getDirection());
} else if (frontFacing == Direction.DOWN) {
state = state.setValue(IMachineBlock.UPWARDS_FACING_PROPERTY, player.getDirection().getOpposite());
}
}
}
return state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,18 @@ public boolean equals(Object o) {
public int hashCode() {
return id.hashCode();
}

static final ThreadLocal<MachineDefinition> STATE = new ThreadLocal<>();

public static MachineDefinition getBuilt() {
return STATE.get();
}

public static void setBuilt(MachineDefinition state) {
STATE.set(state);
}

public static void clearBuilt() {
STATE.remove();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public class MultiblockMachineDefinition extends MachineDefinition {
@Setter
@Getter
private Supplier<List<MultiblockShapeInfo>> shapes;
/** Whether this multi can be rotated or face upwards. */
@Getter
@Setter
private boolean allowExtendedFacing;
/** Set this to false only if your multiblock is set up such that it could have a wall-shared controller. */
@Getter
@Setter
private boolean allowFlip;
@Setter
@Getter
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ default MultiblockControllerMachine self() {
* <br>
* you should always use {@link IMultiController#checkPatternWithLock()} and
* {@link IMultiController#checkPatternWithTryLock()} instead.
*
*
* @return whether it can be formed.
*/
default boolean checkPattern() {
Expand All @@ -62,7 +62,7 @@ default boolean checkPatternWithLock() {

/**
* Check pattern with a try lock
*
*
* @return false - checking failed or cant get the lock.
*/
default boolean checkPatternWithTryLock() {
Expand Down Expand Up @@ -101,7 +101,7 @@ default BlockPattern getPattern() {
/**
* Called in an async thread. It's unsafe, Don't modify anything of world but checking information.
* It will be called per 5 tick.
*
*
* @param periodID period Tick
*/
void asyncCheckPattern(long periodID);
Expand Down Expand Up @@ -175,7 +175,7 @@ default InteractionResult onUse(BlockState state, Level world, BlockPos pos, Pla
BlockHitResult hit) {
if (!self().isFormed() && player.isShiftKeyDown() && player.getItemInHand(hand).isEmpty()) {
if (world.isClientSide()) {
MultiblockInWorldPreviewRenderer.showPreview(pos, self().getFrontFacing(),
MultiblockInWorldPreviewRenderer.showPreview(pos, self().getFrontFacing(), self().getUpwardsFacing(),
self().getDefinition().getMatchingShapes().get(0),
ConfigHolder.INSTANCE.client.inWorldPreviewDuration * 20);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.gregtechceu.gtceu.api.machine.multiblock;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.block.IMachineBlock;
import com.gregtechceu.gtceu.api.block.MetaMachineBlock;
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.MetaMachine;
import com.gregtechceu.gtceu.api.machine.MultiblockMachineDefinition;
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMultiController;
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMultiPart;
import com.gregtechceu.gtceu.api.pattern.MultiblockState;
import com.gregtechceu.gtceu.api.pattern.MultiblockWorldSavedData;
import com.gregtechceu.gtceu.api.pattern.util.RelativeDirection;

import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced;
import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted;
Expand All @@ -18,9 +22,14 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;

import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
Expand Down Expand Up @@ -54,6 +63,11 @@ public class MultiblockControllerMachine extends MetaMachine implements IMultiCo
@DescSynced
@RequireRerender
protected boolean isFormed;
@Getter
@Setter
@Persisted
@DescSynced
protected boolean isFlipped;

public MultiblockControllerMachine(IMachineBlockEntity holder) {
super(holder);
Expand Down Expand Up @@ -204,4 +218,78 @@ public void onRotated(Direction oldFacing, Direction newFacing) {
mwsd.addAsyncLogic(this);
}
}

public boolean allowExtendedFacing() {
return getDefinition().isAllowExtendedFacing();
}

public boolean allowFlip() {
return getDefinition().isAllowFlip();
}

@Override
public boolean isFacingValid(Direction facing) {
return allowExtendedFacing() || super.isFacingValid(facing);
}

public Direction getUpwardsFacing() {
return this.allowExtendedFacing() ? this.getBlockState().getValue(IMachineBlock.UPWARDS_FACING_PROPERTY) :
Direction.NORTH;
}

public void setUpwardsFacing(@NotNull Direction upwardsFacing) {
if (!getDefinition().isAllowExtendedFacing()) return;
if (upwardsFacing == null || upwardsFacing == Direction.UP || upwardsFacing == Direction.DOWN) {
GTCEu.LOGGER.error("Tried to set upwards facing to invalid facing {}! Skipping", upwardsFacing);
return;
}
BlockState blockState = getBlockState();
if (blockState.getBlock() instanceof MetaMachineBlock metaMachineBlock &&
blockState.getValue(IMachineBlock.UPWARDS_FACING_PROPERTY) != upwardsFacing) {
getLevel().setBlockAndUpdate(getPos(),
blockState.setValue(IMachineBlock.UPWARDS_FACING_PROPERTY, upwardsFacing));
if (getLevel() != null && !getLevel().isClientSide) {
notifyBlockUpdate();
markDirty();
checkPattern();
}
}
screret marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
protected InteractionResult onWrenchClick(Player playerIn, InteractionHand hand, Direction gridSide,
BlockHitResult hitResult) {
if (gridSide == getFrontFacing() && allowExtendedFacing()) {
setUpwardsFacing(playerIn.isShiftKeyDown() ? getUpwardsFacing().getCounterClockWise() :
getUpwardsFacing().getClockWise());
return InteractionResult.CONSUME;
}
if (playerIn.isShiftKeyDown()) {
if (gridSide == getFrontFacing() || !isFacingValid(gridSide)) {
return InteractionResult.FAIL;
}
if (!isRemote()) {
setFrontFacing(gridSide);
}
return InteractionResult.CONSUME;
}
return super.onWrenchClick(playerIn, hand, gridSide, hitResult);
}

@Override
public void setFrontFacing(Direction facing) {
Direction oldFacing = getFrontFacing();

if (allowExtendedFacing()) {
Direction newUpwardsFacing = RelativeDirection.simulateAxisRotation(facing, oldFacing, getUpwardsFacing());
setUpwardsFacing(newUpwardsFacing);
}
super.setFrontFacing(facing);

if (getLevel() != null && !getLevel().isClientSide) {
notifyBlockUpdate();
markDirty();
checkPattern();
}
}
}
Loading
Loading