Skip to content

Commit

Permalink
Merge branch 'dev/1.19.2' into dev/1.20.1
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
SirEndii committed Oct 6, 2024
2 parents 23d3b91 + 6888ed5 commit 43f2297
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,10 @@ public final MethodResult getItem(IArguments arguments) throws LuaException {
if (parsedFilter.isEmpty())
return MethodResult.of(null, "EMPTY_FILTER");

return MethodResult.of(AppEngApi.getObjectFromStack(AppEngApi.findAEStackFromFilter(monitor, getCraftingService(), parsedFilter), getCraftingService()));
Pair<Long, AEItemKey> item = AppEngApi.findAEStackFromFilter(monitor, getCraftingService(), parsedFilter);
if (item.getRight() == null && item.getLeft() == 0)
return MethodResult.of(null, "NOT_FOUND");
return MethodResult.of(AppEngApi.getObjectFromStack(item, getCraftingService()));
}

@LuaFunction(mainThread = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public final MethodResult listCraftableItems() {
return notConnected();

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

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

return MethodResult.of(RefinedStorage.getObjectFromStack(RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft()), getNetwork()));
ItemStack item = RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft());
if (item.isEmpty())
return MethodResult.of(null, "NOT_FOUND");
return MethodResult.of(RefinedStorage.getObjectFromStack(item, getNetwork()));
}

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

ItemStack stack = RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft());
if (stack == null)
if (stack.isEmpty())
return MethodResult.of(null, "NOT_CRAFTABLE");

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

FluidStack stack = RefinedStorage.findFluidFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft());
if (stack == null)
if (stack.isEmpty())
return MethodResult.of(null, "NOT_CRAFTABLE");

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

ItemStack stack = RefinedStorage.findStackFromFilter(getNetwork(), getNetwork().getCraftingManager(), filter.getLeft());
if (stack == null)
if (stack.isEmpty())
return MethodResult.of(null, "NOT_CRAFTABLE");

