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

Fix issue #106 #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix issue #106 #118

wants to merge 1 commit into from

Conversation

TreeDB
Copy link

@TreeDB TreeDB commented Sep 21, 2015

No description provided.

@ttk2
Copy link

ttk2 commented Sep 21, 2015

how does this approach the fix?

@rourke750
Copy link

Its the redstone that's the issue. I dont think this will fix anything.

@TreeDB
Copy link
Author

TreeDB commented Sep 21, 2015

@ttk2 It checks the blocks on all 4 sides of a pressure plate for openable blocks. If a reinforcement is found and the player doesn't have access to it the event is cancelled preventing access.

@suirad
Copy link

suirad commented Sep 30, 2015

Tested it, this does fix the issue #106.

@CivcraftBot
Copy link

Can one of the admins verify this patch? Type 'ok to test' to test.

@ProgrammerDan
Copy link

My only real concern with the patch is since it's on physical interaction, every player physical interaction will trigger this event (potentially). I haven't tested to see what in all triggers it, so hopefully someone can/will/has and assuage my fears, but this could potentially be a bit of a resource hog if such a check is run too often.

@suirad
Copy link

suirad commented Sep 30, 2015

So would it be better to approach this as a redstone interaction as @rourke750 mentioned?

@ProgrammerDan
Copy link

Can't speak to that, but it would be better to check that the block being interacted with is of the class of interact-able blocks where this fix matters, before checking all the sides. E.g. fail fast, and reduce running time within the method to the minimal set of tests. Make sure that the test likely to discard the largest number of interactions happens first, etc.

@suirad
Copy link

suirad commented Sep 30, 2015

I am working on an alternate implementation.

@suirad
Copy link

suirad commented Sep 30, 2015

Maybe something like this:
https://gist.github.com/suirad/6b8330c824fd999d3560

@ProgrammerDan
Copy link

Significant improvement. Drop the stack frame cost of the function call for the press-able check unless you're using it in multiple places.

Edit: In fact both checks should simply live inside the IF statement, unless we've got motivation to use them elsewhere it's a premature optimization, and introduces an extra frame/context switch cost per execution that we don't need.

@suirad
Copy link

suirad commented Oct 1, 2015

I was thinking the same, but left it there as i was testing for clarity of the gist. I could make a pull for it.

@ProgrammerDan
Copy link

Sounds good!

@TreeDB
Copy link
Author

TreeDB commented Oct 2, 2015

@suirad @ProgrammerDan Would you like me to update this pull request with the changes you have suggested?

@ProgrammerDan
Copy link

That'd be awesome!

@EventHandler
public void onPlayerInteractEvent(PlayerInteractEvent event) {
Block block = event.getClickedBlock();
if ((event.getAction() == Action.PHYSICAL) && (block != null) && (block instanceof PressureSensor)) {
Copy link

Choose a reason for hiding this comment

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

instanceof will return false if the object is null, so you dont need an additional null check here

@suirad
Copy link

suirad commented Oct 5, 2015

@TreeDB Your change looks good.

@ProgrammerDan
Copy link

Seconded, much improved even with just those small changes. Should be good to go; have you tested it locally, @TreeDB ?

@TreeDB
Copy link
Author

TreeDB commented Oct 5, 2015

@ProgrammerDan No

@ttk2
Copy link

ttk2 commented Oct 6, 2015

ok to test

@ttk2
Copy link

ttk2 commented Oct 6, 2015

drat, can't get a build to test it with. @ProgrammerDan think I should merge and throw on Civtest?

@rourke750
Copy link

ok to test

@rourke750
Copy link

@ttk2 lol let me look into that.

@rourke750
Copy link

I think you just did something weird.

@ttk2
Copy link

ttk2 commented Oct 6, 2015

did you put the testing build on Civtest?

@rourke750
Copy link

I did not, citadel is still broken from the other changes. I'll try getting to this later in the week. I might have time later today to fix citadel.

@rourke750
Copy link

ok to test

@ProgrammerDan
Copy link

@Maxopoly @rourke750 any reason you can think of not to include this? Has it been superceded by future changes?

@rourke750
Copy link

I forgot this existed. If it works might as well merge. I dont believe this was fixed anywhere else.

@ProgrammerDan
Copy link

Ok, going to do an omnibus PR w/ database change to new CivModCore standard, I'll tack this on. Will test it then too.

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.

7 participants