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: make ChangingBlocks case insensitive via BlockUri #15

Merged
merged 8 commits into from Aug 23, 2022

Conversation

jdrueckert
Copy link
Member

@jdrueckert jdrueckert commented Aug 15, 2022

Fixes #14
Depends on MovingBlocks/Terasology#5061

Contains

  • before this PR, a prefab specifying the ChangingBlocks component had to make sure that the keys in the blockFamilyStages map match the string representation of the respective BlockUris including case
    example for a mismatch: PlantPack:Corn1 (as referenced in PlantPack:Corn.prefab) != PlantPack:corn1 (in-game BlockUri of PlantPack:Corn1.block)
  • by sanitizing the reference in the ChangingBlocks component via the BlockUriTypeHandler and comparing it with the in-game BlockUri, the logic becomes case insensitive

How to test

Requires MovingBlocks/Terasology#5062

  1. Start Terasology
  2. Select CoreGameplay and add the PlantPack and ChangingBlocks modules in the Advanced Game Setup (AGS)
  3. Open the in-game console (F1) and execute give corn1
  4. Select the new item in your inventory quickslot bar and right-click to place it on a dirt/grass block
  5. Observe the block being placed successfully

Outstanding before merge

  • identify ChangingBlocks usages other than PlantPack and create follow-up issues to adjust map formatting
    • no further omega usages of ChangingBlocks component

- before this PR, a prefab specifying the `ChangingBlocks` component had to make sure that the keys in the `blockFamilyStages` map match the string representation of the respective `BlockUri`s including case
  example for a mismatch: `PlantPack:Corn1` (as referenced in `PlantPack:Corn.prefab`) != `PlantPack:corn1` (in-game `BlockUri` of `PlantPack:Corn1.block`)
- by sanitizing the reference in the `ChangingBlocks` component via the `SimpleUriTypeHandler` and comparing it with the `SimpleUri` derived from the in-game `BlockUri`, the logic becomes case insensitive
@jdrueckert jdrueckert added Type: Bug Issues reporting and PRs fixing problems Size: S Small effort likely only affecting a single area and requiring little to no research Category: Gameplay Content Requests, Issues and Changes targeting gameplay mechanics and content Category: Crash Requests, Issues and Changes targeting unexpected terminations, segfaults, etc. Status: Needs Testing Requires to be tested in-game Topic: Stabilization Requests, Issues and Changes related to improving stablity and reducing flakyness labels Aug 15, 2022
jdrueckert added a commit to Terasology/PlantPack that referenced this pull request Aug 15, 2022
- line length
- missing whitespaces
- copyright updates
README.md Outdated Show resolved Hide resolved
@@ -63,7 +51,7 @@ public void onSpawn(OnAddedComponent event, EntityRef entity) {
ChangingBlocksComponent changingBlocks = entity.getComponent(ChangingBlocksComponent.class);
LocationComponent locComponent = entity.getComponent(LocationComponent.class);
Block currentBlock = worldprovider.getBlock(locComponent.getWorldPosition(new Vector3f()));
String currentBlockFamilyStage = currentBlock.getURI().toString();
SimpleUri currentBlockFamilyStage = new SimpleUri(currentBlock.getURI().getModuleName(), currentBlock.getURI().getIdentifier());
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this should be available on Block or BlockUri to prevent accidental errors. 🤔 (I'd use at least a module-wide helper class to be sure that we're using the same conversion within the context of Changing Blocks). However, I'm not sure how universal (and generally helpful) this reduction of information is. So, probably the module-wide helper function would indeed be a good compromise.

(We talked about this offline, but just for the record)
The culprit here is that the block uri can contain way more information (shape, orientation, ...) than just the plain block "type" (family?).
Even more confusing, it seems like we're hiding some shapes (if the shape is hard-coded in the block definition maybe?)

@keturn
Copy link
Contributor

keturn commented Aug 21, 2022

Wait, there's a BlockUri?

Okay, yes, I see now that there is. Did I mislead you then, and you actually want be using that instead of SimpleUri?

Looking at the implementation of BlockUri, I see there's also gestalt.assets.ResourceUrn.

Block newBlock = blockManager.getBlock(newBlockUri);
if (newBlockUri.equals(newBlock.getURI().toString())) {
Copy link
Member Author

Choose a reason for hiding this comment

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

BlockManager#getBlock cannot return null. If, before returning, the block that would be returned equals null the air block is returned instead.

@jdrueckert jdrueckert dismissed skaldarnar’s stale review August 21, 2022 22:53

requested changes added

@jdrueckert jdrueckert changed the title fix: make ChangingBlocks case insensitive via SimpleUri fix: make ChangingBlocks case insensitive via BlockUri Aug 23, 2022
@jdrueckert jdrueckert merged commit f81c8a1 into develop Aug 23, 2022
@jdrueckert jdrueckert deleted the feat/make-changingblocks-case-insensitive branch August 23, 2022 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Crash Requests, Issues and Changes targeting unexpected terminations, segfaults, etc. Category: Gameplay Content Requests, Issues and Changes targeting gameplay mechanics and content Size: S Small effort likely only affecting a single area and requiring little to no research Status: Needs Testing Requires to be tested in-game Topic: Stabilization Requests, Issues and Changes related to improving stablity and reducing flakyness Type: Bug Issues reporting and PRs fixing problems
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash on placing a prefab with ChangingBlock property
3 participants