Skip to content
This repository was archived by the owner on Nov 7, 2023. It is now read-only.

fix: regenerate addressess and update merge state when gate position changes#310

Open
sentialx wants to merge 7 commits intoMrJake222:masterfrom
sentialx:address-regen
Open

fix: regenerate addressess and update merge state when gate position changes#310
sentialx wants to merge 7 commits intoMrJake222:masterfrom
sentialx:address-regen

Conversation

@sentialx
Copy link
Copy Markdown

This PR should fix issues when moving the gate by using mods like WarpDrive, Valkyrien etc.

Nine chevron address stays the same when the gate moves and seven chevron address regenerates.

Fixes #253

@MrJake222
Copy link
Copy Markdown
Owner

Won't it spam StargateNetwork with old addresses not pointing to valid gates? You don't seem to remove old addresses from the mapping.

You can query those with /sgquery command.

@sentialx
Copy link
Copy Markdown
Author

sentialx commented May 17, 2021

My generateAddresses function calls the setGateAddress function which seems to remove the old address:
https://github.com/sentialx/AUNIS/blob/c45f70404750b76da843888da99235b5db017c59/src/main/java/mrjake/aunis/tileentity/stargate/StargateAbstractBaseTile.java#L422

@MrJake222
Copy link
Copy Markdown
Owner

Okay, didn't remember that one

Copy link
Copy Markdown
Owner

@MrJake222 MrJake222 left a comment

Choose a reason for hiding this comment

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

You probably shouldn't do sth like this. Find the cause that's passing null there. Or at least handle it higher.

if (!world.isRemote) {
if (!lastPos.equals(pos)) {
lastPos = pos;
generateAddresses(!hasUpgrade(StargateClassicBaseTile.StargateUpgradeEnum.CHEVRON_UPGRADE));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So if there's no chevron upgrade stargate will reset address after chunk will be unloaded and loaded again? Because lastPos field will be null. Custom stargate address will not work without chevron upgrade

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

What would you recommend to check whether the tile has moved?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Btw, does it actually matter? The address will stay the same, since the generator is using the position as seed.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Slava mentions custom Stargate addresses, so someone using commands won't be happy with those changes.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Maybe save a boolean to NBT like addressOverriddenByCommand or just fixedAddress with a docstring indicating it handles address persistence when used with commands?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ah, I missed that command. I've added lastPos assignment in onLoad, and I think it works now.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Did you check that? With command and with Warp drive or other gate-moving mods?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure about that. I think now code inside !lastPos.equals(pos) condition will not be called at all. Because position will be set in onLoad method after TileEntity creation and it's not possible that this position will not be equal to the current gate position

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

That's what I'm thinking. onLoad executes before update and whole effort of making this mod WarpDrive compatible is worthless.


// --------------------------------------------------------------------------------
// Dialing
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's recommended to do code optimisations in different commits/PRs. Because it's a bit harder to review PR with this

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I tried to keep these files as they were, but IntelliJ doesn't have an option to disable formatting on save, sorry for that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes it does. If you're making commits via Intellij Idea there is checkmark Do you want to optimise code before commit?. And there's no automatic optimisations on save unless you turned this on by yourself. Check IDE settings and look at this checkmark on commit

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm not doing commits via intellij, but it's formatting on save, which doesn't seem to have an option to disable that.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I've read there is a macro bound to Ctrl+S by default in intellij

}

// If the gate has already been merged, there is no need to merge it again.
// However, when the gate position changes, the members base pos should be updated as well.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

when the gate position changes
But it will be updated every time when updateMergeState will be called with (shouldBeMerged && this.isMerged) == true. Should be fine anyway? :I
Also you can move this stuff higher probably (above if (!shouldBeMerged) condition, line 1029)

Copy link
Copy Markdown
Author

@sentialx sentialx May 17, 2021

Choose a reason for hiding this comment

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

But it will be updated every time when updateMergeState will be called with (shouldBeMerged && this.isMerged) == true. Should be fine anyway? :I

If that's the case, this means that the gate changed its position. There is no other code path that could trigger the if statement.

address.generate(random);
}

this.setGateAddress(symbolType, address);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Address might be null

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Also there is so much code stripped of this method compared to the original code from onLoad

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah beacause it was basically setGateAddress repeated.

@HaleonGoemea
Copy link
Copy Markdown

I would be willing to test, but idk how to turn this into a .class file. I have figured out that's what I need to do, but it always errors.

I apologize if it's rude to comment here, and will delete if so

@MrJake222
Copy link
Copy Markdown
Owner

I would be willing to test, but idk how to turn this into a .class file. I have figured out that's what I need to do, but it always errors.

I apologize if it's rude to comment here, and will delete if so

Run ./gradlew build and search in build/libs for a .jar file.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warpdrive compatibility

4 participants