Skip to content

Commit

Permalink
Very ugly encased pipe fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MehVahdJukaar committed Jan 15, 2024
1 parent 495f9fb commit 4debf49
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Random;
import java.util.function.Predicate;

import net.minecraft.world.level.block.*;
import org.jetbrains.annotations.NotNull;
import org.joml.Vector3f;
import org.violetmoon.quark.addons.oddities.block.pipe.BasePipeBlock;
Expand All @@ -36,8 +37,6 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LevelEvent;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.ChestBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
Expand Down Expand Up @@ -418,7 +417,8 @@ public static ConnectionType computeConnectionTo(BlockGetter world, BlockPos pos
private static ConnectionType computeConnectionTo(BlockGetter world, BlockPos pos, Direction face, boolean recursed) {
BlockPos truePos = pos.relative(face);

if(world.getBlockState(truePos).getBlock() instanceof WorldlyContainerHolder)
BlockState state = world.getBlockState(truePos);
if(state.getBlock() instanceof WorldlyContainerHolder)
return ConnectionType.TERMINAL;

BlockEntity tile = world.getBlockEntity(truePos);
Expand All @@ -427,7 +427,7 @@ private static ConnectionType computeConnectionTo(BlockGetter world, BlockPos po
if(tile instanceof PipeBlockEntity)
return ConnectionType.PIPE;
else if(tile instanceof Container || tile.getCapability(ForgeCapabilities.ITEM_HANDLER, face.getOpposite()).isPresent())
return tile instanceof ChestBlockEntity ? ConnectionType.TERMINAL_OFFSET : ConnectionType.TERMINAL;
return canHaveOffset(state, pos, world, face) ? ConnectionType.TERMINAL_OFFSET : ConnectionType.TERMINAL;
}

checkSides: if(!recursed) {
Expand All @@ -447,6 +447,13 @@ else if(tile instanceof Container || tile.getCapability(ForgeCapabilities.ITEM_H
return ConnectionType.NONE;
}

private static boolean canHaveOffset(BlockState state, BlockPos pos, BlockGetter world, Direction dir) {
var shape = state.getCollisionShape( world,pos);
if(dir.getAxisDirection() == Direction.AxisDirection.NEGATIVE){
return shape.max(dir.getAxis())<1;
}else return shape.min(dir.getAxis())>0;
}

public static class PipeItem {

private static final String TAG_TICKS = "ticksInPipe";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,16 @@ public BlockState mirror(@NotNull BlockState state, @NotNull Mirror mirror) {

@Override
public BlockState updateShape(BlockState state, Direction direction, BlockState neighbor, LevelAccessor level, BlockPos pos, BlockPos neighborPos) {
PipeBlockEntity.ConnectionType type = PipeBlockEntity.computeConnectionTo(level, pos, direction);
state = state.setValue(MiscUtil.directionProperty(direction), allowsFullConnection(type));
for(var d : Direction.values()) {
// Very ugly. I'm too lazy to figure out a better solution. Checking the given dir would work for normal pipes but not for encased ones
PipeBlockEntity.ConnectionType type = PipeBlockEntity.computeConnectionTo(level, pos, d);
boolean fullConnection = allowsFullConnection(type);
state = state.setValue(MiscUtil.directionProperty(d), fullConnection);
}
// This also shouldn't be here but again gives issues with encased pipes
if(level.getBlockEntity(pos) instanceof PipeBlockEntity tile) {
tile.refreshVisualConnections();
}
return state;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public EncasedPipeBlock(@Nullable ZetaModule module) {

@Override
public boolean allowsFullConnection(ConnectionType conn) {
return conn.isFlared || conn.isSolid;
return conn.isSolid || conn.isFlared;
}

@Override
Expand Down

0 comments on commit 4debf49

Please sign in to comment.