Skip to content

Commit

Permalink
perf: ⚡increase performance of [Relicator] (R)
Browse files Browse the repository at this point in the history
Now, instead of searching for [Memory Crystal] in adjascent inventories, there will be special slot for the Memory. This will make idle Replicators require x10 times less CPU time.

https://i.imgur.com/ncPyPc6.png
  • Loading branch information
Krutoy242 committed Jun 11, 2024
1 parent e717176 commit 13dda7b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 82 deletions.
Binary file modified dev/resources/textures/replicator.psd
Binary file not shown.
Binary file modified resources/enigmatica/textures/gui/replicator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion resources/ftbquests/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ q.industrialcraft.induction_furnace.desc=This is an upgraded Electric Furnace. I
q.industrialcraft.advanced_miner.desc=Early tool for automatic mining
q.industrialcraft.scanner.desc=Place items in the Scanner to see how much UU Matter it costs to replicate them.\n\n§4§lThis will destroy the item.
q.industrialcraft.crystal_memory.desc=Item info §nmust§r be put into Memory to work with the replicator.
q.industrialcraft.replicator.desc=Supplied with §cRF§r (not EU) and §5UU Matter§r, this machine replicates items.\n\n§f1.§r Write item on Crystal Memory\n§f2.§r Put Crystal Memory in adjacent inventory (or keep in Scanner)\n§f3.§r Put item with higher UU cost in Replicator\n§f4.§r Supply with RF and Matter
q.industrialcraft.replicator.desc=Supplied with §cRF§r (not EU) and §5UU Matter§r, this machine replicates items.\n\n§f1.§r Write item data to a Crystal Memory\n§f2.§r Insert Crystal Memory in the marked slot\n§f3.§r Place item with higher UU cost in the §ltop slot§r\n§f4.§r Supply RF and UU Matter
q.industrialcraft.iridium_ore.desc=Iridium is an extremely rare material, used for Tools and crafting. It's a great idea to automate the replication of this.\n\nYou can find Iridium Shards in dungeon loot, and the Shards can be compressed into Iridium Ore.
q.industrialcraft.quantum_armor.name=Quantum Armor
q.industrialcraft.quantum_armor.desc=§bThe Quantum Helmet§r keeps the player's food bar and air meter replenished at the cost of EU.\n§bThe Quantum Chestplate§r significantly reduces all incoming damage as well as preventing the user from taking fire damage.\n§bThe Quantum Leggings§r allow the player to sprint at several times the normal sprinting speed (this action, however, rapidly drains both EU and food)\n§bThe Quantum Boots§r prevent fall damage (with depletion of the boots' EU supply) and allow the player to jump ~10 blocks by holding down the boost key (default: Ctrl) and pressing the normal jump key.\nAfter completing this quest, mobs will spawn with this armor set sometimes.
Expand Down
2 changes: 1 addition & 1 deletion resources/ftbquests/lang/ru_ru.lang
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ q.industrialcraft.induction_furnace.desc=Это улучшенная элект
q.industrialcraft.advanced_miner.desc=Ранний инструмент для автоматического майнинга
q.industrialcraft.scanner.desc=Поместите предметы в сканер, чтобы узнать, сколько UU Matter стоит их репликация.\n\n §4 §l Это уничтожит предмет. §0\n\n Есть довольно много дополнительных элементов, которые можно реплицировать в дополнение к обычным.
q.industrialcraft.crystal_memory.desc=Информация о предмете должна быть занесена в память, чтобы работать с репликатором.
q.industrialcraft.replicator.desc=Поставляемый с материалами EU и UU, эта машина копирует предметы. Установите желаемый элемент с помощью Pattern Storage или Crystal Pattern.
q.industrialcraft.replicator.desc=Питаясь от §cRF§r (не EU) и §5UU Материи§r, эта машина реплицирует предметы.\n\n§f1.§r Запишите данные предмета на Кристаллическую Память\n§f2.§r Вставьте Кристаллическую Память в отмеченный слот\n§f3.§r Поместите предмет с более высокой стоимостью UU в §lверхний слот§r\n§f4.§r Подайте RF и UU Материю
q.industrialcraft.iridium_ore.desc=Иридий - чрезвычайно редкий материал, используемый для изготовления инструментов и изготовления предметов. Это отличная идея - автоматизировать репликацию этого.\n\n Вы можете найти осколки иридиума в добыче подземелий, а осколки можно спрессовать в иридиевую руду.
q.industrialcraft.quantum_armor.name=Квантовая броня
q.industrialcraft.quantum_armor.desc=§BКвантовый шлем§r поддерживает запасы еды и воздуха в баре игрока за счет ЕС.\n§bКвантовый нагрудник§r значительно снижает весь входящий урон, а также предотвращает получение пользователем урона от огня.\n§bКвантовый Леггинсы§r позволяют игроку бежать со скоростью, в несколько раз превышающей нормальную скорость спринта (это действие, однако, быстро истощает ЕС и еду)\n§bКвантовые ботинки§r предотвращают урон от падения (при истощении запаса ЕС сапог) и позволяет игроку прыгать ~ 10 блоков, удерживая клавишу ускорения (по умолчанию: Ctrl) и нажимая обычную клавишу перехода.\nПосле завершения этого квеста иногда будут появляться мобы с этим комплектом брони.
Expand Down
2 changes: 1 addition & 1 deletion resources/ftbquests/lang/zh_cn.lang
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ q.industrialcraft.induction_furnace.desc=电炉的升级版。如果你希望它
q.industrialcraft.advanced_miner.desc=早期的自动采矿工具。
q.industrialcraft.scanner.desc=将物品放在这里就能看到复制需要多少UU物质。\n\n§4§l这会摧毁这个物品。§0\n\n除了正常情况下能复制的物品外,还有很多东西也可以复制。
q.industrialcraft.crystal_memory.desc=物品信息必须放入记忆中才能与复制器一起工作。
q.industrialcraft.replicator.desc=提供EU与UU物质,它就能复制物品。用模式储存机或者模式水晶来设定产物。
q.industrialcraft.replicator.desc=使用§cRF§r(非EU)和§5UU物质§r,该机器可以复制物品。\n\n§f1.§r 将物品数据写入晶体存储器\n§f2.§r 将晶体存储器插入指定槽位\n§f3.§r 将成本更高的物品放入§l顶部槽位§r\n§f4.§r 提供RF和UU物质
q.industrialcraft.iridium_ore.desc=铱是一种极为罕见的材料,工具与物品的合成都用得到。最好能自动化复制它。\n\n在地牢的宝箱中可以生成铱碎片,压缩后可以得到铱矿。
q.industrialcraft.quantum_armor.name=量子套装
q.industrialcraft.quantum_armor.desc=§b量子头盔§r消耗EU保持玩家的饱食度与空气度。\n§b量子胸甲§r显著降低受到的伤害,也能阻止受到火焰伤害。\n§b量子护腿§r允许以数倍于正常的速度冲刺(但是会快速消耗EU与饱食度)\n§b量子靴子§r 阻止掉落伤害(代价是消耗靴子的储电量),也能允许在按下推进键(默认:Ctrl)时,跳跃达到10格高度。\n在完成该任务后,怪物生成时偶尔会穿着该套装。
Expand Down
111 changes: 32 additions & 79 deletions scripts/requious/replicator.zs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import mods.requious.MachineVisual;
import mods.requious.SlotVisual;

