Skip to content

Commit 43f2297

Browse files
committed
Merge branch 'dev/1.19.2' into dev/1.20.1
# Conflicts: # CHANGELOG.md # gradle.properties # src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java # src/main/java/de/srendi/advancedperipherals/common/addons/powah/FurnatorIntegration.java # src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java # src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java # src/main/java/de/srendi/advancedperipherals/common/util/fakeplayer/APFakePlayer.java # src/main/java/de/srendi/advancedperipherals/common/village/VillagerTrades.java
2 parents 23d3b91 + 6888ed5 commit 43f2297

File tree

14 files changed

+204
-113
lines changed

14 files changed

+204
-113
lines changed

src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/MeBridgePeripheral.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,10 @@ public final MethodResult getItem(IArguments arguments) throws LuaException {
420420
if (parsedFilter.isEmpty())
421421
return MethodResult.of(null, "EMPTY_FILTER");
422422

423-
return MethodResult.of(AppEngApi.getObjectFromStack(AppEngApi.findAEStackFromFilter(monitor, getCraftingService(), parsedFilter), getCraftingService()));
423+
Pair<Long, AEItemKey> item = AppEngApi.findAEStackFromFilter(monitor, getCraftingService(), parsedFilter);
424+
if (item.getRight() == null && item.getLeft() == 0)
425+
return MethodResult.of(null, "NOT_FOUND");
426+
return MethodResult.of(AppEngApi.getObjectFromStack(item, getCraftingService()));
424427
}
425428

426429
@LuaFunction(mainThread = true)

src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/RsBridgePeripheral.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public final MethodResult listCraftableItems() {
7474
return notConnected();
7575

7676
List<Object> items = new ArrayList<>();
77-
RefinedStorage.getCraftableItems(getNetwork()).forEach(item -> items.add(RefinedStorage.getObjectFromStack(item.copy(), getNetwork())));
77+
RefinedStorage.getCraftableItems(getNetwork()).forEach(item -> items.add(RefinedStorage.getObjectFromStack(item, getNetwork())));
7878
return MethodResult.of(items);
7979
}
8080

@@ -299,7 +299,10 @@ public final MethodResult getItem(IArguments arguments) throws LuaException {
299299
if (filter.rightPresent())
300300
return MethodResult.of(null, filter.getRight());
301301

302-
return MethodResult.of(RefinedStorage.getObjectFromStack(RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft()), getNetwork()));
302+
ItemStack item = RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft());
303+
if (item.isEmpty())
304+
return MethodResult.of(null, "NOT_FOUND");
305+
return MethodResult.of(RefinedStorage.getObjectFromStack(item, getNetwork()));
303306
}
304307

305308
@LuaFunction(mainThread = true)
@@ -313,7 +316,7 @@ public final MethodResult craftItem(IArguments arguments) throws LuaException {
313316
return MethodResult.of(null, filter.getRight());
314317

315318
ItemStack stack = RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft());
316-
if (stack == null)
319+
if (stack.isEmpty())
317320
return MethodResult.of(null, "NOT_CRAFTABLE");
318321

319322
ICalculationResult result = getNetwork().getCraftingManager().create(stack, filter.getLeft().getCount());
@@ -334,7 +337,7 @@ public final MethodResult craftFluid(IArguments arguments) throws LuaException {
334337
return MethodResult.of(null, filter.getRight());
335338

336339
FluidStack stack = RefinedStorage.findFluidFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft());
337-
if (stack == null)
340+
if (stack.isEmpty())
338341
return MethodResult.of(null, "NOT_CRAFTABLE");
339342

340343
ICalculationResult result = getNetwork().getCraftingManager().create(stack, filter.getLeft().getCount());
@@ -355,7 +358,7 @@ public final MethodResult isItemCrafting(IArguments arguments) throws LuaExcepti
355358
return MethodResult.of(null, filter.getRight());
356359

357360
ItemStack stack = RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft());
358-
if (stack == null)
361+
if (stack.isEmpty())
359362
return MethodResult.of(null, "NOT_CRAFTABLE");
360363

