Skip to content

Commit fbff16a

Browse files
committed
Merge remote-tracking branch 'origin/1.21.1-port' into 1.21.1-datagen
2 parents 9f545f5 + 896b6df commit fbff16a

File tree

594 files changed

+4573
-3612
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

594 files changed

+4573
-3612
lines changed

src/main/java/de/dafuqs/spectrum/SpectrumCommon.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package de.dafuqs.spectrum;
22

3+
import java.util.*;
4+
35
import de.dafuqs.spectrum.api.color.*;
46
import de.dafuqs.spectrum.api.energy.color.*;
57
import de.dafuqs.spectrum.blocks.pastel_network.*;
@@ -38,8 +40,6 @@
3840
import org.jetbrains.annotations.*;
3941
import org.slf4j.*;
4042

41-
import java.util.*;
42-
4343
public class SpectrumCommon implements ModInitializer {
4444

4545
public static final String MOD_ID = "spectrum";
@@ -65,13 +65,12 @@ public static Identifier locate(String name) {
6565
}
6666

6767
/**
68-
* This is the Spectrum analogue of Identifier.ofVanilla. It's best used in a codec where
69-
* the default namespace will be spectrum.
68+
* This is the Spectrum analogue of Identifier.of, but instead of defaulting to the namespace 'minecraft', it defaults to 'spectrum'.
7069
*
7170
* @param id The stringified identifier to parse
7271
* @return The parsed identifier
7372
*/
74-
public static Identifier ofSpectrum(String id) {
73+
public static Identifier ofSpectrumDefaulted(String id) {
7574
int i = id.indexOf(':');
7675
String path = id.substring(i + 1);
7776
String namespace = i > 0 ? id.substring(0, i) : SpectrumCommon.MOD_ID;
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package de.dafuqs.spectrum.api.block;
22

3+
import java.util.*;
4+
35
import de.dafuqs.spectrum.helpers.*;
46
import de.dafuqs.spectrum.inventories.slots.*;
57
import de.dafuqs.spectrum.networking.c2s_payloads.*;
@@ -14,159 +16,172 @@
1416
import net.minecraft.screen.*;
1517
import net.minecraft.screen.slot.*;
1618
import net.minecraft.util.*;
19+
import net.minecraft.util.math.*;
1720
import org.jetbrains.annotations.*;
1821

19-
import java.util.*;
20-
2122
public interface FilterConfigurable {
22-
23-
List<ItemVariant> getItemFilters();
24-
25-
void setFilterItem(int slot, ItemVariant item);
26-
27-
default int getFilterRows() {
28-
return 1;
29-
}
30-
31-
default int getSlotsPerRow() {
32-
return 5;
33-
}
34-
35-
default int getDrawnSlots() {
36-
return getItemFilters().size();
37-
}
38-
39-
static void writeFilterNbt(NbtCompound tag, List<ItemVariant> filterItems) {
23+
24+
List<ItemVariant> getItemFilters();
25+
26+
void setFilterItem(int slot, ItemVariant item);
27+
28+
default int getFilterRows() {
29+
return 1;
30+
}
31+
32+
default int getSlotsPerRow() {
33+
return 5;
34+
}
35+
36+
default int getDrawnSlots() {
37+
return getItemFilters().size();
38+
}
39+
40+
static void writeFilterNbt(NbtCompound tag, List<ItemVariant> filterItems) {
4041
for (int i = 0; i < filterItems.size(); i++) {
4142
if (!filterItems.get(i).isBlank()) {
4243
CodecHelper.writeNbt(tag, "FilterStack" + i, ItemVariant.CODEC, filterItems.get(i));
4344
}
4445
}
45-
}
46-
47-
static void readFilterNbt(NbtCompound tag, List<ItemVariant> filterItems) {
48-
for (int i = 0; i < filterItems.size(); i++) {
49-
if (tag.contains("FilterStack" + i))
46+
}
47+
48+
static void readFilterNbt(NbtCompound tag, List<ItemVariant> filterItems) {
49+
for (int i = 0; i < filterItems.size(); i++) {
50+
if (tag.contains("FilterStack" + i))
5051
filterItems.set(i, CodecHelper.fromNbt(ItemVariant.CODEC, tag.get("FilterStack" + i), null));
51-
}
52-
}
53-
54-
static Inventory getFilterInventoryFromDataClicker(ExtendedData data, ShadowSlotClicker clicker) {
55-
var size = data.filterItems().size();
56-
Inventory inventory = new FilterInventory(clicker, size);
57-
for (int i = 0; i < size; i++) {
58-
inventory.setStack(i, data.filterItems().get(i).toStack());
59-
}
60-
return inventory;
61-
}
62-
63-
static Inventory getFilterInventoryFromExtendedData(int syncId, @NotNull PlayerInventory playerInventory, ExtendedData data, @NotNull ScreenHandler handler) {
64-
final var clicker = new ShadowSlotClicker.FromHandler(handler, playerInventory.player, syncId);
65-
return getFilterInventoryFromDataClicker(data, clicker);
66-
}
67-
68-
static Inventory getFilterInventoryFromItemsClicker(List<ItemVariant> items, ShadowSlotClicker clicker) {
69-
Inventory inventory = new FilterInventory(clicker, items.size());
70-
for (int i = 0; i < items.size(); i++) {
71-
inventory.setStack(i, items.get(i).toStack());
72-
}
73-
return inventory;
74-
}
75-
76-
static Inventory getFilterInventoryFromItemsHandler(int syncId, @NotNull PlayerInventory playerInventory, List<ItemVariant> items, @NotNull ScreenHandler thisHandler) {
77-
final var clicker = new ShadowSlotClicker.FromHandler(thisHandler, playerInventory.player, syncId);
78-
return getFilterInventoryFromItemsClicker(items, clicker);
79-
}
80-
81-
// Ensures execution of ShadowSlot.onClicked both on the server and client.
82-
// Do not use if not required.
83-
interface ShadowSlotClicker {
84-
default void clickShadowSlot(int syncId, Slot slot, ItemStack shadowStack) {
85-
clickShadowSlot(syncId, slot.id, shadowStack);
86-
}
87-
88-
void clickShadowSlot(int syncId, int id, ItemStack shadowStack);
89-
90-
class FromHandler implements ShadowSlotClicker {
91-
public final @NotNull ScreenHandler handler;
92-
public final @NotNull PlayerEntity player;
93-
public final int syncId;
94-
95-
public FromHandler(@NotNull ScreenHandler screenHandler, @NotNull PlayerEntity player, int syncId) {
96-
this.handler = screenHandler;
97-
this.player = player;
98-
this.syncId = syncId;
99-
}
100-
101-
@Override
102-
public void clickShadowSlot(int syncId, @Nullable Slot slot, ItemStack shadowStack) {
103-
if (this.syncId != syncId || !(slot instanceof ShadowSlot shadowSlot)) return;
104-
if (!shadowSlot.onClicked(shadowStack, ClickType.LEFT, player)) return;
105-
106-
// Sync with server
107-
if (player.getWorld().isClient()) {
108-
ClientPlayNetworking.send(new SetShadowSlotPayload(syncId, slot.id, shadowStack));
109-
}
110-
}
111-
112-
@Override
113-
public void clickShadowSlot(int syncId, int id, ItemStack shadowStack) {
114-
this.clickShadowSlot(syncId, handler.getSlot(id), shadowStack);
115-
}
116-
}
117-
}
118-
119-
// Contains the slot clicker.
120-
class FilterInventory extends SimpleInventory {
121-
private final @NotNull FilterConfigurable.ShadowSlotClicker clicker;
122-
123-
public FilterInventory(@NotNull FilterConfigurable.ShadowSlotClicker slotClicker, int size) {
124-
super(size);
125-
this.clicker = slotClicker;
126-
}
127-
128-
public @NotNull FilterConfigurable.ShadowSlotClicker getClicker() {
129-
return clicker;
130-
}
131-
}
132-
133-
static void writeScreenOpeningData(RegistryByteBuf buf, FilterConfigurable configurable) {
134-
writeScreenOpeningData(buf, configurable.getItemFilters(), configurable.getFilterRows(), configurable.getSlotsPerRow(), configurable.getDrawnSlots());
135-
}
136-
137-
static void writeScreenOpeningData(RegistryByteBuf buf, List<ItemVariant> filterItems, int rows, int slotsPerRow, int drawnSlots) {
138-
buf.writeInt(filterItems.size());
139-
for (ItemVariant filterItem : filterItems) {
140-
// The difference between just using filterItem.toNbt() is that ItemVariant nbt uses "item" while ItemStack uses "id"
141-
ItemStack.PACKET_CODEC.encode(buf, filterItem.toStack());
142-
}
143-
buf.writeInt(rows);
144-
buf.writeInt(slotsPerRow);
145-
buf.writeInt(drawnSlots);
146-
}
147-
148-
default boolean hasEmptyFilter() {
149-
return getItemFilters().stream().allMatch(ItemVariant::isBlank);
150-
}
151-
152-
record ExtendedData(List<ItemVariant> filterItems, int rows, int slotsPerRow, int drawnSlots) {
153-
52+
}
53+
}
54+
55+
static Inventory getFilterInventoryFromDataClicker(ExtendedData data, ShadowSlotClicker clicker) {
56+
var size = data.filterItems().size();
57+
Inventory inventory = new FilterInventory(clicker, size);
58+
for (int i = 0; i < size; i++) {
59+
inventory.setStack(i, data.filterItems().get(i).toStack());
60+
}
61+
return inventory;
62+
}
63+
64+
static Inventory getFilterInventoryFromExtendedData(int syncId, @NotNull PlayerInventory playerInventory, ExtendedData data, @NotNull ScreenHandler handler) {
65+
final var clicker = new ShadowSlotClicker.FromHandler(handler, playerInventory.player, syncId);
66+
return getFilterInventoryFromDataClicker(data, clicker);
67+
}
68+
69+
static Inventory getFilterInventoryFromItemsClicker(List<ItemVariant> items, ShadowSlotClicker clicker) {
70+
Inventory inventory = new FilterInventory(clicker, items.size());
71+
for (int i = 0; i < items.size(); i++) {
72+
inventory.setStack(i, items.get(i).toStack());
73+
}
74+
return inventory;
75+
}
76+
77+
static Inventory getFilterInventoryFromItemsHandler(int syncId, @NotNull PlayerInventory playerInventory, List<ItemVariant> items, @NotNull ScreenHandler thisHandler) {
78+
final var clicker = new ShadowSlotClicker.FromHandler(thisHandler, playerInventory.player, syncId);
79+
return getFilterInventoryFromItemsClicker(items, clicker);
80+
}
81+
82+
// Ensures execution of ShadowSlot.onClicked both on the server and client.
83+
// Do not use if not required.
84+
interface ShadowSlotClicker {
85+
default void clickShadowSlot(int syncId, Slot slot, ItemStack shadowStack) {
86+
clickShadowSlot(syncId, slot.id, shadowStack);
87+
}
88+
89+
void clickShadowSlot(int syncId, int id, ItemStack shadowStack);
90+
91+
class FromHandler implements ShadowSlotClicker {
92+
public final @NotNull ScreenHandler handler;
93+
public final @NotNull PlayerEntity player;
94+
public final int syncId;
95+
96+
public FromHandler(@NotNull ScreenHandler screenHandler, @NotNull PlayerEntity player, int syncId) {
97+
this.handler = screenHandler;
98+
this.player = player;
99+
this.syncId = syncId;
100+
}
101+
102+
@Override
103+
public void clickShadowSlot(int syncId, @Nullable Slot slot, ItemStack shadowStack) {
104+
if (this.syncId != syncId || !(slot instanceof ShadowSlot shadowSlot)) return;
105+
if (!shadowSlot.onClicked(shadowStack, ClickType.LEFT, player)) return;
106+
107+
// Sync with server
108+
if (player.getWorld().isClient()) {
109+
ClientPlayNetworking.send(new SetShadowSlotPayload(syncId, slot.id, shadowStack));
110+
}
111+
}
112+
113+
@Override
114+
public void clickShadowSlot(int syncId, int id, ItemStack shadowStack) {
115+
this.clickShadowSlot(syncId, handler.getSlot(id), shadowStack);
116+
}
117+
}
118+
}
119+
120+
// Contains the slot clicker.
121+
class FilterInventory extends SimpleInventory {
122+
private final @NotNull FilterConfigurable.ShadowSlotClicker clicker;
123+
124+
public FilterInventory(@NotNull FilterConfigurable.ShadowSlotClicker slotClicker, int size) {
125+
super(size);
126+
this.clicker = slotClicker;
127+
}
128+
129+
public @NotNull FilterConfigurable.ShadowSlotClicker getClicker() {
130+
return clicker;
131+
}
132+
}
133+
134+
static void writeScreenOpeningData(RegistryByteBuf buf, FilterConfigurable configurable) {
135+
writeScreenOpeningData(buf, configurable.getItemFilters(), configurable.getFilterRows(), configurable.getSlotsPerRow(), configurable.getDrawnSlots());
136+
}
137+
138+
static void writeScreenOpeningData(RegistryByteBuf buf, List<ItemVariant> filterItems, int rows, int slotsPerRow, int drawnSlots) {
139+
buf.writeInt(filterItems.size());
140+
for (ItemVariant filterItem : filterItems) {
141+
// The difference between just using filterItem.toNbt() is that ItemVariant nbt uses "item" while ItemStack uses "id"
142+
ItemStack.PACKET_CODEC.encode(buf, filterItem.toStack());
143+
}
144+
buf.writeInt(rows);
145+
buf.writeInt(slotsPerRow);
146+
buf.writeInt(drawnSlots);
147+
}
148+
149+
default boolean hasEmptyFilter() {
150+
return getItemFilters().stream().allMatch(ItemVariant::isBlank);
151+
}
152+
153+
record ExtendedData(List<ItemVariant> filterItems, int rows, int slotsPerRow, int drawnSlots) {
154+
154155
public ExtendedData(FilterConfigurable configurable) {
155156
this(configurable.getItemFilters(), configurable.getFilterRows(), configurable.getSlotsPerRow(), configurable.getDrawnSlots());
156157
}
157158

158-
public static final PacketCodec<RegistryByteBuf, ExtendedData> PACKET_CODEC = PacketCodec.tuple(
159-
ItemVariant.PACKET_CODEC.collect(PacketCodecs.toList()),
160-
ExtendedData::filterItems,
161-
PacketCodecs.VAR_INT,
162-
ExtendedData::rows,
163-
PacketCodecs.VAR_INT,
164-
ExtendedData::slotsPerRow,
165-
PacketCodecs.VAR_INT,
166-
ExtendedData::drawnSlots,
167-
ExtendedData::new
168-
);
169-
170-
}
171-
159+
public static final PacketCodec<RegistryByteBuf, ExtendedData> PACKET_CODEC = PacketCodec.tuple(
160+
ItemVariant.PACKET_CODEC.collect(PacketCodecs.toList()), ExtendedData::filterItems,
161+
PacketCodecs.VAR_INT, ExtendedData::rows,
162+
PacketCodecs.VAR_INT, ExtendedData::slotsPerRow,
163+
PacketCodecs.VAR_INT, ExtendedData::drawnSlots,
164+
ExtendedData::new
165+
);
166+
167+
}
168+
169+
record ExtendedDataWithPos(BlockPos pos, ExtendedData data) {
170+
171+
public ExtendedDataWithPos(BlockPos pos, FilterConfigurable configurable) {
172+
this(pos, new ExtendedData(configurable.getItemFilters(), configurable.getFilterRows(), configurable.getSlotsPerRow(), configurable.getDrawnSlots()));
173+
}
174+
175+
public ExtendedDataWithPos(BlockPos pos, List<ItemVariant> filterItems, int rows, int slotsPerRow, int drawnSlots) {
176+
this(pos, new ExtendedData(filterItems, rows, slotsPerRow, drawnSlots));
177+
}
178+
179+
public static final PacketCodec<RegistryByteBuf, ExtendedDataWithPos> PACKET_CODEC = PacketCodec.tuple(
180+
BlockPos.PACKET_CODEC, c -> c.pos,
181+
ExtendedData.PACKET_CODEC, c -> c.data,
182+
ExtendedDataWithPos::new
183+
);
184+
185+
}
186+
172187
}

src/main/java/de/dafuqs/spectrum/api/block/MultiblockCrafter.java

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static void spawnItemStackAsEntitySplitViaMaxCount(World world, Vec3d pos, ItemS
7777
if (owner != null) {
7878
itemEntity.setOwner(owner.getUuid());
7979
}
80+
itemEntity.setCovetedItem();
8081
world.spawnEntity(itemEntity);
8182

8283
amount -= currentAmount;
@@ -86,6 +87,7 @@ static void spawnItemStackAsEntitySplitViaMaxCount(World world, Vec3d pos, ItemS
8687
static void spawnOutputAsItemEntity(World world, BlockPos pos, ItemStack outputItemStack) {
8788
ItemEntity itemEntity = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, outputItemStack);
8889
itemEntity.addVelocity(0, 0.1, 0);
90+
itemEntity.setCovetedItem();
8991
world.spawnEntity(itemEntity);
9092
}
9193

src/main/java/de/dafuqs/spectrum/api/block/RedstonePoweredBlock.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
public interface RedstonePoweredBlock {
88

9-
BooleanProperty POWERED = BooleanProperty.of("powered");
10-
119
default boolean checkGettingPowered(World world, BlockPos pos) {
1210
Direction[] var4 = Direction.values();
1311
int var5 = var4.length;
@@ -38,11 +36,11 @@ default boolean checkGettingPowered(World world, BlockPos pos) {
3836
}
3937

4038
default void power(World world, BlockPos pos) {
41-
world.setBlockState(pos, world.getBlockState(pos).with(POWERED, true));
39+
world.setBlockState(pos, world.getBlockState(pos).with(Properties.POWERED, true));
4240
}
4341

4442
default void unPower(World world, BlockPos pos) {
45-
world.setBlockState(pos, world.getBlockState(pos).with(POWERED, false));
43+
world.setBlockState(pos, world.getBlockState(pos).with(Properties.POWERED, false));
4644
}
4745

4846
}

0 commit comments

Comments
 (0)