-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41e6be6
commit 3bed7bf
Showing
8 changed files
with
218 additions
and
6 deletions.
There are no files selected for viewing
7 changes: 6 additions & 1 deletion
7
blockentity/common/src/main/java/band/kessoku/lib/api/blockentity/BlockEntityAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
package band.kessoku.lib.api.blockentity; | ||
|
||
public class BlockEntityAccess { | ||
import band.kessoku.lib.api.data.DataAccess; | ||
import band.kessoku.lib.api.data.DataStructure; | ||
import net.minecraft.block.entity.BlockEntity; | ||
|
||
@FunctionalInterface | ||
public interface BlockEntityAccess<T extends BlockEntity, S extends DataStructure> extends DataAccess<T, S> { | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...kentity/common/src/main/java/band/kessoku/lib/api/blockentity/BlockEntityCoordinator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package band.kessoku.lib.api.blockentity; | ||
|
||
import band.kessoku.lib.api.data.DataStructure; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.block.entity.BlockEntityType; | ||
|
||
public class BlockEntityCoordinator { | ||
public static <T extends BlockEntity, S extends DataStructure> void add(BlockEntityType<T> type, BlockEntityAccess<T, S> access) { | ||
|
||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
blockentity/common/src/main/java/band/kessoku/lib/api/blockentity/KessokuBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
package band.kessoku.lib.api.blockentity; | ||
|
||
import band.kessoku.lib.api.data.Storage; | ||
import band.kessoku.lib.impl.ItemSidinator; | ||
import net.minecraft.block.entity.BlockEntityType; | ||
import org.slf4j.Marker; | ||
import org.slf4j.MarkerFactory; | ||
|
||
public class KessokuBlockEntity { | ||
public static final String MOD_ID = "kessoku_blockentity"; | ||
public static final String NAME = "Kessoku Block Entity API"; | ||
public static final Marker MARKER = MarkerFactory.getMarker("[" + NAME +"]"); | ||
|
||
public void init() { | ||
BlockEntityCoordinator.add(BlockEntityType.FURNACE, Storage::inventory); | ||
BlockEntityCoordinator.add(BlockEntityType.CHEST, Storage::inventory); | ||
BlockEntityCoordinator.add( | ||
BlockEntityType.FURNACE, | ||
(blockentity) -> ItemSidinator.builder().side(1).bottom(2, 1).top(0).build() | ||
); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
data/common/src/main/java/band/kessoku/lib/api/data/Sidinator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package band.kessoku.lib.api.data; | ||
|
||
import net.minecraft.util.math.Direction; | ||
|
||
import java.util.List; | ||
|
||
public interface Sidinator<S extends DataStructure> extends DataStructure { | ||
List<Integer> get(Direction direction); | ||
} |
24 changes: 24 additions & 0 deletions
24
data/common/src/main/java/band/kessoku/lib/api/data/Storage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package band.kessoku.lib.api.data; | ||
|
||
import net.minecraft.inventory.Inventory; | ||
import net.minecraft.item.ItemStack; | ||
|
||
public interface Storage<T> extends DataStructure { | ||
T get(int id); | ||
|
||
int size(); | ||
|
||
static Storage<ItemStack> inventory(Inventory inventory) { | ||
return new Storage<>() { | ||
@Override | ||
public ItemStack get(int id) { | ||
return inventory.getStack(id); | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return inventory.size(); | ||
} | ||
}; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
data/common/src/main/java/band/kessoku/lib/api/data/Timer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package band.kessoku.lib.api.data; | ||
|
||
public interface Timer extends DataStructure { | ||
int time(); | ||
|
||
int totalTime(); | ||
} |
145 changes: 145 additions & 0 deletions
145
data/common/src/main/java/band/kessoku/lib/impl/ItemSidinator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
package band.kessoku.lib.impl; | ||
|
||
import band.kessoku.lib.api.data.Sidinator; | ||
import band.kessoku.lib.api.data.Storage; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.network.RegistryByteBuf; | ||
import net.minecraft.network.codec.PacketCodec; | ||
import net.minecraft.util.math.Direction; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.function.BiConsumer; | ||
|
||
public class ItemSidinator implements Sidinator<Storage<ItemStack>> { | ||
public static Codec<ItemSidinator> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
Codec.INT.listOf().fieldOf("down").forGetter((sidinator -> sidinator.get(Direction.DOWN))), | ||
Codec.INT.listOf().fieldOf("up").forGetter((sidinator -> sidinator.get(Direction.UP))), | ||
Codec.INT.listOf().fieldOf("north").forGetter((sidinator -> sidinator.get(Direction.NORTH))), | ||
Codec.INT.listOf().fieldOf("south").forGetter((sidinator -> sidinator.get(Direction.SOUTH))), | ||
Codec.INT.listOf().fieldOf("west").forGetter((sidinator -> sidinator.get(Direction.WEST))), | ||
Codec.INT.listOf().fieldOf("east").forGetter((sidinator -> sidinator.get(Direction.EAST))) | ||
).apply(instance, ItemSidinator::new)); | ||
public static final PacketCodec<RegistryByteBuf, ItemSidinator> PACKET_CODEC = new PacketCodec<>() { | ||
@Override | ||
public ItemSidinator decode(RegistryByteBuf buf) { | ||
ItemSidinator.Builder builder = ItemSidinator.builder(); | ||
for (Direction value : Direction.values()) { | ||
int size = buf.readInt(); | ||
int[] ids = new int[size]; | ||
for (int i = 0; i < size; i++) { | ||
ids[i] = buf.readInt(); | ||
} | ||
builder.add(value, ids); | ||
} | ||
return builder.build(); | ||
} | ||
|
||
@Override | ||
public void encode(RegistryByteBuf buf, ItemSidinator value) { | ||
value.forEach((direction, ids) -> { | ||
buf.writeInt(ids.size()); | ||
ids.forEach(buf::writeInt); | ||
}); | ||
} | ||
}; | ||
|
||
|
||
private final List<Integer> down; | ||
private final List<Integer> up; | ||
private final List<Integer> north; | ||
private final List<Integer> south; | ||
private final List<Integer> west; | ||
private final List<Integer> east; | ||
|
||
private ItemSidinator( | ||
List<Integer> down, | ||
List<Integer> up, | ||
List<Integer> north, | ||
List<Integer> south, | ||
List<Integer> west, | ||
List<Integer> east | ||
) { | ||
this.down = down; | ||
this.up = up; | ||
this.north = north; | ||
this.south = south; | ||
this.west = west; | ||
this.east = east; | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
@Override | ||
public List<Integer> get(Direction direction) { | ||
return switch (direction) { | ||
case DOWN -> down; | ||
case UP -> up; | ||
case NORTH -> north; | ||
case SOUTH -> south; | ||
case WEST -> west; | ||
case EAST -> east; | ||
}; | ||
} | ||
|
||
public void forEach(BiConsumer<Direction, List<Integer>> biConsumer) { | ||
for (Direction value : Direction.values()) { | ||
biConsumer.accept(value, get(value)); | ||
} | ||
} | ||
|
||
public static class Builder { | ||
private Builder() {} | ||
|
||
private final List<Integer> down = new ArrayList<>(); | ||
private final List<Integer> up = new ArrayList<>(); | ||
private final List<Integer> north = new ArrayList<>(); | ||
private final List<Integer> south = new ArrayList<>(); | ||
private final List<Integer> west = new ArrayList<>(); | ||
private final List<Integer> east = new ArrayList<>(); | ||
|
||
public Builder side(int... values) { | ||
return add(Direction.EAST, values).add(Direction.WEST, values).add(Direction.SOUTH, values).add(Direction.NORTH, values); | ||
} | ||
|
||
public Builder top(int... values) { | ||
return add(Direction.UP, values); | ||
} | ||
|
||
public Builder bottom(int... values) { | ||
return add(Direction.DOWN, values); | ||
} | ||
|
||
public Builder add(Direction direction, int... values) { | ||
get(direction).addAll(Arrays.stream(values).boxed().toList()); | ||
return this; | ||
} | ||
|
||
private List<Integer> get(Direction direction) { | ||
return switch (direction) { | ||
case DOWN -> down; | ||
case UP -> up; | ||
case NORTH -> north; | ||
case SOUTH -> south; | ||
case WEST -> west; | ||
case EAST -> east; | ||
}; | ||
} | ||
|
||
public ItemSidinator build() { | ||
return new ItemSidinator( | ||
down.stream().distinct().toList(), | ||
up.stream().distinct().toList(), | ||
north.stream().distinct().toList(), | ||
south.stream().distinct().toList(), | ||
west.stream().distinct().toList(), | ||
east.stream().distinct().toList() | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters