Compare commits

..

5 commits

Author SHA1 Message Date
Ell
41bf05a17e 1.12.1 2022-03-30 14:33:24 +02:00
Ell
27aa6809ae added comparator output to the pressurizer
Related to #79
2022-03-30 14:32:40 +02:00
Ell
1c5a3a118d allow holding Alt to request anyway
Closes #118
2022-03-30 14:26:38 +02:00
Ell
0228932472 hash item stack nbt to avoid going over the packet size limit
Closes #120
2022-03-30 14:16:52 +02:00
Ell
9ae2aea70c updated JEI 2022-03-30 14:11:14 +02:00
9 changed files with 55 additions and 18 deletions

View file

@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse' apply plugin: 'eclipse'
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
version = '1.12.0' version = '1.12.1'
group = 'de.ellpeck.prettypipes' // http://maven.apache.org/guides/mini/guide-naming-conventions.html group = 'de.ellpeck.prettypipes' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'PrettyPipes' archivesBaseName = 'PrettyPipes'
@ -105,11 +105,11 @@ configurations {
} }
dependencies { dependencies {
minecraft 'net.minecraftforge:forge:1.18.2-40.0.3' minecraft 'net.minecraftforge:forge:1.18.2-40.0.32'
embed 'org.jgrapht:jgrapht-core:1.5.1' embed 'org.jgrapht:jgrapht-core:1.5.1'
compileOnly fg.deobf("mezz.jei:jei-1.18.2:9.4.1.117:api") compileOnly fg.deobf("mezz.jei:jei-1.18.2:9.5.5.174:api")
runtimeOnly fg.deobf("mezz.jei:jei-1.18.2:9.4.1.117") runtimeOnly fg.deobf("mezz.jei:jei-1.18.2:9.5.5.174")
// to test the rf requiring and crafting stuff // to test the rf requiring and crafting stuff
/* runtimeOnly fg.deobf("curse.maven:powah-352656:3057732") /* runtimeOnly fg.deobf("curse.maven:powah-352656:3057732")

View file

@ -112,7 +112,7 @@ public class PacketButton {
}), }),
CRAFT_TERMINAL_REQUEST((pos, data, player) -> { CRAFT_TERMINAL_REQUEST((pos, data, player) -> {
var tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, player.level, pos); var tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, player.level, pos);
tile.requestCraftingItems(player, data[0]); tile.requestCraftingItems(player, data[0], data[1] > 0);
}), }),
CANCEL_CRAFTING((pos, data, player) -> { CANCEL_CRAFTING((pos, data, player) -> {
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level, pos); var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level, pos);

View file

@ -14,11 +14,13 @@ public class PacketRequest {
private BlockPos pos; private BlockPos pos;
private ItemStack stack; private ItemStack stack;
private int nbtHash;
private int amount; private int amount;
public PacketRequest(BlockPos pos, ItemStack stack, int amount) { public PacketRequest(BlockPos pos, ItemStack stack, int amount) {
this.pos = pos; this.pos = pos;
this.stack = stack; this.stack = stack;
this.nbtHash = stack.getTag().hashCode();
this.amount = amount; this.amount = amount;
} }
@ -30,14 +32,15 @@ public class PacketRequest {
var packet = new PacketRequest(); var packet = new PacketRequest();
packet.pos = buf.readBlockPos(); packet.pos = buf.readBlockPos();
packet.stack = buf.readItem(); packet.stack = buf.readItem();
packet.nbtHash = buf.readVarInt();
packet.amount = buf.readVarInt(); packet.amount = buf.readVarInt();
return packet; return packet;
} }
public static void toBytes(PacketRequest packet, FriendlyByteBuf buf) { public static void toBytes(PacketRequest packet, FriendlyByteBuf buf) {
buf.writeBlockPos(packet.pos); buf.writeBlockPos(packet.pos);
// if we limit the tag here, non-shared data will be omitted, making the requested item not match the stored one buf.writeItem(packet.stack);
buf.writeItemStack(packet.stack, false); buf.writeVarInt(packet.nbtHash);
buf.writeVarInt(packet.amount); buf.writeVarInt(packet.amount);
} }
@ -49,7 +52,7 @@ public class PacketRequest {
Player player = ctx.get().getSender(); Player player = ctx.get().getSender();
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level, message.pos); var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level, message.pos);
message.stack.setCount(message.amount); message.stack.setCount(message.amount);
tile.requestItem(player, message.stack); tile.requestItem(player, message.stack, message.nbtHash);
} }
}); });
ctx.get().setPacketHandled(true); ctx.get().setPacketHandled(true);

View file

@ -65,4 +65,17 @@ public class PressurizerBlock extends BaseEntityBlock {
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) { public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
return level.isClientSide ? null : createTickerHelper(type, Registry.pressurizerBlockEntity, PressurizerBlockEntity::tick); return level.isClientSide ? null : createTickerHelper(type, Registry.pressurizerBlockEntity, PressurizerBlockEntity::tick);
} }
@Override
public boolean hasAnalogOutputSignal(BlockState state) {
return true;
}
@Override
public int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos) {
var pipe = Utility.getBlockEntity(PressurizerBlockEntity.class, world, pos);
if (pipe == null)
return 0;
return (int) (pipe.getEnergy() / (float) pipe.getMaxEnergy() * 15);
}
} }

View file

@ -134,9 +134,10 @@ public class PressurizerBlockEntity extends BlockEntity implements MenuProvider,
} }
} }
// send energy update // send energy update and comparator output
if (pressurizer.lastEnergy != pressurizer.storage.getEnergyStored() && pressurizer.level.getGameTime() % 10 == 0) { if (pressurizer.lastEnergy != pressurizer.storage.getEnergyStored() && pressurizer.level.getGameTime() % 10 == 0) {
pressurizer.lastEnergy = pressurizer.storage.getEnergyStored(); pressurizer.lastEnergy = pressurizer.storage.getEnergyStored();
level.updateNeighbourForOutputSignal(pos, state.getBlock());
Utility.sendBlockEntityToClients(pressurizer); Utility.sendBlockEntityToClients(pressurizer);
} }
} }

View file

@ -105,7 +105,7 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity {
} }
} }
public void requestCraftingItems(Player player, int maxAmount) { public void requestCraftingItems(Player player, int maxAmount, boolean force) {
var pipe = this.getConnectedPipe(); var pipe = this.getConnectedPipe();
if (pipe == null) if (pipe == null)
return; return;
@ -116,7 +116,10 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity {
var lowestAvailable = getAvailableCrafts(pipe, this.craftItems.getSlots(), i -> ItemHandlerHelper.copyStackWithSize(this.getRequestedCraftItem(i), 1), this::isGhostItem, s -> { var lowestAvailable = getAvailableCrafts(pipe, this.craftItems.getSlots(), i -> ItemHandlerHelper.copyStackWithSize(this.getRequestedCraftItem(i), 1), this::isGhostItem, s -> {
var item = this.networkItems.get(s); var item = this.networkItems.get(s);
return item != null ? item.getLocations() : Collections.emptyList(); return item != null ? item.getLocations() : Collections.emptyList();
}, onItemUnavailable(player), new Stack<>(), ItemEquality.NBT); }, onItemUnavailable(player, force), new Stack<>(), ItemEquality.NBT);
// if we're forcing, just pretend we have one available
if (lowestAvailable <= 0 && force)
lowestAvailable = maxAmount;
if (lowestAvailable > 0) { if (lowestAvailable > 0) {
// if we're limiting the amount, pretend we only have that amount available // if we're limiting the amount, pretend we only have that amount available
if (maxAmount < lowestAvailable) if (maxAmount < lowestAvailable)
@ -127,10 +130,13 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity {
continue; continue;
requested = requested.copy(); requested = requested.copy();
requested.setCount(lowestAvailable); requested.setCount(lowestAvailable);
this.requestItemImpl(requested, onItemUnavailable(player)); this.requestItemImpl(requested, onItemUnavailable(player, force));
} }
player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".sending_ingredients", lowestAvailable).setStyle(Style.EMPTY.applyFormat(ChatFormatting.GREEN)), UUID.randomUUID()); player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".sending_ingredients", lowestAvailable).setStyle(Style.EMPTY.applyFormat(ChatFormatting.GREEN)), UUID.randomUUID());
} }
else{
player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".hold_alt"), UUID.randomUUID());
}
network.endProfile(); network.endProfile();
} }

View file

@ -151,15 +151,23 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
} }
} }
public void requestItem(Player player, ItemStack stack) { public void requestItem(Player player, ItemStack stack, int nbtHash) {
var network = PipeNetwork.get(this.level); var network = PipeNetwork.get(this.level);
network.startProfile("terminal_request_item"); network.startProfile("terminal_request_item");
this.updateItems(); this.updateItems();
var requested = this.requestItemImpl(stack, onItemUnavailable(player)); if (nbtHash != 0) {
var filter = stack;
stack = this.networkItems.values().stream()
.map(NetworkItem::asStack)
// don't compare with nbt equality here or the whole hashing thing is pointless
.filter(s -> ItemEquality.compareItems(s, filter) && s.getTag().hashCode() == nbtHash)
.findFirst().orElse(filter);
}
var requested = this.requestItemImpl(stack, onItemUnavailable(player, false));
if (requested > 0) { if (requested > 0) {
player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".sending", requested, stack.getHoverName()).setStyle(Style.EMPTY.applyFormat(ChatFormatting.GREEN)), UUID.randomUUID()); player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".sending", requested, stack.getHoverName()).setStyle(Style.EMPTY.applyFormat(ChatFormatting.GREEN)), UUID.randomUUID());
} else { } else {
onItemUnavailable(player).accept(stack); onItemUnavailable(player, false).accept(stack);
} }
network.endProfile(); network.endProfile();
} }
@ -307,7 +315,11 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
return Pair.of(requests, remain); return Pair.of(requests, remain);
} }
public static Consumer<ItemStack> onItemUnavailable(Player player) { public static Consumer<ItemStack> onItemUnavailable(Player player, boolean ignore) {
return s -> player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".not_found", s.getHoverName()).setStyle(Style.EMPTY.applyFormat(ChatFormatting.RED)), UUID.randomUUID()); return s -> {
if (ignore)
return;
player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".not_found", s.getHoverName()).setStyle(Style.EMPTY.applyFormat(ChatFormatting.RED)), UUID.randomUUID());
};
} }
} }

View file

@ -25,7 +25,8 @@ public class CraftingTerminalGui extends ItemTerminalGui {
super.init(); super.init();
this.requestButton = this.addRenderableWidget(new Button(this.leftPos + 8, this.topPos + 100, 50, 20, new TranslatableComponent("info." + PrettyPipes.ID + ".request"), button -> { this.requestButton = this.addRenderableWidget(new Button(this.leftPos + 8, this.topPos + 100, 50, 20, new TranslatableComponent("info." + PrettyPipes.ID + ".request"), button -> {
var amount = requestModifier(); var amount = requestModifier();
PacketHandler.sendToServer(new PacketButton(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount)); var force = hasAltDown() ? 1 : 0;
PacketHandler.sendToServer(new PacketButton(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount, force));
})); }));
this.tick(); this.tick();
} }

View file

@ -72,6 +72,7 @@
"info.prettypipes.limit_to_max_off": "Don't limit to one stack", "info.prettypipes.limit_to_max_off": "Don't limit to one stack",
"info.prettypipes.request": "Request", "info.prettypipes.request": "Request",
"info.prettypipes.not_found": "%s not found", "info.prettypipes.not_found": "%s not found",
"info.prettypipes.hold_alt": "Hold Alt to request anyway",
"info.prettypipes.sending": "Sending %s %s", "info.prettypipes.sending": "Sending %s %s",
"info.prettypipes.sending_ingredients": "Sending %s sets of ingredients", "info.prettypipes.sending_ingredients": "Sending %s sets of ingredients",
"info.prettypipes.order": "Order by %s", "info.prettypipes.order": "Order by %s",