import scripts.category.uu.getCost;
import scripts.lib.D.D.D_zs;

static TICK_STEP as int = 1;
static ENERGY_USAGE as int = 20000;
Expand Down Expand Up @@ -58,33 +57,37 @@ static catlY as int = 0;
x.setItemSlot(catlX,catlY, ComponentFace.all(), 64)
.setAccess(true,false)
.setHandAccess(true,true)
.setFilter(<*>.only(function (item) { return getCost(item) > 0; }))
// .setFilter(<*>.only(function (item) { return getCost(item) > 0; })) // Filters not working
.setGroup('input');

static diskX as int = 3;
static diskY as int = 2;
x.setItemSlot(diskX, diskY, ComponentFace.all(), 1)
.setAccess(true,true)
.setHandAccess(true,true)
.setGroup('disk');

static upgrX as int = 7;
static upgrY as int = 2;
x.setItemSlot(upgrX,upgrY, ComponentFace.none(), 64)
.setAccess(false,false)
.setHandAccess(true,true)
.setFilter(<ic2:upgrade>)
.setBackground(SlotVisual.create(1,1).addPart(replTexture, 7, 2))
.setGroup('upgrade');
// .setFilter(<ic2:upgrade>)
.setBackground(SlotVisual.create(1,1).addPart(replTexture, 7, 2));

static outX as int = 4;
static outY as int = 4;
x.setItemSlot(outX,outY, ComponentFace.all(), 64)
.setAccess(false,true)
.setHandAccess(false,true)
.setGroup('output');
.setHandAccess(false,true);

static mattX as int = 0;
static mattY as int = 0;
x.setFluidSlot(mattX, mattY, ComponentFace.all(), 16000)
.setAccess(true /* input */, true /* output */)
.setFilter(function (liquid/* as ILiquidStack */) { return liquid.name == 'ic2uu_matter'; })
.setBackground(SlotVisual.create(1,5).addPart(replTexture, /* x */ 0,/* y */ 0))
.setForeground(SlotVisual.create(1,5).addPart(replTexture, /* x */ 10,/* y */ 0))
.setGroup('input');
.setForeground(SlotVisual.create(1,5).addPart(replTexture, /* x */ 10,/* y */ 0));

