mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-22 11:53:29 +01:00
remove CONNECTED_INVENTORY
This commit is contained in:
parent
4c764023f4
commit
ab7e472a0f
5 changed files with 34 additions and 29 deletions
|
@ -5,8 +5,7 @@ import net.minecraft.util.IStringSerializable;
|
|||
import java.util.Locale;
|
||||
|
||||
public enum ConnectionType implements IStringSerializable {
|
||||
CONNECTED_PIPE(true),
|
||||
CONNECTED_INVENTORY(true),
|
||||
CONNECTED(true),
|
||||
DISCONNECTED(false),
|
||||
BLOCKED(false);
|
||||
|
||||
|
|
|
@ -67,11 +67,11 @@ public class PipeBlock extends ContainerBlock {
|
|||
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult p_225533_6_) {
|
||||
if (!player.getHeldItem(handIn).isEmpty())
|
||||
return ActionResultType.PASS;
|
||||
if (DIRECTIONS.values().stream().noneMatch(d -> state.get(d) == ConnectionType.CONNECTED_INVENTORY))
|
||||
return ActionResultType.PASS;
|
||||
PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, worldIn, pos);
|
||||
if (tile == null)
|
||||
return ActionResultType.PASS;
|
||||
if (!tile.isConnectedInventory())
|
||||
return ActionResultType.PASS;
|
||||
if (!worldIn.isRemote)
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, tile, pos);
|
||||
return ActionResultType.SUCCESS;
|
||||
|
@ -133,7 +133,7 @@ public class PipeBlock extends ContainerBlock {
|
|||
return state;
|
||||
}
|
||||
|
||||
public static ConnectionType getConnectionType(World world, BlockPos pos, Direction direction) {
|
||||
private static ConnectionType getConnectionType(World world, BlockPos pos, Direction direction) {
|
||||
BlockPos offset = pos.offset(direction);
|
||||
if (!world.isBlockLoaded(offset))
|
||||
return ConnectionType.DISCONNECTED;
|
||||
|
@ -141,32 +141,31 @@ public class PipeBlock extends ContainerBlock {
|
|||
if (state.getBlock() instanceof PipeBlock) {
|
||||
if (state.get(DIRECTIONS.get(direction.getOpposite())) == ConnectionType.BLOCKED)
|
||||
return ConnectionType.BLOCKED;
|
||||
return ConnectionType.CONNECTED_PIPE;
|
||||
} else {
|
||||
TileEntity tile = world.getTileEntity(offset);
|
||||
if (tile == null)
|
||||
return ConnectionType.DISCONNECTED;
|
||||
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, direction.getOpposite()).orElse(null);
|
||||
return handler == null ? ConnectionType.DISCONNECTED : ConnectionType.CONNECTED_INVENTORY;
|
||||
return ConnectionType.CONNECTED;
|
||||
}
|
||||
TileEntity tile = world.getTileEntity(offset);
|
||||
if (tile != null) {
|
||||
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, direction.getOpposite()).orElse(null);
|
||||
if (handler != null)
|
||||
return ConnectionType.CONNECTED;
|
||||
}
|
||||
return ConnectionType.DISCONNECTED;
|
||||
}
|
||||
|
||||
public static void onStateChanged(World world, BlockPos pos, BlockState newState) {
|
||||
if (DIRECTIONS.values().stream().noneMatch(d -> newState.get(d) == ConnectionType.CONNECTED_INVENTORY)) {
|
||||
PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, world, pos);
|
||||
if (tile != null)
|
||||
if (tile != null && !tile.isConnectedInventory())
|
||||
Utility.dropInventory(tile, tile.upgrades);
|
||||
}
|
||||
|
||||
PipeNetwork network = PipeNetwork.get(world);
|
||||
int connections = 0;
|
||||
boolean inventory = false;
|
||||
for (EnumProperty<ConnectionType> prop : DIRECTIONS.values()) {
|
||||
ConnectionType value = newState.get(prop);
|
||||
for (Direction dir : Direction.values()) {
|
||||
ConnectionType value = newState.get(DIRECTIONS.get(dir));
|
||||
if (!value.isConnected())
|
||||
continue;
|
||||
connections++;
|
||||
if (value == ConnectionType.CONNECTED_INVENTORY) {
|
||||
if (tile.isConnectedInventory(dir)) {
|
||||
inventory = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import net.minecraftforge.items.ItemStackHandler;
|
|||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class PipeTileEntity extends TileEntity implements INamedContainerProvider, ITickableTileEntity {
|
||||
|
@ -144,4 +145,12 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide
|
|||
return null;
|
||||
return tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, dir.getOpposite()).orElse(null);
|
||||
}
|
||||
|
||||
public boolean isConnectedInventory(Direction dir) {
|
||||
return this.getItemHandler(dir) != null;
|
||||
}
|
||||
|
||||
public boolean isConnectedInventory() {
|
||||
return Arrays.stream(Direction.values()).anyMatch(this::isConnectedInventory);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,15 +53,13 @@ public class WrenchItem extends Item {
|
|||
continue;
|
||||
|
||||
if (!world.isRemote) {
|
||||
ConnectionType newType = curr == ConnectionType.BLOCKED ? ConnectionType.CONNECTED_PIPE : ConnectionType.BLOCKED;
|
||||
ConnectionType newType = curr == ConnectionType.BLOCKED ? ConnectionType.CONNECTED : ConnectionType.BLOCKED;
|
||||
BlockPos otherPos = pos.offset(entry.getKey());
|
||||
BlockState otherState = world.getBlockState(otherPos);
|
||||
if (otherState.getBlock() instanceof PipeBlock) {
|
||||
otherState = otherState.with(PipeBlock.DIRECTIONS.get(entry.getKey().getOpposite()), newType);
|
||||
world.setBlockState(otherPos, otherState);
|
||||
PipeBlock.onStateChanged(world, otherPos, otherState);
|
||||
} else if (newType == ConnectionType.CONNECTED_PIPE) {
|
||||
newType = ConnectionType.CONNECTED_INVENTORY;
|
||||
}
|
||||
BlockState newState = state.with(prop, newType);
|
||||
world.setBlockState(pos, newState);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
},
|
||||
{
|
||||
"when": {
|
||||
"north": "connected_pipe|connected_inventory"
|
||||
"north": "connected"
|
||||
},
|
||||
"apply": {
|
||||
"model": "prettypipes:block/pipe_end"
|
||||
|
@ -15,7 +15,7 @@
|
|||
},
|
||||
{
|
||||
"when": {
|
||||
"south": "connected_pipe|connected_inventory"
|
||||
"south": "connected"
|
||||
},
|
||||
"apply": {
|
||||
"model": "prettypipes:block/pipe_end",
|
||||
|
@ -24,7 +24,7 @@
|
|||
},
|
||||
{
|
||||
"when": {
|
||||
"east": "connected_pipe|connected_inventory"
|
||||
"east": "connected"
|
||||
},
|
||||
"apply": {
|
||||
"model": "prettypipes:block/pipe_end",
|
||||
|
@ -33,7 +33,7 @@
|
|||
},
|
||||
{
|
||||
"when": {
|
||||
"west": "connected_pipe|connected_inventory"
|
||||
"west": "connected"
|
||||
},
|
||||
"apply": {
|
||||
"model": "prettypipes:block/pipe_end",
|
||||
|
@ -42,7 +42,7 @@
|
|||
},
|
||||
{
|
||||
"when": {
|
||||
"down": "connected_pipe|connected_inventory"
|
||||
"down": "connected"
|
||||
},
|
||||
"apply": {
|
||||
"model": "prettypipes:block/pipe_end",
|
||||
|
@ -51,7 +51,7 @@
|
|||
},
|
||||
{
|
||||
"when": {
|
||||
"up": "connected_pipe|connected_inventory"
|
||||
"up": "connected"
|
||||
},
|
||||
"apply": {
|
||||
"model": "prettypipes:block/pipe_end",
|
||||
|
|
Loading…
Reference in a new issue