resolved all todos (untested though oof)

This commit is contained in:
Ell 2021-12-02 22:00:00 +01:00
parent 1d9c22cb0a
commit ae5128971c
9 changed files with 130 additions and 94 deletions

View file

@ -78,6 +78,6 @@ public class ItemTerminalWidget extends AbstractWidget {
@Override
public void updateNarration(NarrationElementOutput output) {
// TODO narration
this.defaultButtonNarrationText(output);
}
}

View file

@ -20,6 +20,8 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
@ -297,6 +299,12 @@ public class PipeBlock extends BaseEntityBlock {
return RenderShape.MODEL;
}
@org.jetbrains.annotations.Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
return createTickerHelper(type, Registry.pipeBlockEntity, PipeBlockEntity::tick);
}
public static void dropItems(Level worldIn, BlockPos pos, Player player) {
var tile = Utility.getBlockEntity(PipeBlockEntity.class, worldIn, pos);
if (tile != null) {

View file

@ -28,6 +28,7 @@ import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
@ -143,52 +144,6 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
this.load(pkt.getTag());
}
// TODO tick
/* @Override
public void tick() {
// invalidate our pressurizer reference if it was removed
if (this.pressurizer != null && this.pressurizer.isRemoved())
this.pressurizer = null;
if (!this.world.isAreaLoaded(this.pos, 1))
return;
IProfiler profiler = this.world.getProfiler();
if (!this.world.isRemote) {
// drop modules here to give a bit of time for blocks to update (iron -> gold chest etc.)
if (this.moduleDropCheck > 0) {
this.moduleDropCheck--;
if (this.moduleDropCheck <= 0 && !this.canHaveModules())
Utility.dropInventory(this, this.modules);
}
profiler.startSection("ticking_modules");
var prio = 0;
var modules = this.streamModules().iterator();
while (modules.hasNext()) {
var module = modules.next();
module.getRight().tick(module.getLeft(), this);
prio += module.getRight().getPriority(module.getLeft(), this);
}
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);
}
profiler.endSection();
}
profiler.startSection("ticking_items");
var items = this.getItems();
for (var i = items.size() - 1; i >= 0; i--)
items.get(i).updateInPipe(this);
if (items.size() != this.lastItemAmount) {
this.lastItemAmount = items.size();
this.world.updateComparatorOutputLevel(this.pos, this.getBlockState().getBlock());
}
profiler.endSection();
}*/
public List<IPipeItem> getItems() {
if (this.items == null)
this.items = PipeNetwork.get(this.level).getItemsInPipe(this.worldPosition);
@ -453,4 +408,49 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
return ConnectionType.BLOCKED;
return ConnectionType.CONNECTED;
}
public static void tick(Level level, BlockPos pos, BlockState state, PipeBlockEntity pipe) {
// invalidate our pressurizer reference if it was removed
if (pipe.pressurizer != null && pipe.pressurizer.isRemoved())
pipe.pressurizer = null;
if (!pipe.level.isAreaLoaded(pipe.worldPosition, 1))
return;
var profiler = pipe.level.getProfiler();
if (!pipe.level.isClientSide) {
// drop modules here to give a bit of time for blocks to update (iron -> gold chest etc.)
if (pipe.moduleDropCheck > 0) {
pipe.moduleDropCheck--;
if (pipe.moduleDropCheck <= 0 && !pipe.canHaveModules())
Utility.dropInventory(pipe, pipe.modules);
}
profiler.push("ticking_modules");
var prio = 0;
var modules = pipe.streamModules().iterator();
while (modules.hasNext()) {
var module = modules.next();
module.getRight().tick(module.getLeft(), pipe);
prio += module.getRight().getPriority(module.getLeft(), pipe);
}
if (prio != pipe.priority) {
pipe.priority = prio;
// clear the cache so that it's reevaluated based on priority
PipeNetwork.get(pipe.level).clearDestinationCache(pipe.worldPosition);
}
profiler.pop();
}
profiler.push("ticking_items");
var items = pipe.getItems();
for (var i = items.size() - 1; i >= 0; i--)
items.get(i).updateInPipe(pipe);
if (items.size() != pipe.lastItemAmount) {
pipe.lastItemAmount = items.size();
pipe.level.updateNeighbourForOutputSignal(pipe.worldPosition, pipe.getBlockState().getBlock());
}
profiler.pop();
}
}

View file

