Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new pumps #84

Merged
merged 2 commits into from
May 6, 2020
Merged

new pumps #84

merged 2 commits into from
May 6, 2020

Conversation

AndreySolodovnikov
Copy link
Contributor

переписал помпы, теперь аналогичны майнерам

@AndreySolodovnikov
Copy link
Contributor Author

сюда случайно попал коммит на новый баланс статов нефтекачек, но это тоже нужно, так что не думаю что проблема

Copy link

@SaloEater SaloEater left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Приношу свои извинения, но очень сильно захотелось так сделать.

@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
super.onPostTick(aBaseMetaTileEntity, aTick);
if (aBaseMetaTileEntity.isServerSide()) {
Copy link

@SaloEater SaloEater Apr 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сделать return, если тикает у клиента.

Suggested change
if (aBaseMetaTileEntity.isServerSide()) {
if (this.isClientSide(aBaseMetaTileEntity)) {
mMaxProgresstime = 0;
return;
}
...
private bool isClientSide(IGregTechTileEntity aBaseMetaTileEntity)
{
return !aBaseMetaTileEntity.isServerSide();
}

public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
super.onPostTick(aBaseMetaTileEntity, aTick);
if (aBaseMetaTileEntity.isServerSide()) {
if (aBaseMetaTileEntity.isAllowedToWork() && aBaseMetaTileEntity.isUniversalEnergyStored(ENERGY[mTier] * (SPEED[mTier] - mProgresstime)) && hasFreeSpace()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Было бы круто вынести в отдельный метод проверки связанные с TE

Suggested change
if (aBaseMetaTileEntity.isAllowedToWork() && aBaseMetaTileEntity.isUniversalEnergyStored(ENERGY[mTier] * (SPEED[mTier] - mProgresstime)) && hasFreeSpace()) {
if (
isTEAllowedToWorkAndStoredEnoughEnergy(aBaseMetaTileEntity)
&& hasFreeSpace()
) {
...
private bool isTEAllowedToWorkAndStoredEnoughEnergy(IGregTechTileEntity aBaseMetaTileEntity)
{
return aBaseMetaTileEntity.isAllowedToWork() && aBaseMetaTileEntity.isUniversalEnergyStored(ENERGY[mTier] * (SPEED[mTier] - mProgresstime));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нет ни малейшего смысла создавать функции которые будут использованы ровно 1 раз, функции нужны для упрощения понимания или для уменьшения количества кода, тут имхо ни того, ни другого

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

К сожалению, с этой стороны есть только мое имхо по которому и я предложил данное изменение.

if (aBaseMetaTileEntity.isServerSide()) {
if (aBaseMetaTileEntity.isAllowedToWork() && aBaseMetaTileEntity.isUniversalEnergyStored(ENERGY[mTier] * (SPEED[mTier] - mProgresstime)) && hasFreeSpace()) {
miningPipe:
if (waitMiningPipe) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно вынести весь цикл в метод и, возможно, избавиться от флага waitMiningPipe.

Suggested change
if (waitMiningPipe) {
if (waitMiningPipe && noMiningPipesInInput()) {
mMaxProgresstime = 0;
return;
}
...
private bool noMiningPipesInInput()
{
for (int i = 0; i < mInputSlotCount; i++) {
ItemStack s = getInputAt(i);
if (s != null && s.getItem() == MINING_PIPE.getItem() && s.stackSize > 0) {
waitMiningPipe = false;
return false;
}
}
return true;
}

@@ -87,7 +87,7 @@ protected void setElectricityStats() {
this.mEfficiencyIncrease = 10000;
int tier = Math.max(1, GT_Utility.getTier(getMaxInputVoltage()));
this.mEUt = -3 * (1 << (tier << 1));
this.mMaxProgresstime = (workState == STATE_AT_BOTTOM ? (1280 * getRangeInChunks() * getRangeInChunks() / (1 << getMinTier())) : 80) / (1 << tier);
this.mMaxProgresstime = (workState == STATE_AT_BOTTOM ? 320 : 80) / (1 << tier);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не может ли быть такого, что эти значения уже вынесены в константы?
В любом случае их лучше вынести в константы.

mMaxProgresstime = 0;
return;
}
if (mProgresstime == SPEED[mTier] - 1) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Выражение SPEED[mTier] - 1 стоит тоже вынести, но его смысл для меня непонятен, поэтому на ваше усмотрение.

Suggested change
if (mProgresstime == SPEED[mTier] - 1) {
if (mProgresstime != SPEED[mTier] - 1) {
return;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это самый банальный счетчик тиков, если поставить =! то будет работать каждый тик за исключением заданного значения => неверная работа

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Обращаю внимание на 68 строку в ченже.

return;
}
if (mProgresstime == SPEED[mTier] - 1) {
if (isPickingPipes) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

После предыдущего ченжа будет логичнее избавиться от return'a и превратить конструкцию в

Suggested change
if (isPickingPipes) {
if (isPickingPipes) {
} else {
}

}
return;
}
if (drillY == 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Выражение drillY == 0 || drillZ > RADIUS[mTier] тоже стоит вынести в отдельную функцию, но название для меня вообще не очевидно, поэтому на ваше усмотрение.

Suggested change
if (drillY == 0) {
if (drillY == 0 || drillZ > RADIUS[mTier]) {
moveOneDown(aBaseMetaTileEntity);
} else {
while (drillZ <= RADIUS[mTier]) {
while (drillX <= RADIUS[mTier]) {
if(workBlock(aBaseMetaTileEntity))
return;
drillX++;
}
drillX = -RADIUS[mTier];
drillZ++;
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

эта проверка совершенно лишняя, помпа не может добывать жидкости на том же уровне на котором находится контроллер

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Объединил оригинальные 80 и 84 строки, чтобы избавиться от return'ов.

if (drillY == 0) {
aBaseMetaTileEntity.disableWorking();
isPickingPipes = false;
} else if (aBaseMetaTileEntity.getBlockOffset(0, drillY, 0) == MINING_PIPE_TIP_BLOCK || aBaseMetaTileEntity.getBlockOffset(0, drillY, 0) == MINING_PIPE_BLOCK) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else if (aBaseMetaTileEntity.getBlockOffset(0, drillY, 0) == MINING_PIPE_TIP_BLOCK || aBaseMetaTileEntity.getBlockOffset(0, drillY, 0) == MINING_PIPE_BLOCK) {
} else if (isPipeBelowTEOnOffset(drillY) {
...
private bool isPipeBelowTEOnOffset(int offset)
{
return aBaseMetaTileEntity.getBlockOffset(0, offset, 0) == MINING_PIPE_TIP_BLOCK
|| aBaseMetaTileEntity.getBlockOffset(0, offset, 0) == MINING_PIPE_BLOCK;
}

}
} else {
ItemData association = GT_OreDictUnificator.getAssociation(new ItemStack(block, 1, blockMeta));
if (association != null && association.mPrefix.toString().startsWith("ore")) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Немного странно, что "ore" за столько лет не вынесли в константу )

Suggested change
if (association != null && association.mPrefix.toString().startsWith("ore")) {
if (doesBlockHaveOreAssociation(block, blockMeta)) {
...
private bool doesBlockHaveOreAssociation(Block block, int blockMeta)
{
ItemData association = GT_OreDictUnificator.getAssociation(new ItemStack(block, 1, blockMeta));
return association != null && association.mPrefix.toString().startsWith("ore");
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а смысл констранты из 3х букв? думаешь это может изменится в будущем ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это скорее nit, просто выразил удивление, что нет стандарта для наименований.

int blockMeta = aBaseMetaTileEntity.getMetaIDOffset(drillX, drillY, drillZ);
if (block instanceof GT_Block_Ores_Abstract) {
TileEntity tTileEntity = getBaseMetaTileEntity().getTileEntityOffset(drillX, drillY, drillZ);
if (tTileEntity != null && tTileEntity instanceof GT_TileEntity_Ores && ((GT_TileEntity_Ores) tTileEntity).mNatural) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (tTileEntity != null && tTileEntity instanceof GT_TileEntity_Ores && ((GT_TileEntity_Ores) tTileEntity).mNatural) {
if (tTileEntity != null && isNaturalOre(tTileEntity )) {
...
private bool isNaturalOre(TileEntity tTileEntity)
{
return tTileEntity instanceof GT_TileEntity_Ores
&& ((GT_TileEntity_Ores) tTileEntity).mNatural;
}

@AndreySolodovnikov AndreySolodovnikov merged commit 03c65a3 into IIA-dev May 6, 2020
@AndreySolodovnikov AndreySolodovnikov deleted the new-pumps branch October 25, 2020 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants