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: 'maven-publish'
version = '1.12.0'
version = '1.12.1'
group = 'de.ellpeck.prettypipes' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'PrettyPipes'
@ -105,11 +105,11 @@ configurations {
}
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'
compileOnly fg.deobf("mezz.jei:jei-1.18.2:9.4.1.117:api")
runtimeOnly fg.deobf("mezz.jei:jei-1.18.2:9.4.1.117")
compileOnly fg.deobf("mezz.jei:jei-1.18.2:9.5.5.174:api")
runtimeOnly fg.deobf("mezz.jei:jei-1.18.2:9.5.5.174")
// to test the rf requiring and crafting stuff
/* runtimeOnly fg.deobf("curse.maven:powah-352656:3057732")

View file

@ -112,7 +112,7 @@ public class PacketButton {
}),
CRAFT_TERMINAL_REQUEST((pos, data, player) -> {
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) -> {
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level, pos);

View file

@ -14,11 +14,13 @@ public class PacketRequest {
private BlockPos pos;
private ItemStack stack;
private int nbtHash;
private int amount;
public PacketRequest(BlockPos pos, ItemStack stack, int amount) {
this.pos = pos;
this.stack = stack;
this.nbtHash = stack.getTag().hashCode();
this.amount = amount;
}
@ -30,14 +32,15 @@ public class PacketRequest {
var packet = new PacketRequest();
packet.pos = buf.readBlockPos();
packet.stack = buf.readItem();
packet.nbtHash = buf.readVarInt();
packet.amount = buf.readVarInt();
return packet;
}
public static void toBytes(PacketRequest packet, FriendlyByteBuf buf) {
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.writeItemStack(packet.stack, false);
buf.writeItem(packet.stack);
buf.writeVarInt(packet.nbtHash);
buf.writeVarInt(packet.amount);
}
@ -49,7 +52,7 @@ public class PacketRequest {
Player player = ctx.get().getSender();
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level, message.pos);
message.stack.setCount(message.amount);
tile.requestItem(player, message.stack);
tile.requestItem(player, message.stack, message.nbtHash);
}
});
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) {
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) {
pressurizer.lastEnergy = pressurizer.storage.getEnergyStored();
level.updateNeighbourForOutputSignal(pos, state.getBlock());
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();
if (pipe == null)
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 item = this.networkItems.get(s);
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 we're limiting the amount, pretend we only have that amount available
if (maxAmount < lowestAvailable)
@ -127,10 +130,13 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity {
continue;
requested = requested.copy();
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());
}
else{
player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".hold_alt"), UUID.randomUUID());
}
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);
network.startProfile("terminal_request_item");
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) {
player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".sending", requested, stack.getHoverName()).setStyle(Style.EMPTY.applyFormat(ChatFormatting.GREEN)), UUID.randomUUID());
} else {
onItemUnavailable(player).accept(stack);
onItemUnavailable(player, false).accept(stack);
}
network.endProfile();
}
@ -307,7 +315,11 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
return Pair.of(requests, remain);
}
public static Consumer<ItemStack> onItemUnavailable(Player player) {
return s -> player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".not_found", s.getHoverName()).setStyle(Style.EMPTY.applyFormat(ChatFormatting.RED)), UUID.randomUUID());
public static Consumer<ItemStack> onItemUnavailable(Player player, boolean ignore) {
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();
this.requestButton = this.addRenderableWidget(new Button(this.leftPos + 8, this.topPos + 100, 50, 20, new TranslatableComponent("info." + PrettyPipes.ID + ".request"), button -> {
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();
}

View file

@ -72,6 +72,7 @@
"info.prettypipes.limit_to_max_off": "Don't limit to one stack",
"info.prettypipes.request": "Request",
"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_ingredients": "Sending %s sets of ingredients",
"info.prettypipes.order": "Order by %s",