@ -1,10 +1,12 @@
package de.ellpeck.prettypipes.pipe;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.BlockPos;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.model.pipeline.ForgeBlockModelRenderer;
@ -33,13 +35,13 @@ public class PipeRenderer implements BlockEntityRenderer<PipeBlockEntity> {
if (tile.cover != null) {
matrixStack.pushPose();
ForgeBlockModelRenderer.enableCaching();
// TODO figure out how to render covers, maybe finally use baked models bleh
/*for (RenderType layer : RenderType.chunkBufferLayers()) {
if (!RenderTypeLookup.canRenderInLayer(tile.cover, layer))
var renderer = Minecraft.getInstance().getBlockRenderer();
for (var layer : RenderType.chunkBufferLayers()) {
if (!ItemBlockRenderTypes.canRenderInLayer(tile.cover, layer))
continue;
ForgeHooksClient.setRenderType(layer);
Minecraft.getInstance().getBlockRenderer().renderBatched(tile.cover,tile.getBlockPos(),null, matrixStack,null, light, overlay, EmptyModelData.INSTANCE);
}*/
renderer.getModelRenderer().tesselateBlock(tile.getLevel(), renderer.getBlockModel(tile.cover), tile.cover, tile.getBlockPos(), matrixStack, source.getBuffer(layer), true, new Random(), tile.cover.getSeed(tile.getBlockPos()), overlay);
}
ForgeHooksClient.setRenderType(null);
ForgeBlockModelRenderer.clearCache();
matrixStack.popPose();

View file

@ -1,6 +1,8 @@
package de.ellpeck.prettypipes.pressurizer;
import de.ellpeck.prettypipes.Registry;
import de.ellpeck.prettypipes.Utility;
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
@ -15,6 +17,8 @@ import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
@ -55,4 +59,10 @@ public class PressurizerBlock extends BaseEntityBlock {
public void appendHoverText(ItemStack stack, @Nullable BlockGetter worldIn, List<Component> tooltip, TooltipFlag flagIn) {
Utility.addTooltip(this.getRegistryName().getPath(), tooltip);
}
@org.jetbrains.annotations.Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
return level.isClientSide ? null : createTickerHelper(type, Registry.pressurizerBlockEntity, PressurizerBlockEntity::tick);
}
}

View file

@ -2,6 +2,8 @@ package de.ellpeck.prettypipes.pressurizer;
import de.ellpeck.prettypipes.PrettyPipes;
import de.ellpeck.prettypipes.Registry;
import de.ellpeck.prettypipes.Utility;
import de.ellpeck.prettypipes.network.PipeNetwork;
import de.ellpeck.prettypipes.pipe.ConnectionType;
import de.ellpeck.prettypipes.pipe.IPipeConnectable;
import net.minecraft.core.BlockPos;
@ -16,6 +18,7 @@ import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.capabilities.Capability;
@ -110,36 +113,32 @@ public class PressurizerBlockEntity extends BlockEntity implements MenuProvider,
this.lazyThis.invalidate();
}
// TODO tick
/*@Override
public void tick() {
if (this.world.isRemote)
return;
@Override
public ConnectionType getConnectionType(BlockPos pipePos, Direction direction) {
return ConnectionType.CONNECTED;
}
public static void tick(Level level, BlockPos pos, BlockState state, PressurizerBlockEntity pressurizer) {
// notify pipes in network about us
if (this.world.getGameTime() % 10 == 0) {
PipeNetwork network = PipeNetwork.get(this.world);
for (Direction dir : Direction.values()) {
BlockPos offset = this.pos.offset(dir);
for (BlockPos node : network.getOrderedNetworkNodes(offset)) {
if (!this.world.isBlockLoaded(node))
if (pressurizer.level.getGameTime() % 10 == 0) {
var network = PipeNetwork.get(pressurizer.level);
for (var dir : Direction.values()) {
var offset = pressurizer.worldPosition.relative(dir);
for (var node : network.getOrderedNetworkNodes(offset)) {
if (!pressurizer.level.isLoaded(node))
continue;
PipeBlockEntity pipe = network.getPipe(node);
var pipe = network.getPipe(node);
if (pipe != null)
pipe.pressurizer = this;
pipe.pressurizer = pressurizer;
}
}
}
// send energy update
if (this.lastEnergy != this.storage.getEnergyStored() && this.world.getGameTime() % 10 == 0) {
this.lastEnergy = this.storage.getEnergyStored();
Utility.sendBlockEntityToClients(this);
if (pressurizer.lastEnergy != pressurizer.storage.getEnergyStored() && pressurizer.level.getGameTime() % 10 == 0) {
pressurizer.lastEnergy = pressurizer.storage.getEnergyStored();
Utility.sendBlockEntityToClients(pressurizer);
}
}*/
@Override
public ConnectionType getConnectionType(BlockPos pipePos, Direction direction) {
return ConnectionType.CONNECTED;
}
private static class ModifiableEnergyStorage extends EnergyStorage {

View file

@ -1,7 +1,11 @@
package de.ellpeck.prettypipes.terminal;
import de.ellpeck.prettypipes.Registry;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
public class CraftingTerminalBlock extends ItemTerminalBlock {
@ -11,4 +15,9 @@ public class CraftingTerminalBlock extends ItemTerminalBlock {
return new CraftingTerminalBlockEntity(pos, state);
}
@org.jetbrains.annotations.Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
return createTickerHelper(type, Registry.craftingTerminalBlockEntity, ItemTerminalBlockEntity::tick);
}
}

