Compare commits

..

7 commits

Author SHA1 Message Date
Ell
cb98ef5be1 backport 27aa6809ae 2022-03-30 14:52:27 +02:00
Ell
43bf12924f backport 1c5a3a118d 2022-03-30 14:51:18 +02:00
Ell
58f665452d backport 0228932472 2022-03-30 14:48:51 +02:00
Ell
e3fad2bd6a 1.9.7 2022-03-30 14:46:05 +02:00
Ell
2f75a2c774 backport bf7760c5fb 2022-03-30 14:45:28 +02:00
Ell
9ff65e3b06 backport 8ead508776 2022-03-30 14:43:33 +02:00
Ell
db58a7b105 backport 6a170a1ace 2022-03-30 14:37:16 +02:00
14 changed files with 84 additions and 38 deletions

View file

@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
version = '1.9.6'
version = '1.9.7'
group = 'de.ellpeck.prettypipes' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'PrettyPipes'

View file

@ -38,8 +38,7 @@ public class ItemFilter extends ItemStackHandler {
super(size);
this.stack = stack;
this.pipe = pipe;
if (stack.hasTag())
this.deserializeNBT(stack.getTag().getCompound("filter"));
this.load();
}
public List<Slot> getSlots(int x, int y) {
@ -70,12 +69,13 @@ public class ItemFilter extends ItemStackHandler {
return buttons;
}
public void onButtonPacket(int id) {
public void onButtonPacket(IFilteredContainer menu, int id) {
if (id == 0 && this.canModifyWhitelist) {
this.isWhitelist = !this.isWhitelist;
this.modified = true;
this.save();
} else if (id == 1 && this.canPopulateFromInventories) {
boolean changed = false;
// populate filter from inventories
List<ItemFilter> filters = this.pipe.getFilters();
for (Direction direction : Direction.values()) {
@ -91,12 +91,15 @@ public class ItemFilter extends ItemStackHandler {
// try inserting into ourselves and any filter increase modifiers
for (ItemFilter filter : filters) {
if (ItemHandlerHelper.insertItem(filter, copy, false).isEmpty()) {
changed = true;
filter.save();
break;
}
}
}
}
if (changed)
menu.onFilterPopulated();
}
}
@ -126,6 +129,11 @@ public class ItemFilter extends ItemStackHandler {
}
}
public void load() {
if (this.stack.hasTag())
this.deserializeNBT(this.stack.getTag().getCompound("filter"));
}
@Override
public CompoundNBT serializeNBT() {
CompoundNBT nbt = super.serializeNBT();
@ -154,6 +162,10 @@ public class ItemFilter extends ItemStackHandler {
}
public interface IFilteredContainer {
ItemFilter getFilter();
default void onFilterPopulated() {}
}
}

View file

@ -464,13 +464,13 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundNBT>, GraphL
return ret;
}
public void clearDestinationCache(BlockPos... nodes) {
public void clearDestinationCache(List<BlockPos> nodes) {
this.startProfile("clear_node_cache");
// remove caches for the nodes
for (BlockPos node : nodes)
this.nodeToConnectedNodes.keySet().remove(node);
// remove caches that contain the nodes as a destination
this.nodeToConnectedNodes.values().removeIf(cached -> Arrays.stream(nodes).anyMatch(cached::contains));
this.nodeToConnectedNodes.values().removeIf(cached -> nodes.stream().anyMatch(cached::contains));
this.endProfile();
}
@ -493,12 +493,12 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundNBT>, GraphL
@Override
public void edgeAdded(GraphEdgeChangeEvent<BlockPos, NetworkEdge> e) {
this.clearDestinationCache(e.getEdgeSource(), e.getEdgeTarget());
this.clearDestinationCache(e.getEdge().pipes);
}
@Override
public void edgeRemoved(GraphEdgeChangeEvent<BlockPos, NetworkEdge> e) {
this.clearDestinationCache(e.getEdgeSource(), e.getEdgeTarget());
this.clearDestinationCache(e.getEdge().pipes);
}
@Override

View file

@ -2,7 +2,6 @@ package de.ellpeck.prettypipes.packets;
import de.ellpeck.prettypipes.Utility;
import de.ellpeck.prettypipes.items.IModule;
import de.ellpeck.prettypipes.misc.ItemFilter;
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
@ -100,9 +99,8 @@ public class PacketButton {
}
}),
FILTER_CHANGE((pos, data, player) -> {
IFilteredContainer container = (IFilteredContainer) player.openContainer;
ItemFilter filter = container.getFilter();
filter.onButtonPacket(data[0]);
if (player.openContainer instanceof IFilteredContainer)
((IFilteredContainer) player.openContainer).getFilter().onButtonPacket((IFilteredContainer) player.openContainer, data[0]);
}),
STACK_SIZE_MODULE_BUTTON((pos, data, player) -> {
AbstractPipeContainer<?> container = (AbstractPipeContainer<?>) player.openContainer;
@ -114,7 +112,7 @@ public class PacketButton {
}),
CRAFT_TERMINAL_REQUEST((pos, data, player) -> {
CraftingTerminalTileEntity tile = Utility.getTileEntity(CraftingTerminalTileEntity.class, player.world, pos);
tile.requestCraftingItems(player, data[0]);
tile.requestCraftingItems(player, data[0], data[1] > 0);
}),
CANCEL_CRAFTING((pos, data, player) -> {
ItemTerminalTileEntity tile = Utility.getTileEntity(ItemTerminalTileEntity.class, player.world, 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,6 +32,7 @@ public class PacketRequest {
PacketRequest packet = new PacketRequest();
packet.pos = buf.readBlockPos();
packet.stack = buf.readItemStack();
packet.nbtHash = buf.readVarInt();
packet.amount = buf.readVarInt();
return packet;
}
@ -37,6 +40,7 @@ public class PacketRequest {
public static void toBytes(PacketRequest packet, PacketBuffer buf) {
buf.writeBlockPos(packet.pos);
buf.writeItemStack(packet.stack);
buf.writeVarInt(packet.nbtHash);
buf.writeVarInt(packet.amount);
}
@ -48,7 +52,7 @@ public class PacketRequest {
PlayerEntity player = ctx.get().getSender();
ItemTerminalTileEntity tile = Utility.getTileEntity(ItemTerminalTileEntity.class, player.world, 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

@ -180,7 +180,7 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide
if (prio != this.priority) {
this.priority = prio;
// clear the cache so that it's reevaluated based on priority
PipeNetwork.get(this.world).clearDestinationCache(this.pos);
PipeNetwork.get(this.world).clearDestinationCache(Collections.singletonList(this.pos));
}
profiler.endSection();
}

View file

@ -169,8 +169,10 @@ public class CraftingModuleItem extends ModuleItem {
ItemEquality[] equalityTypes = ItemFilter.getEqualityTypes(tile);
int resultAmount = this.getResultAmountPerCraft(module, stack, equalityTypes);
// calculate how many crafting *operations* to do (as opposed to how many *items* to craft)
int requiredCrafts = MathHelper.ceil(stack.getCount() / (float) resultAmount);
int toCraft = Math.min(craftableAmount, requiredCrafts);
int craftableCrafts = MathHelper.ceil(craftableAmount / (float) resultAmount);
int toCraft = Math.min(craftableCrafts, requiredCrafts);
ItemStackHandler input = this.getInput(module);
for (int i = 0; i < input.getSlots(); i++) {

View file

@ -35,4 +35,11 @@ public class FilterModuleContainer extends AbstractPipeContainer<FilterModuleIte
public ItemFilter getFilter() {
return this.filter;
}
@Override
public void onFilterPopulated() {
// reload the filter so that it displays correctly on the client
this.filter.load();
}
}

View file

@ -1,9 +1,6 @@
package de.ellpeck.prettypipes.pressurizer;
import de.ellpeck.prettypipes.Utility;
import de.ellpeck.prettypipes.pipe.ConnectionType;
import de.ellpeck.prettypipes.pipe.IPipeConnectable;
import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.ContainerBlock;
@ -15,7 +12,6 @@ import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
@ -28,6 +24,7 @@ import javax.annotation.Nullable;
import java.util.List;
public class PressurizerBlock extends ContainerBlock {
public PressurizerBlock() {
super(Properties.create(Material.ROCK).hardnessAndResistance(3).sound(SoundType.STONE));
}
@ -56,4 +53,17 @@ public class PressurizerBlock extends ContainerBlock {
public void addInformation(ItemStack stack, @Nullable IBlockReader worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
Utility.addTooltip(this.getRegistryName().getPath(), tooltip);
}
@Override
public boolean hasComparatorInputOverride(BlockState state) {
return true;
}
@Override
public int getComparatorInputOverride(BlockState state, World world, BlockPos pos) {
PressurizerTileEntity pipe = Utility.getTileEntity(PressurizerTileEntity.class, world, pos);
if (pipe == null)
return 0;
return (int) (pipe.getEnergy() / (float) pipe.getMaxEnergy() * 15);
}
}

View file

@ -7,7 +7,6 @@ import de.ellpeck.prettypipes.network.PipeNetwork;
import de.ellpeck.prettypipes.pipe.ConnectionType;
import de.ellpeck.prettypipes.pipe.IPipeConnectable;
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import de.ellpeck.prettypipes.terminal.containers.ItemTerminalContainer;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
@ -19,12 +18,10 @@ import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.energy.CapabilityEnergy;
@ -136,9 +133,10 @@ public class PressurizerTileEntity extends TileEntity implements INamedContainer
}
}
// send energy update
// send energy update and comparator output
if (this.lastEnergy != this.storage.getEnergyStored() && this.world.getGameTime() % 10 == 0) {
this.lastEnergy = this.storage.getEnergyStored();
this.world.updateComparatorOutputLevel(this.pos, this.getBlockState().getBlock());
Utility.sendTileEntityToClients(this);
}
}

View file

@ -106,7 +106,7 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
}
}
public void requestCraftingItems(PlayerEntity player, int maxAmount) {
public void requestCraftingItems(PlayerEntity player, int maxAmount, boolean force) {
PipeTileEntity pipe = this.getConnectedPipe();
if (pipe == null)
return;
@ -117,7 +117,10 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
int lowestAvailable = getAvailableCrafts(pipe, this.craftItems.getSlots(), i -> ItemHandlerHelper.copyStackWithSize(this.getRequestedCraftItem(i), 1), this::isGhostItem, s -> {
NetworkItem 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)
@ -128,9 +131,11 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
continue;
requested = requested.copy();
requested.setCount(lowestAvailable);
this.requestItemImpl(requested, onItemUnavailable(player));
this.requestItemImpl(requested, onItemUnavailable(player, force));
}
player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".sending_ingredients", lowestAvailable).setStyle(Style.EMPTY.setFormatting(TextFormatting.GREEN)), UUID.randomUUID());
} else {
player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".hold_alt"), UUID.randomUUID());
}
network.endProfile();
}