static powX as int = 8;
static powY as int = 0;
Expand All @@ -100,8 +103,7 @@ x.setEnergySlot(powX, powY, ComponentFace.all(), 2000000000)
1, // width
5, // height
[255,255,255] // rgb
))
.setGroup('input');
));

x.setTextSlot(1,1).setVisual(SlotVisual.create(3,1)).setRenderText('§7%s \n§8%s ', ['goal','buffer']).alignRight();
x.setTextSlot(5,3).setVisual(SlotVisual.create(3,1)).setRenderText(' %s',['error']);
Expand Down Expand Up @@ -146,9 +148,8 @@ function pushErr(m as MachineContainer, reason as string) as void {

function defineVars(m as MachineContainer) as void {
// Skip init if already initialized
if (m.getInteger('face_index') != 0) return;
if (!isNull(m.getString('error'))) return;

m.setInteger('face_index', -1); // Index of face where pattern storage is
m.setString('error', ''); // Error line
m.setInteger('goal', 0); // how much UU need. -1 if just trying to push output
m.setInteger('buffer', 0); // stored UU in internal
Expand Down Expand Up @@ -185,67 +186,16 @@ function getUpgrAmount(m as MachineContainer) as double {
: upgr.amount as double;
}

static facings as IFacing[] = [
IFacing.north(),
IFacing.east(),
IFacing.south(),
IFacing.west(),
IFacing.down(),
IFacing.up(),
] as IFacing[];

function getBlockWithStorage(world as IWorld, pos as IBlockPos) as D_zs {
val block = world.getBlock(pos);
if (isNull(block)) return null; // No block at all
val d = D(block.data);
val nbtPaths = [
'InvSlots.SaveSlot.Contents[0]',
'InvSlots.disk.Contents[0]',
'Items[0]',
] as string[];
for path in nbtPaths {
if (d.getString(path ~ '.id', '') != 'ic2:crystal_memory') continue;
return d.move(path);
}
return null;
}

function findPatternStorage(m as MachineContainer) as D_zs {
// Check previously stored face side
val face = m.getInteger('face_index');
if (face > 0) {
val b = getBlockWithStorage(m.world, m.pos.getOffset(facings[face - 1], 1));
if (!isNull(b)) return b;
}

for i, f in facings {
val b = getBlockWithStorage(m.world, m.pos.getOffset(f, 1));
if (isNull(b)) continue;
m.setInteger('face_index', i + 1);
return b;
}
m.setInteger('face_index', -1);
return null;
}

function getReplicateItem(m as MachineContainer, d as D_zs) as IItemStack {
d.move('tag.Pattern');
if (!d.check(['id','Damage'])) {
pushErr(m, '§3Write data\n§3 to memory');
return null;
}

val item = itemUtils.getItem(
d.getString('id', ''),
d.getString('Damage', '')
);

if (isNull(item)) {
pushErr(m, '§8Unreplicable\n§8 item');
return null;
}

return item;
function getReplicateItem(m as MachineContainer, disk as IItemStack) as IItemStack {
if (
isNull(disk)
|| isNull(disk.tag)
|| isNull(disk.tag.Pattern)
|| isNull(disk.tag.Pattern.id)
|| isNull(disk.tag.Pattern.Damage)
) return null;

return <item:${disk.tag.Pattern.id}:${disk.tag.Pattern.Damage}>;
}

function consumeEnergy(m as MachineContainer, amount as int) as void {
Expand Down Expand Up @@ -358,13 +308,16 @@ function tick(m as MachineContainer) as void {
if (goal > 0) return work(m, tick, upgrAmount, powr);

// ❔ Find what item we should replicate
val ps = findPatternStorage(m);
if (isNull(ps)) {
val disk = m.getItem(diskX, diskY);
if (isNull(disk) || disk.definition.id != 'ic2:crystal_memory') {
m.setItem(displX, displY, null);
return pushErr(m, '§bInsrt Crstl\n§b Memory');
}
val item = getReplicateItem(m, disk);
if (isNull(item)) {
m.setItem(displX, displY, null);
return pushErr(m, '§bPlace adjst.\n§b Storage');
return pushErr(m, '§3Write data\n§3 to memory');
}
val item = getReplicateItem(m, ps);
if (isNull(item)) return m.setItem(displX, displY, null);
m.setItem(displX, displY, item); // Set item is display slot

// 🥼 Check if we can consume catalyst
Expand Down

0 comments on commit 13dda7b

Please sign in to comment.