for (ICraftingTask task : getNetwork().getCraftingManager().getTasks()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public final MethodResult useOnAnimal(@NotNull IArguments arguments) throws LuaE
if (automataCore.hasAttribute(AutomataCorePeripheral.ATTR_STORING_TOOL_DURABILITY))
selectedTool.setDamageValue(previousDamageValue);

return MethodResult.of(true, result.toString());
return MethodResult.of(result.consumesAction(), result.toString());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final MethodResult feedSoul() {

InteractionResult result = owner.withPlayer(APFakePlayer::useOnEntity);
automataCore.addRotationCycle(3);
return MethodResult.of(true, result.toString());
return MethodResult.of(result.consumesAction(), result.toString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import dan200.computercraft.api.lua.LuaFunction;
import de.srendi.advancedperipherals.lib.peripherals.APGenericPeripheral;
import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral;
import de.srendi.advancedperipherals.common.util.LuaConverter;
import net.minecraft.world.item.ItemStack;
import owmii.powah.block.furnator.FurnatorTile;

Expand All @@ -12,6 +14,11 @@ public String getPeripheralType() {
return "furnator";
}

@LuaFunction(mainThread = true)
public final String getName() {
return "Furnator";
}

@LuaFunction(mainThread = true)
public final boolean isBurning(FurnatorTile blockEntity) {
return blockEntity.isBurning();
Expand Down Expand Up @@ -40,7 +47,11 @@ public final double getCarbon(FurnatorTile blockEntity) {
}

@LuaFunction(mainThread = true)
public final ItemStack getInventory(FurnatorTile blockEntity) {
return blockEntity.getInventory().getStackInSlot(1);
public final Object getInventory(FurnatorTile blockEntity) {
ItemStack stack = blockEntity.getInventory().getStackInSlot(1);
if (stack.isEmpty()) {
return null;
}
return LuaConverter.stackToObject(stack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import dan200.computercraft.api.lua.LuaFunction;
import de.srendi.advancedperipherals.lib.peripherals.APGenericPeripheral;
import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral;
import de.srendi.advancedperipherals.common.util.LuaConverter;
import net.minecraft.world.item.ItemStack;
import owmii.powah.block.reactor.ReactorPartTile;

Expand All @@ -12,6 +14,11 @@ public String getPeripheralType() {
return "uraniniteReactor";
}

@LuaFunction(mainThread = true)
public final String getName() {
return "Uraninite Reactor";
}

@LuaFunction(mainThread = true)
public final boolean isRunning(ReactorPartTile blockEntity) {
if (blockEntity.core().isEmpty())
Expand Down Expand Up @@ -71,23 +78,38 @@ public final double getTemperature(ReactorPartTile blockEntity) {
}

@LuaFunction(mainThread = true)
public final ItemStack getInventoryUraninite(ReactorPartTile blockEntity) {
if (blockEntity.core().isEmpty())
return ItemStack.EMPTY;
return blockEntity.core().get().getInventory().getStackInSlot(1);
public final Object getInventoryUraninite(ReactorPartTile blockEntity) {
if (blockEntity.core().isEmpty()) {
return null;
}
ItemStack stack = blockEntity.core().get().getStack(1);
if (stack.isEmpty()) {
return null;
}
return LuaConverter.stackToObject(stack);
}

@LuaFunction(mainThread = true)
public final ItemStack getInventoryRedstone(ReactorPartTile blockEntity) {
if (blockEntity.core().isEmpty())
return ItemStack.EMPTY;
return blockEntity.core().get().getInventory().getStackInSlot(3);
public final Object getInventoryRedstone(ReactorPartTile blockEntity) {
if (blockEntity.core().isEmpty()) {
return null;
}
ItemStack stack = blockEntity.core().get().getStack(3);
if (stack.isEmpty()) {
return null;
}
return LuaConverter.stackToObject(stack);
}

@LuaFunction(mainThread = true)
public final ItemStack getInventoryCarbon(ReactorPartTile blockEntity) {
if (blockEntity.core().isEmpty())
return ItemStack.EMPTY;
return blockEntity.core().get().getInventory().getStackInSlot(2);
public final Object getInventoryCarbon(ReactorPartTile blockEntity) {
if (blockEntity.core().isEmpty()) {
return null;
}
ItemStack stack = blockEntity.core().get().getStack(2);
if (stack.isEmpty()) {
return null;
}
return LuaConverter.stackToObject(stack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static ItemStack findStackFromStack(INetwork network, @Nullable ICrafting

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

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

for (ICraftingPattern pattern : crafting.getPatterns()) {
for(ItemStack stack : pattern.getOutputs()) {
if (filter.test(stack.copy()))
if (filter.test(stack))
return stack.copy();
}
}
Expand All @@ -78,7 +78,7 @@ public static FluidStack findFluidFromStack(INetwork network, @Nullable ICraftin

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

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

map.put("outputs", outputs);

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

List<Object> byproducts = new ArrayList<>();
if (!pattern.isProcessing()) {
List<ItemStack> byproductsList = pattern.getByproducts();
for (ItemStack stack : byproductsList)
byproducts.add(getObjectFromStack(stack.copy(), network));
byproducts.add(getObjectFromStack(stack, network));
}

map.put("inputs", inputs);
Expand Down Expand Up @@ -228,7 +228,7 @@ public static Map<String, Object> getObjectFromFluid(@Nullable FluidStack fluidS
public static Object getItem(INetwork network, ItemStack item) {
for (ItemStack itemStack : getItems(network)) {
if (itemStack.is(item.getItem()) && Objects.equals(itemStack.getTag(), item.getTag()))
return getObjectFromStack(itemStack.copy(), network);
return getObjectFromStack(itemStack, network);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@
import de.srendi.advancedperipherals.common.setup.BlockEntityTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.server.ServerLifecycleHooks;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;

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

private UUID owner = null;

public InventoryManagerEntity(BlockPos pos, BlockState state) {
super(BlockEntityTypes.INVENTORY_MANAGER.get(), pos, state);
}
Expand All @@ -45,22 +50,48 @@ public boolean canPlaceItemThroughFace(int index, @NotNull ItemStack itemStackIn
return itemStackIn.getItem() instanceof MemoryCardItem;
}

@Override
public void setItem(int index, @NotNull ItemStack stack) {
if (stack.getItem() instanceof MemoryCardItem && stack.hasTag() && stack.getTag().contains("ownerId")) {
UUID owner = stack.getTag().getUUID("ownerId");
this.owner = owner;
stack.getTag().remove("ownerId");
stack.getTag().remove("owner");
} else {
this.owner = null;
}
super.setItem(index, stack);
}

@NotNull
@Override
public Component getDisplayName() {
return Component.translatable("block.advancedperipherals.inventory_manager");
}

@Override
public void load(CompoundTag data) {
if (data.contains("ownerId")) {
this.owner = data.getUUID("ownerId");
}
super.load(data);
// Fresh the memory card for backward compatibility
this.setItem(0, this.getItem(0));
}

@Override
public void saveAdditional(CompoundTag data) {
super.saveAdditional(data);
if (this.owner != null) {
data.putUUID("ownerId", this.owner);
}
}

public Player getOwnerPlayer() {
//Checks if the tile entity has an item in his inventory
if (items.get(0).isEmpty()) return null;
ItemStack stack = items.get(0);
//Checks if the item contains the owner name
if (!stack.getOrCreateTag().contains("owner")) return null;
//Loop through all players and check if the player is online
for (Player entity : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers()) {
if (entity.getName().getString().equals(stack.getOrCreateTag().getString("owner"))) return entity;
if (this.owner == null) {
return null;
}
return null;
Player player = ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayer(this.owner);
return player;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class WorldConfig implements IAPConfig {
public final ForgeConfigSpec.BooleanValue enableVillagerStructures;
public final ForgeConfigSpec.BooleanValue givePlayerBookOnJoin;
public final ForgeConfigSpec.IntValue villagerStructureWeight;
public final ForgeConfigSpec.BooleanValue enableWanderingTraderTrades;
private final ForgeConfigSpec configSpec;

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

builder.pop();
configSpec = builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.srendi.advancedperipherals.common.configuration.APConfig;
import de.srendi.advancedperipherals.common.items.base.BaseItem;
import de.srendi.advancedperipherals.common.util.EnumColor;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
Expand All @@ -28,21 +29,27 @@ public boolean isEnabled() {
@Override
public void appendHoverText(ItemStack stack, @Nullable Level levelIn, List<Component> tooltip, TooltipFlag flagIn) {
super.appendHoverText(stack, levelIn, tooltip, flagIn);
if (stack.getOrCreateTag().contains("owner"))
tooltip.add(EnumColor.buildTextComponent(Component.translatable("item.advancedperipherals.tooltip.memory_card.bound", stack.getOrCreateTag().getString("owner"))));

CompoundTag data = stack.getOrCreateTag();
// TODO <0.8>: remove the owner name field
if (data.contains("ownerId") && data.contains("owner")) {
tooltip.add(EnumColor.buildTextComponent(Component.translatable("item.advancedperipherals.tooltip.memory_card.bound", data.getString("owner"))));
}
}

@Override
public InteractionResultHolder<ItemStack> use(Level worldIn, Player playerIn, InteractionHand handIn) {
if (!worldIn.isClientSide) {
ItemStack stack = playerIn.getItemInHand(handIn);
if (stack.getOrCreateTag().contains("owner")) {
CompoundTag data = stack.getOrCreateTag();
// TODO <0.8>: remove the owner name field
if (data.contains("ownerId") || data.contains("owner")) {
playerIn.displayClientMessage(Component.translatable("text.advancedperipherals.removed_player"), true);
stack.getOrCreateTag().remove("owner");
data.remove("ownerId");
data.remove("owner");
} else {
playerIn.displayClientMessage(Component.translatable("text.advancedperipherals.added_player"), true);
stack.getOrCreateTag().putString("owner", playerIn.getName().getString());
data.putUUID("ownerId", playerIn.getUUID());
data.putString("owner", playerIn.getName().getString());
}
}
return super.use(worldIn, playerIn, handIn);
Expand Down
Loading

0 comments on commit 43f2297

Please sign in to comment.