added filter modules

This commit is contained in:
Ellpeck 2020-04-16 21:19:40 +02:00
parent 23462bbe00
commit 592e524153
12 changed files with 135 additions and 5 deletions

View file

@ -10,6 +10,9 @@ import de.ellpeck.prettypipes.network.PipeNetwork;
import de.ellpeck.prettypipes.packets.PacketHandler;
import de.ellpeck.prettypipes.pipe.*;
import de.ellpeck.prettypipes.pipe.containers.*;
import de.ellpeck.prettypipes.pipe.insertion.FilterModuleContainer;
import de.ellpeck.prettypipes.pipe.insertion.FilterModuleGui;
import de.ellpeck.prettypipes.pipe.insertion.FilterModuleItem;
import net.minecraft.block.Block;
import net.minecraft.client.gui.ScreenManager;
import net.minecraft.client.renderer.RenderType;
@ -63,6 +66,7 @@ public final class Registry {
public static ContainerType<MainPipeContainer> pipeContainer;
public static ContainerType<ExtractionModuleContainer> extractionModuleContainer;
public static ContainerType<FilterModuleContainer> filterModuleContainer;
@SubscribeEvent
public static void registerBlocks(RegistryEvent.Register<Block> event) {
@ -78,6 +82,7 @@ public final class Registry {
wrenchItem = new WrenchItem().setRegistryName("wrench")
);
registry.registerAll(createTieredModule("extraction_module", ExtractionModuleItem::new));
registry.registerAll(createTieredModule("filter_module", FilterModuleItem::new));
ForgeRegistries.BLOCKS.getValues().stream()
.filter(b -> b.getRegistryName().getNamespace().equals(PrettyPipes.ID))
@ -95,7 +100,9 @@ public final class Registry {
public static void registerContainer(RegistryEvent.Register<ContainerType<?>> event) {
event.getRegistry().registerAll(
pipeContainer = (ContainerType<MainPipeContainer>) IForgeContainerType.create((windowId, inv, data) -> new MainPipeContainer(pipeContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("pipe"),
extractionModuleContainer = (ContainerType<ExtractionModuleContainer>) IForgeContainerType.create((windowId, inv, data) -> new ExtractionModuleContainer(extractionModuleContainer, windowId, inv.player, data.readBlockPos(), data.readInt())).setRegistryName("extraction_module"));
extractionModuleContainer = (ContainerType<ExtractionModuleContainer>) IForgeContainerType.create((windowId, inv, data) -> new ExtractionModuleContainer(extractionModuleContainer, windowId, inv.player, data.readBlockPos(), data.readInt())).setRegistryName("extraction_module"),
filterModuleContainer = (ContainerType<FilterModuleContainer>) IForgeContainerType.create((windowId, inv, data) -> new FilterModuleContainer(filterModuleContainer, windowId, inv.player, data.readBlockPos(), data.readInt())).setRegistryName("filter_module")
);
}
public static void setup(FMLCommonSetupEvent event) {
@ -128,6 +135,7 @@ public final class Registry {
ScreenManager.registerFactory(pipeContainer, MainPipeGui::new);
ScreenManager.registerFactory(extractionModuleContainer, ExtractionModuleGui::new);
ScreenManager.registerFactory(filterModuleContainer, FilterModuleGui::new);
}
}
}

View file

@ -44,10 +44,8 @@ public class ItemFilter extends ItemStackHandler {
public List<Slot> getSlots(int x, int y) {
List<Slot> slots = new ArrayList<>();
for (int i = 0; i < this.getSlots(); i++) {
slots.add(new SlotFilter(this, i, x, y));
x += 18;
}
for (int i = 0; i < this.getSlots(); i++)
slots.add(new SlotFilter(this, i, x + i % 9 * 18, y + i / 9 * 18));
return slots;
}

View file

@ -0,0 +1,39 @@
package de.ellpeck.prettypipes.pipe.insertion;
import de.ellpeck.prettypipes.misc.ItemFilter;
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.Slot;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import javax.annotation.Nullable;
public class FilterModuleContainer extends AbstractPipeContainer<FilterModuleItem> implements IFilteredContainer {
public ItemFilter filter;
public FilterModuleContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) {
super(type, id, player, pos, moduleIndex);
}
@Override
protected void addSlots() {
this.filter = new ItemFilter(this.module.filterSlots, this.moduleStack);
for (Slot slot : this.filter.getSlots((176 - Math.min(this.module.filterSlots, 9) * 18) / 2 + 1, 17 + 32))
this.addSlot(slot);
}
@Override
public void onContainerClosed(PlayerEntity playerIn) {
super.onContainerClosed(playerIn);
this.filter.save();
}
@Override
public ItemFilter getFilter() {
return this.filter;
}
}

View file

@ -0,0 +1,20 @@
package de.ellpeck.prettypipes.pipe.insertion;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
public class FilterModuleGui extends AbstractPipeGui<FilterModuleContainer> {
public FilterModuleGui(FilterModuleContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
super(screenContainer, inv, titleIn);
}
@Override
protected void init() {
super.init();
for (Widget widget : this.container.filter.getButtons(this.guiLeft + 7, this.guiTop + 17 + 32 + 18 * MathHelper.ceil(this.container.filter.getSlots() / 9F) + 2))
this.addButton(widget);
}
}

View file

@ -0,0 +1,43 @@
package de.ellpeck.prettypipes.pipe.insertion;
import de.ellpeck.prettypipes.Registry;
import de.ellpeck.prettypipes.items.IModule;
import de.ellpeck.prettypipes.items.ModuleItem;
import de.ellpeck.prettypipes.items.ModuleTier;
import de.ellpeck.prettypipes.misc.ItemFilter;
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
public class FilterModuleItem extends ModuleItem {
public final int filterSlots;
public FilterModuleItem(String name, ModuleTier tier) {
super(name);
this.filterSlots = tier.forTier(5, 9, 18);
}
@Override
public boolean canAcceptItem(ItemStack module, PipeTileEntity tile, ItemStack stack) {
ItemFilter filter = new ItemFilter(this.filterSlots, module);
return filter.isAllowed(stack);
}
@Override
public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) {
return !(other instanceof FilterModuleItem);
}
@Override
public boolean hasContainer(ItemStack module, PipeTileEntity tile) {
return true;
}
@Override
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) {
return new FilterModuleContainer(Registry.filterModuleContainer, windowId, player, tile.getPos(), moduleIndex);
}
}

View file

@ -3,7 +3,11 @@
"item.prettypipes.low_extraction_module": "Low Extraction Module",
"item.prettypipes.medium_extraction_module": "Medium Extraction Module",
"item.prettypipes.high_extraction_module": "High Extraction Module",
"item.prettypipes.low_filter_module": "Low Filter Module",
"item.prettypipes.medium_filter_module": "Medium Filter Module",
"item.prettypipes.high_filter_module": "High Filter Module",
"info.prettypipes.extraction_module": "Pulls items from adjacent inventories\nFilters and pull rates vary by tier",
"info.prettypipes.filter_module": "Restricts flow from pipes into adjacent inventories\nFilter amount varies by tier",
"block.prettypipes.pipe": "Pipe",
"itemGroup.prettypipes": "Pretty Pipes",
"container.prettypipes.pipe": "Pipe",

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "prettypipes:item/high_filter_module"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "prettypipes:item/low_filter_module"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "prettypipes:item/medium_filter_module"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 B