mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-25 13:08:34 +01:00
Compare commits
No commits in common. "cb98ef5be13aaf1ca30b4a76b35fef9ddeccbe03" and "ae182423c1ada365fb289d4e70d0bce291f8306b" have entirely different histories.
cb98ef5be1
...
ae182423c1
14 changed files with 38 additions and 84 deletions
|
@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
|
|||
apply plugin: 'eclipse'
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
version = '1.9.7'
|
||||
version = '1.9.6'
|
||||
group = 'de.ellpeck.prettypipes' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
archivesBaseName = 'PrettyPipes'
|
||||
|
||||
|
|
|
@ -38,7 +38,8 @@ public class ItemFilter extends ItemStackHandler {
|
|||
super(size);
|
||||
this.stack = stack;
|
||||
this.pipe = pipe;
|
||||
this.load();
|
||||
if (stack.hasTag())
|
||||
this.deserializeNBT(stack.getTag().getCompound("filter"));
|
||||
}
|
||||
|
||||
public List<Slot> getSlots(int x, int y) {
|
||||
|
@ -69,13 +70,12 @@ public class ItemFilter extends ItemStackHandler {
|
|||
return buttons;
|
||||
}
|
||||
|
||||
public void onButtonPacket(IFilteredContainer menu, int id) {
|
||||
public void onButtonPacket(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,15 +91,12 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,11 +126,6 @@ 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();
|
||||
|
@ -162,10 +154,6 @@ public class ItemFilter extends ItemStackHandler {
|
|||
}
|
||||
|
||||
public interface IFilteredContainer {
|
||||
|
||||
ItemFilter getFilter();
|
||||
|
||||
default void onFilterPopulated() {}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -464,13 +464,13 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundNBT>, GraphL
|
|||
return ret;
|
||||
}
|
||||
|
||||
public void clearDestinationCache(List<BlockPos> nodes) {
|
||||
public void clearDestinationCache(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 -> nodes.stream().anyMatch(cached::contains));
|
||||
this.nodeToConnectedNodes.values().removeIf(cached -> Arrays.stream(nodes).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.getEdge().pipes);
|
||||
this.clearDestinationCache(e.getEdgeSource(), e.getEdgeTarget());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void edgeRemoved(GraphEdgeChangeEvent<BlockPos, NetworkEdge> e) {
|
||||
this.clearDestinationCache(e.getEdge().pipes);
|
||||
this.clearDestinationCache(e.getEdgeSource(), e.getEdgeTarget());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,6 +2,7 @@ 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;
|
||||
|
@ -99,8 +100,9 @@ public class PacketButton {
|
|||
}
|
||||
}),
|
||||
FILTER_CHANGE((pos, data, player) -> {
|
||||
if (player.openContainer instanceof IFilteredContainer)
|
||||
((IFilteredContainer) player.openContainer).getFilter().onButtonPacket((IFilteredContainer) player.openContainer, data[0]);
|
||||
IFilteredContainer container = (IFilteredContainer) player.openContainer;
|
||||
ItemFilter filter = container.getFilter();
|
||||
filter.onButtonPacket(data[0]);
|
||||
}),
|
||||
STACK_SIZE_MODULE_BUTTON((pos, data, player) -> {
|
||||
AbstractPipeContainer<?> container = (AbstractPipeContainer<?>) player.openContainer;
|
||||
|
@ -112,7 +114,7 @@ public class PacketButton {
|
|||
}),
|
||||
CRAFT_TERMINAL_REQUEST((pos, data, player) -> {
|
||||
CraftingTerminalTileEntity tile = Utility.getTileEntity(CraftingTerminalTileEntity.class, player.world, pos);
|
||||
tile.requestCraftingItems(player, data[0], data[1] > 0);
|
||||
tile.requestCraftingItems(player, data[0]);
|
||||
}),
|
||||
CANCEL_CRAFTING((pos, data, player) -> {
|
||||
ItemTerminalTileEntity tile = Utility.getTileEntity(ItemTerminalTileEntity.class, player.world, pos);
|
||||
|
|
|
@ -14,13 +14,11 @@ 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;
|
||||
}
|
||||
|
||||
|
@ -32,7 +30,6 @@ 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;
|
||||
}
|
||||
|
@ -40,7 +37,6 @@ 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);
|
||||
}
|
||||
|
||||
|
@ -52,7 +48,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, message.nbtHash);
|
||||
tile.requestItem(player, message.stack);
|
||||
}
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
|
|
|
@ -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(Collections.singletonList(this.pos));
|
||||
PipeNetwork.get(this.world).clearDestinationCache(this.pos);
|
||||
}
|
||||
profiler.endSection();
|
||||
}
|
||||
|
|
|
@ -169,10 +169,8 @@ 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 craftableCrafts = MathHelper.ceil(craftableAmount / (float) resultAmount);
|
||||
int toCraft = Math.min(craftableCrafts, requiredCrafts);
|
||||
int toCraft = Math.min(craftableAmount, requiredCrafts);
|
||||
|
||||
ItemStackHandler input = this.getInput(module);
|
||||
for (int i = 0; i < input.getSlots(); i++) {
|
||||
|
|
|
@ -35,11 +35,4 @@ 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
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;
|
||||
|
@ -12,6 +15,7 @@ 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;
|
||||
|
@ -24,7 +28,6 @@ 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));
|
||||
}
|
||||
|
@ -53,17 +56,4 @@ 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ 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;
|
||||
|
@ -18,10 +19,12 @@ 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;
|
||||
|
@ -133,10 +136,9 @@ public class PressurizerTileEntity extends TileEntity implements INamedContainer
|
|||
}
|
||||
}
|
||||
|
||||
// send energy update and comparator output
|
||||
// send energy update
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
|
|||
}
|
||||
}
|
||||
|
||||
public void requestCraftingItems(PlayerEntity player, int maxAmount, boolean force) {
|
||||
public void requestCraftingItems(PlayerEntity player, int maxAmount) {
|
||||
PipeTileEntity pipe = this.getConnectedPipe();
|
||||
if (pipe == null)
|
||||
return;
|
||||
|
@ -117,10 +117,7 @@ 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, force), new Stack<>(), ItemEquality.NBT);
|
||||
// if we're forcing, just pretend we have one available
|
||||
if (lowestAvailable <= 0 && force)
|
||||
lowestAvailable = maxAmount;
|
||||
}, onItemUnavailable(player), new Stack<>(), ItemEquality.NBT);
|
||||
if (lowestAvailable > 0) {
|
||||
// if we're limiting the amount, pretend we only have that amount available
|
||||
if (maxAmount < lowestAvailable)
|
||||
|
@ -131,11 +128,9 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
|
|||
continue;
|
||||
requested = requested.copy();
|
||||
requested.setCount(lowestAvailable);
|
||||
this.requestItemImpl(requested, onItemUnavailable(player, force));
|
||||
this.requestItemImpl(requested, onItemUnavailable(player));
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -154,23 +154,15 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
|||
}
|
||||
}
|
||||
|
||||
public void requestItem(PlayerEntity player, ItemStack stack, int nbtHash) {
|
||||
public void requestItem(PlayerEntity player, ItemStack stack) {
|
||||
PipeNetwork network = PipeNetwork.get(this.world);
|
||||
network.startProfile("terminal_request_item");
|
||||
this.updateItems();
|
||||
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));
|
||||
int requested = this.requestItemImpl(stack, onItemUnavailable(player));
|
||||
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, false).accept(stack);
|
||||
onItemUnavailable(player).accept(stack);
|
||||
}
|
||||
network.endProfile();
|
||||
}
|
||||
|
@ -321,11 +313,7 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
|||
return Pair.of(requests, remain);
|
||||
}
|
||||
|
||||
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());
|
||||
};
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
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;
|
||||
|
@ -14,7 +19,6 @@ 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;
|
||||
|
||||
|
@ -28,8 +32,7 @@ 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();
|
||||
int force = hasAltDown() ? 1 : 0;
|
||||
PacketHandler.sendToServer(new PacketButton(this.container.tile.getPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount, force));
|
||||
PacketHandler.sendToServer(new PacketButton(this.container.tile.getPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount));
|
||||
}));
|
||||
this.tick();
|
||||
}
|
||||
|
|
|
@ -72,7 +72,6 @@
|
|||
"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",
|
||||
|
|
Loading…
Reference in a new issue