361364
for (ICraftingTask task : getNetwork().getCraftingManager().getTasks()) {

src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataEntityHandPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public final MethodResult useOnAnimal(@NotNull IArguments arguments) throws LuaE
5656
if (automataCore.hasAttribute(AutomataCorePeripheral.ATTR_STORING_TOOL_DURABILITY))
5757
selectedTool.setDamageValue(previousDamageValue);
5858

59-
return MethodResult.of(true, result.toString());
59+
return MethodResult.of(result.consumesAction(), result.toString());
6060
});
6161
}
6262

src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/plugins/AutomataSoulFeedingPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public final MethodResult feedSoul() {
2424

2525
InteractionResult result = owner.withPlayer(APFakePlayer::useOnEntity);
2626
automataCore.addRotationCycle(3);
27-
return MethodResult.of(true, result.toString());
27+
return MethodResult.of(result.consumesAction(), result.toString());
2828
}
2929

3030
@Override

src/main/java/de/srendi/advancedperipherals/common/addons/powah/FurnatorIntegration.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import dan200.computercraft.api.lua.LuaFunction;
44
import de.srendi.advancedperipherals.lib.peripherals.APGenericPeripheral;
5+
import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral;
6+
import de.srendi.advancedperipherals.common.util.LuaConverter;
57
import net.minecraft.world.item.ItemStack;
68
import owmii.powah.block.furnator.FurnatorTile;
79

@@ -12,6 +14,11 @@ public String getPeripheralType() {
1214
return "furnator";
1315
}
1416