View file

@ -154,15 +154,23 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
}
}
public void requestItem(PlayerEntity player, ItemStack stack) {
public void requestItem(PlayerEntity player, ItemStack stack, int nbtHash) {
PipeNetwork network = PipeNetwork.get(this.world);
network.startProfile("terminal_request_item");
this.updateItems();
int requested = this.requestItemImpl(stack, onItemUnavailable(player));
if (nbtHash != 0) {
ItemStack 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);
}
int requested = this.requestItemImpl(stack, onItemUnavailable(player, false));
if (requested > 0) {
player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".sending", requested, stack.getDisplayName()).setStyle(Style.EMPTY.setFormatting(TextFormatting.GREEN)), UUID.randomUUID());
} else {
onItemUnavailable(player).accept(stack);
onItemUnavailable(player, false).accept(stack);
}
network.endProfile();
}
@ -313,7 +321,11 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
return Pair.of(requests, remain);
}
public static Consumer<ItemStack> onItemUnavailable(PlayerEntity player) {
return s -> player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".not_found", s.getDisplayName()).setStyle(Style.EMPTY.setFormatting(TextFormatting.RED)), UUID.randomUUID());
public static Consumer<ItemStack> onItemUnavailable(PlayerEntity player, boolean ignore) {
return s -> {
if (ignore)
return;
player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".not_found", s.getDisplayName()).setStyle(Style.EMPTY.setFormatting(TextFormatting.RED)), UUID.randomUUID());
};
}
}

View file

@ -1,16 +1,11 @@
package de.ellpeck.prettypipes.terminal.containers;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import de.ellpeck.prettypipes.PrettyPipes;
import de.ellpeck.prettypipes.packets.PacketButton;
import de.ellpeck.prettypipes.packets.PacketHandler;
import de.ellpeck.prettypipes.packets.PacketRequest;
import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
@ -19,6 +14,7 @@ import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
public class CraftingTerminalGui extends ItemTerminalGui {
private static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/crafting_terminal.png");
private Button requestButton;
@ -32,7 +28,8 @@ public class CraftingTerminalGui extends ItemTerminalGui {
super.init();
this.requestButton = this.addButton(new Button(this.guiLeft + 8, this.guiTop + 100, 50, 20, new TranslationTextComponent("info." + PrettyPipes.ID + ".request"), button -> {
int amount = requestModifier();
PacketHandler.sendToServer(new PacketButton(this.container.tile.getPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount));
int force = hasAltDown() ? 1 : 0;
PacketHandler.sendToServer(new PacketButton(this.container.tile.getPos(), 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",