View file

@ -1,5 +1,6 @@
package de.ellpeck.prettypipes.terminal;
import de.ellpeck.prettypipes.Registry;
import de.ellpeck.prettypipes.Utility;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
@ -17,6 +18,8 @@ import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.BlockHitResult;
@ -75,4 +78,11 @@ public class ItemTerminalBlock extends BaseEntityBlock {
public void appendHoverText(ItemStack stack, @Nullable BlockGetter worldIn, List<Component> tooltip, TooltipFlag flagIn) {
Utility.addTooltip(this.getRegistryName().getPath(), tooltip);
}
@org.jetbrains.annotations.Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
return createTickerHelper(type, Registry.itemTerminalBlockEntity, ItemTerminalBlockEntity::tick);
}
}

View file

@ -64,44 +64,42 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
this(Registry.itemTerminalBlockEntity, pos, state);
}
// TODO tick
/* @Override
public void tick() {
if (this.level.isRemote)
public static void tick(Level level, BlockPos pos, BlockState state, ItemTerminalBlockEntity terminal) {
if (terminal.level.isClientSide)
return;
PipeNetwork network = PipeNetwork.get(this.level);
PipeBlockEntity pipe = this.getConnectedPipe();
var network = PipeNetwork.get(terminal.level);
var pipe = terminal.getConnectedPipe();
if (pipe == null)
return;
boolean update = false;
int interval = pipe.pressurizer != null ? 2 : 10;
if (this.level.getGameTime() % interval == 0) {
for (int i = 6; i < 12; i++) {
ItemStack extracted = this.items.extractItem(i, Integer.MAX_VALUE, true);
var update = false;
var interval = pipe.pressurizer != null ? 2 : 10;
if (terminal.level.getGameTime() % interval == 0) {
for (var i = 6; i < 12; i++) {
var extracted = terminal.items.extractItem(i, Integer.MAX_VALUE, true);
if (extracted.isEmpty())
continue;
ItemStack remain = network.routeItem(pipe.getPos(), this.pos, extracted, true);
var remain = network.routeItem(pipe.getBlockPos(), terminal.getBlockPos(), extracted, true);
if (remain.getCount() == extracted.getCount())
continue;
this.items.extractItem(i, extracted.getCount() - remain.getCount(), false);
terminal.items.extractItem(i, extracted.getCount() - remain.getCount(), false);
break;
}
if (!this.existingRequests.isEmpty()) {
NetworkLock request = this.existingRequests.remove();
if (!terminal.existingRequests.isEmpty()) {
var request = terminal.existingRequests.remove();
network.resolveNetworkLock(request);
network.requestExistingItem(request.location, pipe.getPos(), this.pos, request, request.stack, ItemEquality.NBT);
network.requestExistingItem(request.location, pipe.getBlockPos(), terminal.getBlockPos(), request, request.stack, ItemEquality.NBT);
update = true;
}
}
if (this.level.getGameTime() % 100 == 0 || update) {
PlayerEntity[] lookingPlayers = this.getLookingPlayers();
if (terminal.level.getGameTime() % 100 == 0 || update) {
var lookingPlayers = terminal.getLookingPlayers();
if (lookingPlayers.length > 0)
this.updateItems(lookingPlayers);
terminal.updateItems(lookingPlayers);
}
}*/
}
@Override
public void setRemoved() {