17+
@LuaFunction(mainThread = true)
18+
public final String getName() {
19+
return "Furnator";
20+
}
21+
1522
@LuaFunction(mainThread = true)
1623
public final boolean isBurning(FurnatorTile blockEntity) {
1724
return blockEntity.isBurning();
@@ -40,7 +47,11 @@ public final double getCarbon(FurnatorTile blockEntity) {
4047
}
4148

4249
@LuaFunction(mainThread = true)
43-
public final ItemStack getInventory(FurnatorTile blockEntity) {
44-
return blockEntity.getInventory().getStackInSlot(1);
50+
public final Object getInventory(FurnatorTile blockEntity) {
51+
ItemStack stack = blockEntity.getInventory().getStackInSlot(1);
52+
if (stack.isEmpty()) {
53+
return null;
54+
}
55+
return LuaConverter.stackToObject(stack);
4556
}
4657
}

src/main/java/de/srendi/advancedperipherals/common/addons/powah/ReactorIntegration.java

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import dan200.computercraft.api.lua.LuaFunction;
44
import de.srendi.advancedperipherals.lib.peripherals.APGenericPeripheral;
5+
import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral;
6+
import de.srendi.advancedperipherals.common.util.LuaConverter;
57
import net.minecraft.world.item.ItemStack;
68
import owmii.powah.block.reactor.ReactorPartTile;
79

@@ -12,6 +14,11 @@ public String getPeripheralType() {
1214
return "uraniniteReactor";
1315
}
1416

17+
@LuaFunction(mainThread = true)
18+
public final String getName() {
19+
return "Uraninite Reactor";
20+
}
21+
1522
@LuaFunction(mainThread = true)
1623
public final boolean isRunning(ReactorPartTile blockEntity) {
1724
if (blockEntity.core().isEmpty())
@@ -71,23 +78,38 @@ public final double getTemperature(ReactorPartTile blockEntity) {
7178
}
7279

7380
@LuaFunction(mainThread = true)
74-
public final ItemStack getInventoryUraninite(ReactorPartTile blockEntity) {
75-
if (blockEntity.core().isEmpty())
76-
return ItemStack.EMPTY;
77-
return blockEntity.core().get().getInventory().getStackInSlot(1);
81+
public final Object getInventoryUraninite(ReactorPartTile blockEntity) {
82+
if (blockEntity.core().isEmpty()) {
83+
return null;
84+
}
85+
ItemStack stack = blockEntity.core().get().getStack(1);
86+
if (stack.isEmpty()) {
87+
return null;
88+
}
89+
return LuaConverter.stackToObject(stack);
7890
}
7991

8092
@LuaFunction(mainThread = true)
81-
public final ItemStack getInventoryRedstone(ReactorPartTile blockEntity) {
82-
if (blockEntity.core().isEmpty())
83-
return ItemStack.EMPTY;
84-
return blockEntity.core().get().getInventory().getStackInSlot(3);
93+
public final Object getInventoryRedstone(ReactorPartTile blockEntity) {
94+
if (blockEntity.core().isEmpty()) {
95+
return null;
96+
}
97+
ItemStack stack = blockEntity.core().get().getStack(3);
98+
if (stack.isEmpty()) {
99+
return null;
100+
}
101+
return LuaConverter.stackToObject(stack);
85102
}
86103

87104
@LuaFunction(mainThread = true)
88-
public final ItemStack getInventoryCarbon(ReactorPartTile blockEntity) {
89-
if (blockEntity.core().isEmpty())
90-
return ItemStack.EMPTY;
91-
return blockEntity.core().get().getInventory().getStackInSlot(2);
105+
public final Object getInventoryCarbon(ReactorPartTile blockEntity) {
106+
if (blockEntity.core().isEmpty()) {
107+
return null;
108+
}
109+
ItemStack stack = blockEntity.core().get().getStack(2);
110+
if (stack.isEmpty()) {
111+
return null;
112+
}
113+
return LuaConverter.stackToObject(stack);
92114
}
93115
}

src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RefinedStorage.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static ItemStack findStackFromStack(INetwork network, @Nullable ICrafting
5555

5656
public static ItemStack findStackFromFilter(INetwork network, @Nullable ICraftingManager crafting, ItemFilter filter) {
5757
for (StackListEntry<ItemStack> temp : network.getItemStorageCache().getList().getStacks()) {
58-
if (filter.test(temp.getStack().copy()))
58+
if (filter.test(temp.getStack()))
5959
return temp.getStack().copy();
6060
}
6161

@@ -64,7 +64,7 @@ public static ItemStack findStackFromFilter(INetwork network, @Nullable ICraftin
6464

6565
for (ICraftingPattern pattern : crafting.getPatterns()) {
6666
for(ItemStack stack : pattern.getOutputs()) {
67-
if (filter.test(stack.copy()))
67+
if (filter.test(stack))
6868
return stack.copy();
6969
}
7070
}
@@ -78,7 +78,7 @@ public static FluidStack findFluidFromStack(INetwork network, @Nullable ICraftin
7878

7979
public static FluidStack findFluidFromFilter(INetwork network, @Nullable ICraftingManager crafting, FluidFilter filter) {
8080
for (StackListEntry<FluidStack> temp : network.getFluidStorageCache().getList().getStacks()) {
81-
if (filter.test(temp.getStack().copy()))
81+
if (filter.test(temp.getStack()))
8282
return temp.getStack().copy();
8383
}
8484

@@ -165,7 +165,7 @@ public static Object getObjectFromPattern(ICraftingPattern pattern, INetwork net
165165
List<ItemStack> outputsList = pattern.getOutputs();
166166
List<Object> outputs = new ArrayList<>();
167167
for (ItemStack itemStack : outputsList)
168-
outputs.add(getObjectFromStack(itemStack.copy(), network));
168+
outputs.add(getObjectFromStack(itemStack, network));
169169

170170
map.put("outputs", outputs);
171171

@@ -174,15 +174,15 @@ public static Object getObjectFromPattern(ICraftingPattern pattern, INetwork net
174174
for (List<ItemStack> singleInputList : inputList) {
175175
List<Object> inputs1 = new ArrayList<>();
176176
for (ItemStack stack : singleInputList)
177-
inputs1.add(getObjectFromStack(stack.copy(), network));
177+
inputs1.add(getObjectFromStack(stack, network));
178178
inputs.add(inputs1);
179179
}
180180

181181
List<Object> byproducts = new ArrayList<>();
182182
if (!pattern.isProcessing()) {
183183
List<ItemStack> byproductsList = pattern.getByproducts();
184184
for (ItemStack stack : byproductsList)
185-
byproducts.add(getObjectFromStack(stack.copy(), network));
185+
byproducts.add(getObjectFromStack(stack, network));
186186
}
187187

188188
map.put("inputs", inputs);
@@ -228,7 +228,7 @@ public static Map<String, Object> getObjectFromFluid(@Nullable FluidStack fluidS
228228
public static Object getItem(INetwork network, ItemStack item) {
229229
for (ItemStack itemStack : getItems(network)) {
230230
if (itemStack.is(item.getItem()) && Objects.equals(itemStack.getTag(), item.getTag()))
231-
return getObjectFromStack(itemStack.copy(), network);
231+
return getObjectFromStack(itemStack, network);
232232
}
233233
return null;
234234
}

src/main/java/de/srendi/advancedperipherals/common/blocks/blockentities/InventoryManagerEntity.java

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,23 @@
88
import de.srendi.advancedperipherals.common.setup.BlockEntityTypes;
99
import net.minecraft.core.BlockPos;
1010
import net.minecraft.core.Direction;
11+
import net.minecraft.nbt.CompoundTag;
1112
import net.minecraft.network.chat.Component;
1213
import net.minecraft.world.entity.player.Inventory;
1314
import net.minecraft.world.entity.player.Player;
1415
import net.minecraft.world.item.ItemStack;
1516
import net.minecraft.world.level.Level;
1617
import net.minecraft.world.level.block.state.BlockState;
1718
import net.minecraftforge.server.ServerLifecycleHooks;
19+
1820
import org.jetbrains.annotations.NotNull;
1921
import org.jetbrains.annotations.Nullable;
22+
import java.util.UUID;
2023

2124
public class InventoryManagerEntity extends PeripheralBlockEntity<InventoryManagerPeripheral> implements IInventoryBlock<InventoryManagerContainer> {
2225

26+
private UUID owner = null;
27+
2328
public InventoryManagerEntity(BlockPos pos, BlockState state) {
2429
super(BlockEntityTypes.INVENTORY_MANAGER.get(), pos, state);
2530
}
@@ -45,22 +50,48 @@ public boolean canPlaceItemThroughFace(int index, @NotNull ItemStack itemStackIn
4550
return itemStackIn.getItem() instanceof MemoryCardItem;
4651
}
4752

53+
@Override
54+
public void setItem(int index, @NotNull ItemStack stack) {
55+
if (stack.getItem() instanceof MemoryCardItem && stack.hasTag() && stack.getTag().contains("ownerId")) {
56+
UUID owner = stack.getTag().getUUID("ownerId");
57+
this.owner = owner;
58+
stack.getTag().remove("ownerId");
59+
stack.getTag().remove("owner");
60+
} else {
61+
this.owner = null;
62+
}
63+
super.setItem(index, stack);
64+
}
65+
4866
@NotNull
4967
@Override
5068
public Component getDisplayName() {
5169
return Component.translatable("block.advancedperipherals.inventory_manager");
5270
}
5371

72+
@Override
73+
public void load(CompoundTag data) {
74+
if (data.contains("ownerId")) {
75+
this.owner = data.getUUID("ownerId");
76+
}
77+
super.load(data);
78+
// Fresh the memory card for backward compatibility
79+
this.setItem(0, this.getItem(0));
80+
}
81+
82+
@Override
83+
public void saveAdditional(CompoundTag data) {
84+
super.saveAdditional(data);
85+
if (this.owner != null) {
86+
data.putUUID("ownerId", this.owner);
87+
}
88+
}
89+
5490
public Player getOwnerPlayer() {
55-
//Checks if the tile entity has an item in his inventory
56-
if (items.get(0).isEmpty()) return null;
57-
ItemStack stack = items.get(0);
58-
//Checks if the item contains the owner name
59-
if (!stack.getOrCreateTag().contains("owner")) return null;
60-
//Loop through all players and check if the player is online
61-
for (Player entity : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers()) {
62-
if (entity.getName().getString().equals(stack.getOrCreateTag().getString("owner"))) return entity;
91+
if (this.owner == null) {
92+
return null;
6393
}
64-
return null;
94+
Player player = ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayer(this.owner);
95+
return player;
6596
}
6697
}

src/main/java/de/srendi/advancedperipherals/common/configuration/WorldConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class WorldConfig implements IAPConfig {
1010
public final ForgeConfigSpec.BooleanValue enableVillagerStructures;
1111
public final ForgeConfigSpec.BooleanValue givePlayerBookOnJoin;
1212
public final ForgeConfigSpec.IntValue villagerStructureWeight;
13+
public final ForgeConfigSpec.BooleanValue enableWanderingTraderTrades;
1314
private final ForgeConfigSpec configSpec;
1415

1516
public WorldConfig() {
@@ -20,6 +21,7 @@ public WorldConfig() {
2021
enableVillagerStructures = builder.comment("Enable the villager structures for the computer scientist.").define("enableVillagerStructures", true);
2122
givePlayerBookOnJoin = builder.comment("Gives the ap documentation to new players.").define("givePlayerBookOnJoin", true);
2223
villagerStructureWeight = builder.comment("The weight of the villager structures.").defineInRange("villagerStructureWeight", 10, 0, 16000);
24+
enableWanderingTraderTrades = builder.comment("Enable new wandering trader trades.").define("enableWanderingTraderTrades", true);
2325

2426
builder.pop();
2527
configSpec = builder.build();

src/main/java/de/srendi/advancedperipherals/common/items/MemoryCardItem.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import de.srendi.advancedperipherals.common.configuration.APConfig;
44
import de.srendi.advancedperipherals.common.items.base.BaseItem;
55
import de.srendi.advancedperipherals.common.util.EnumColor;
6+
import net.minecraft.nbt.CompoundTag;
67
import net.minecraft.network.chat.Component;
78
import net.minecraft.world.InteractionHand;
89
import net.minecraft.world.InteractionResultHolder;
@@ -28,21 +29,27 @@ public boolean isEnabled() {
2829
@Override
2930
public void appendHoverText(ItemStack stack, @Nullable Level levelIn, List<Component> tooltip, TooltipFlag flagIn) {
3031
super.appendHoverText(stack, levelIn, tooltip, flagIn);
31-
if (stack.getOrCreateTag().contains("owner"))
32-
tooltip.add(EnumColor.buildTextComponent(Component.translatable("item.advancedperipherals.tooltip.memory_card.bound", stack.getOrCreateTag().getString("owner"))));
33-
32+
CompoundTag data = stack.getOrCreateTag();
33+
// TODO <0.8>: remove the owner name field
34+
if (data.contains("ownerId") && data.contains("owner")) {
35+
tooltip.add(EnumColor.buildTextComponent(Component.translatable("item.advancedperipherals.tooltip.memory_card.bound", data.getString("owner"))));
36+
}
3437
}
3538

3639
@Override
3740
public InteractionResultHolder<ItemStack> use(Level worldIn, Player playerIn, InteractionHand handIn) {
3841
if (!worldIn.isClientSide) {
3942
ItemStack stack = playerIn.getItemInHand(handIn);
40-
if (stack.getOrCreateTag().contains("owner")) {
43+
CompoundTag data = stack.getOrCreateTag();
44+
// TODO <0.8>: remove the owner name field
45+
if (data.contains("ownerId") || data.contains("owner")) {
4146
playerIn.displayClientMessage(Component.translatable("text.advancedperipherals.removed_player"), true);
42-
stack.getOrCreateTag().remove("owner");
47+
data.remove("ownerId");
48+
data.remove("owner");
4349
} else {
4450
playerIn.displayClientMessage(Component.translatable("text.advancedperipherals.added_player"), true);
45-
stack.getOrCreateTag().putString("owner", playerIn.getName().getString());
51+
data.putUUID("ownerId", playerIn.getUUID());
52+
data.putString("owner", playerIn.getName().getString());
4653
}
4754
}
4855
return super.use(worldIn, playerIn, handIn);

0 commit comments

Comments
 (0)