added pipe speed modules

This commit is contained in:
Ellpeck 2020-04-16 23:40:35 +02:00
parent c6d9803f64
commit dc5ce8a26c
24 changed files with 123 additions and 42 deletions

View file

@ -1,18 +1,19 @@
package de.ellpeck.prettypipes;
import de.ellpeck.prettypipes.items.ModuleItem;
import de.ellpeck.prettypipes.pipe.extraction.ExtractionModuleContainer;
import de.ellpeck.prettypipes.pipe.extraction.ExtractionModuleGui;
import de.ellpeck.prettypipes.pipe.extraction.ExtractionModuleItem;
import de.ellpeck.prettypipes.pipe.modules.SpeedModuleItem;
import de.ellpeck.prettypipes.pipe.modules.extraction.ExtractionModuleContainer;
import de.ellpeck.prettypipes.pipe.modules.extraction.ExtractionModuleGui;
import de.ellpeck.prettypipes.pipe.modules.extraction.ExtractionModuleItem;
import de.ellpeck.prettypipes.items.ModuleTier;
import de.ellpeck.prettypipes.items.WrenchItem;
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 de.ellpeck.prettypipes.pipe.modules.containers.*;
import de.ellpeck.prettypipes.pipe.modules.insertion.FilterModuleContainer;
import de.ellpeck.prettypipes.pipe.modules.insertion.FilterModuleGui;
import de.ellpeck.prettypipes.pipe.modules.insertion.FilterModuleItem;
import net.minecraft.block.Block;
import net.minecraft.client.gui.ScreenManager;
import net.minecraft.client.renderer.RenderType;
@ -44,7 +45,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.function.BiFunction;
import java.util.function.Function;
@Mod.EventBusSubscriber(bus = Bus.MOD)
public final class Registry {
@ -83,6 +83,7 @@ public final class Registry {
);
registry.registerAll(createTieredModule("extraction_module", ExtractionModuleItem::new));
registry.registerAll(createTieredModule("filter_module", FilterModuleItem::new));
registry.registerAll(createTieredModule("speed_module", SpeedModuleItem::new));
ForgeRegistries.BLOCKS.getValues().stream()
.filter(b -> b.getRegistryName().getNamespace().equals(PrettyPipes.ID))

View file

@ -1,6 +1,6 @@
package de.ellpeck.prettypipes.items;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import de.ellpeck.prettypipes.pipe.modules.containers.AbstractPipeContainer;
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
@ -22,4 +22,6 @@ public interface IModule {
boolean hasContainer(ItemStack module, PipeTileEntity tile);
AbstractPipeContainer<?> getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex);
float getItemSpeedIncrease(ItemStack module, PipeTileEntity tile);
}

View file

@ -2,7 +2,7 @@ package de.ellpeck.prettypipes.items;
import de.ellpeck.prettypipes.PrettyPipes;
import de.ellpeck.prettypipes.Registry;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import de.ellpeck.prettypipes.pipe.modules.containers.AbstractPipeContainer;
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.resources.I18n;
@ -15,7 +15,6 @@ import net.minecraft.util.text.*;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.client.gui.GuiUtils;
import net.minecraftforge.items.IItemHandler;
import javax.annotation.Nullable;
@ -67,4 +66,9 @@ public abstract class ModuleItem extends Item implements IModule {
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) {
return null;
}
@Override
public float getItemSpeedIncrease(ItemStack module, PipeTileEntity tile) {
return 0;
}
}

View file

@ -28,6 +28,7 @@ import java.util.function.Consumer;
public class PipeItem implements INBTSerializable<CompoundNBT> {
public ItemStack stack;
public float speed;
public float x;
public float y;
public float z;
@ -45,8 +46,9 @@ public class PipeItem implements INBTSerializable<CompoundNBT> {
private boolean dropOnObstruction;
private long lastWorldTick;
public PipeItem(ItemStack stack) {
public PipeItem(ItemStack stack, float speed) {
this.stack = stack;
this.speed = speed;
}
public PipeItem(CompoundNBT nbt) {
@ -79,7 +81,7 @@ public class PipeItem implements INBTSerializable<CompoundNBT> {
return;
this.lastWorldTick = worldTick;
float speed = 0.05F;
float currSpeed = this.speed;
BlockPos myPos = new BlockPos(this.x, this.y, this.z);
if (!myPos.equals(currPipe.getPos()) && (this.reachedDestination() || !myPos.equals(this.startInventory))) {
// we're done with the current pipe, so switch to the next one
@ -102,7 +104,7 @@ public class PipeItem implements INBTSerializable<CompoundNBT> {
}
} else {
double dist = new Vec3d(this.currGoalPos).squareDistanceTo(this.x - 0.5F, this.y - 0.5F, this.z - 0.5F);
if (dist < speed * speed) {
if (dist < this.speed * this.speed) {
// we're past the start of the pipe, so move to the center of the next pipe
PipeTileEntity next = this.getNextTile(currPipe, false);
if (next == null) {
@ -115,7 +117,19 @@ public class PipeItem implements INBTSerializable<CompoundNBT> {
return;
}
} else {
this.currGoalPos = next.getPos();
BlockPos nextPos = next.getPos();
if (dist >= 0.001F) {
// when going around corners, we want to move right up to the corner
Vec3d motion = new Vec3d(this.x - this.lastX, this.y - this.lastY, this.z - this.lastZ);
Vec3d diff = new Vec3d(nextPos.getX() + 0.5F - this.x, nextPos.getY() + 0.5F - this.y, nextPos.getZ() + 0.5F - this.z);
if (motion.crossProduct(diff).length() >= 0.001F) {
currSpeed = (float) Math.sqrt(dist);
} else {
this.currGoalPos = nextPos;
}
} else {
this.currGoalPos = nextPos;
}
}
}
}
@ -126,15 +140,15 @@ public class PipeItem implements INBTSerializable<CompoundNBT> {
Vec3d dist = new Vec3d(this.currGoalPos.getX() + 0.5F - this.x, this.currGoalPos.getY() + 0.5F - this.y, this.currGoalPos.getZ() + 0.5F - this.z);
dist = dist.normalize();
this.x += dist.x * speed;
this.y += dist.y * speed;
this.z += dist.z * speed;
this.x += dist.x * currSpeed;
this.y += dist.y * currSpeed;
this.z += dist.z * currSpeed;
}
private void onPathObstructed(PipeTileEntity currPipe, boolean tryReturn) {
if (!this.dropOnObstruction && tryReturn) {
PipeNetwork network = PipeNetwork.get(currPipe.getWorld());
if (network.routeItemToLocation(currPipe.getPos(), this.destInventory, this.startPipe, this.startInventory, () -> this)) {
if (network.routeItemToLocation(currPipe.getPos(), this.destInventory, this.startPipe, this.startInventory, speed -> this)) {
this.dropOnObstruction = true;
return;
}
@ -176,6 +190,7 @@ public class PipeItem implements INBTSerializable<CompoundNBT> {
public CompoundNBT serializeNBT() {
CompoundNBT nbt = new CompoundNBT();
nbt.put("stack", this.stack.serializeNBT());
nbt.putFloat("speed", this.speed);
nbt.put("start_pipe", NBTUtil.writeBlockPos(this.startPipe));
nbt.put("start_inv", NBTUtil.writeBlockPos(this.startInventory));
nbt.put("dest_pipe", NBTUtil.writeBlockPos(this.destPipe));
@ -196,6 +211,7 @@ public class PipeItem implements INBTSerializable<CompoundNBT> {
@Override
public void deserializeNBT(CompoundNBT nbt) {
this.stack = ItemStack.read(nbt.getCompound("stack"));
this.speed = nbt.getFloat("speed");
this.startPipe = NBTUtil.readBlockPos(nbt.getCompound("start_pipe"));
this.startInventory = NBTUtil.readBlockPos(nbt.getCompound("start_inv"));
this.destPipe = NBTUtil.readBlockPos(nbt.getCompound("dest_pipe"));

View file

@ -34,6 +34,7 @@ import org.jgrapht.traverse.BreadthFirstIterator;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
@ -109,10 +110,10 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundNBT>, GraphL
}
public boolean tryInsertItem(BlockPos startPipePos, BlockPos startInventory, ItemStack stack) {
return this.routeItem(startPipePos, startInventory, stack, () -> new PipeItem(stack));
return this.routeItem(startPipePos, startInventory, stack, speed -> new PipeItem(stack, speed));
}
public boolean routeItem(BlockPos startPipePos, BlockPos startInventory, ItemStack stack, Supplier<PipeItem> itemSupplier) {
public boolean routeItem(BlockPos startPipePos, BlockPos startInventory, ItemStack stack, Function<Float, PipeItem> itemSupplier) {
if (!this.isNode(startPipePos))
return false;
if (!this.world.isBlockLoaded(startPipePos))
@ -133,7 +134,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundNBT>, GraphL
return false;
}
public boolean routeItemToLocation(BlockPos startPipePos, BlockPos startInventory, BlockPos destPipe, BlockPos destInventory, Supplier<PipeItem> itemSupplier) {
public boolean routeItemToLocation(BlockPos startPipePos, BlockPos startInventory, BlockPos destPipe, BlockPos destInventory, Function<Float, PipeItem> itemSupplier) {
if (!this.isNode(startPipePos))
return false;
if (!this.world.isBlockLoaded(startPipePos))
@ -146,7 +147,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundNBT>, GraphL
this.endProfile();
if (path == null)
return false;
PipeItem item = itemSupplier.get();
PipeItem item = itemSupplier.apply(startPipe.getItemSpeed());
item.setDestination(startPipePos, startInventory, destPipe, destInventory, path);
if (!startPipe.items.contains(item))
startPipe.items.add(item);

View file

@ -4,7 +4,7 @@ import de.ellpeck.prettypipes.PrettyPipes;
import de.ellpeck.prettypipes.Registry;
import de.ellpeck.prettypipes.items.IModule;
import de.ellpeck.prettypipes.network.PipeItem;
import de.ellpeck.prettypipes.pipe.containers.MainPipeContainer;
import de.ellpeck.prettypipes.pipe.modules.containers.MainPipeContainer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
@ -122,6 +122,11 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide
return this.streamModules().mapToInt(m -> m.getRight().getPriority(m.getLeft(), this)).max().orElse(0);
}
public float getItemSpeed() {
float speed = (float) this.streamModules().mapToDouble(m -> m.getRight().getItemSpeedIncrease(m.getLeft(), this)).sum();
return 0.05F + speed;
}
public IItemHandler getItemHandler(Direction dir) {
if (!this.isConnected(dir))
return null;
@ -139,7 +144,7 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide
return Arrays.stream(Direction.values()).anyMatch(this::isConnectedInventory);
}
public Stream<Pair<ItemStack, IModule>> streamModules() {
private Stream<Pair<ItemStack, IModule>> streamModules() {
Stream.Builder<Pair<ItemStack, IModule>> builder = Stream.builder();
for (int i = 0; i < this.modules.getSlots(); i++) {
ItemStack stack = this.modules.getStackInSlot(i);

View file

@ -0,0 +1,31 @@
package de.ellpeck.prettypipes.pipe.modules;
import de.ellpeck.prettypipes.items.IModule;
import de.ellpeck.prettypipes.items.ModuleItem;
import de.ellpeck.prettypipes.items.ModuleTier;
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import net.minecraft.item.ItemStack;
public class SpeedModuleItem extends ModuleItem {
private final float speedIncrease;
public SpeedModuleItem(String name, ModuleTier tier) {
super(name);
this.speedIncrease = tier.forTier(0.05F, 0.1F, 0.2F);
}
@Override
public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) {
return !(other instanceof SpeedModuleItem);
}
@Override
public boolean hasContainer(ItemStack module, PipeTileEntity tile) {
return false;
}
@Override
public float getItemSpeedIncrease(ItemStack module, PipeTileEntity tile) {
return this.speedIncrease;
}
}

View file

@ -1,4 +1,4 @@
package de.ellpeck.prettypipes.pipe.containers;
package de.ellpeck.prettypipes.pipe.modules.containers;
import de.ellpeck.prettypipes.Utility;
import de.ellpeck.prettypipes.items.IModule;

View file

@ -1,4 +1,4 @@
package de.ellpeck.prettypipes.pipe.containers;
package de.ellpeck.prettypipes.pipe.modules.containers;
import de.ellpeck.prettypipes.PrettyPipes;
import de.ellpeck.prettypipes.Registry;

View file

@ -1,4 +1,4 @@
package de.ellpeck.prettypipes.pipe.containers;
package de.ellpeck.prettypipes.pipe.modules.containers;
import de.ellpeck.prettypipes.items.IModule;
import net.minecraft.entity.player.PlayerEntity;

View file

@ -1,4 +1,4 @@
package de.ellpeck.prettypipes.pipe.containers;
package de.ellpeck.prettypipes.pipe.modules.containers;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.text.ITextComponent;

View file

@ -1,8 +1,8 @@
package de.ellpeck.prettypipes.pipe.extraction;
package de.ellpeck.prettypipes.pipe.modules.extraction;
import de.ellpeck.prettypipes.misc.ItemFilter;
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import de.ellpeck.prettypipes.pipe.modules.containers.AbstractPipeContainer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.Slot;

View file

@ -1,6 +1,6 @@
package de.ellpeck.prettypipes.pipe.extraction;
package de.ellpeck.prettypipes.pipe.modules.extraction;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
import de.ellpeck.prettypipes.pipe.modules.containers.AbstractPipeGui;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.text.ITextComponent;

View file

@ -1,4 +1,4 @@
package de.ellpeck.prettypipes.pipe.extraction;
package de.ellpeck.prettypipes.pipe.modules.extraction;
import de.ellpeck.prettypipes.Registry;
import de.ellpeck.prettypipes.items.ModuleItem;
@ -7,7 +7,7 @@ import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import de.ellpeck.prettypipes.items.IModule;
import de.ellpeck.prettypipes.items.ModuleTier;
import de.ellpeck.prettypipes.network.PipeNetwork;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import de.ellpeck.prettypipes.pipe.modules.containers.AbstractPipeContainer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;

View file

@ -1,13 +1,12 @@
package de.ellpeck.prettypipes.pipe.insertion;
package de.ellpeck.prettypipes.pipe.modules.insertion;
import de.ellpeck.prettypipes.misc.ItemFilter;
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import de.ellpeck.prettypipes.pipe.modules.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;

View file

@ -1,6 +1,6 @@
package de.ellpeck.prettypipes.pipe.insertion;
package de.ellpeck.prettypipes.pipe.modules.insertion;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
import de.ellpeck.prettypipes.pipe.modules.containers.AbstractPipeGui;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.math.MathHelper;

View file

@ -1,4 +1,4 @@
package de.ellpeck.prettypipes.pipe.insertion;
package de.ellpeck.prettypipes.pipe.modules.insertion;
import de.ellpeck.prettypipes.Registry;
import de.ellpeck.prettypipes.items.IModule;
@ -6,7 +6,7 @@ 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 de.ellpeck.prettypipes.pipe.modules.containers.AbstractPipeContainer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;

View file

@ -6,8 +6,12 @@
"item.prettypipes.low_filter_module": "Low Filter Module",
"item.prettypipes.medium_filter_module": "Medium Filter Module",
"item.prettypipes.high_filter_module": "High Filter Module",
"item.prettypipes.low_speed_module": "Low Speed Increase Module",
"item.prettypipes.medium_speed_module": "Medium Speed Increase Module",
"item.prettypipes.high_speed_module": "High Speed Increase 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",
"info.prettypipes.speed_module": "Increases speed of items exiting adjacent inventories\nSpeed 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_speed_module"
}
}

View file

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

View file

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 B