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
jdrueckert
merged 8 commits into
develop
from
feat/make-changingblocks-case-insensitive
Aug 23, 2022
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a5d6d13
feat: make ChangingBlocks case insensitive via SimpleUri
jdrueckert 765e649
chore: update copyright
jdrueckert 2297a31
chore: fix checkstyle findings
jdrueckert 78fe822
chore: align sample component map formatting
jdrueckert 40182c6
doc: fix sample prefab indentation
jdrueckert 61af268
chore: fix spotbugs findings
jdrueckert 54773d5
chore: extract BlockUri to SimpleUri logic into helper method
jdrueckert af4803f
feat: use BlockUri instead of SimpleUri
jdrueckert File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,11 @@ | ||
/* | ||
* Copyright 2015 MovingBlocks | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
// Copyright 2022 The Terasology Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package org.terasology.changingBlocks; | ||
|
||
import org.joml.RoundingMode; | ||
import org.joml.Vector3f; | ||
import org.joml.Vector3i; | ||
import org.terasology.engine.core.SimpleUri; | ||
import org.terasology.engine.core.Time; | ||
import org.terasology.engine.entitySystem.entity.EntityManager; | ||
import org.terasology.engine.entitySystem.entity.EntityRef; | ||
|
@@ -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()); | ||
changingBlocks.timeInGameMsToNextStage = changingBlocks.blockFamilyStages.get(currentBlockFamilyStage); | ||
changingBlocks.lastGameTimeCheck = initTime; | ||
entity.saveComponent(changingBlocks); | ||
|
@@ -79,7 +67,8 @@ public void update(float delta) { | |
// System last time check is to try to improve performance | ||
long gameTimeInMs = timer.getGameTimeInMs(); | ||
if (lastCheckTime + CHECK_INTERVAL < gameTimeInMs) { | ||
for (EntityRef changingBlocks : entityManager.getEntitiesWith(ChangingBlocksComponent.class, BlockComponent.class, LocationComponent.class)) { | ||
for (EntityRef changingBlocks : entityManager.getEntitiesWith(ChangingBlocksComponent.class, | ||
BlockComponent.class, LocationComponent.class)) { | ||
ChangingBlocksComponent blockAnimation = changingBlocks.getComponent(ChangingBlocksComponent.class); | ||
if (blockAnimation.stopped) { | ||
return; | ||
|
@@ -93,9 +82,10 @@ public void update(float delta) { | |
blockAnimation.lastGameTimeCheck = timer.getGameTimeInMs(); | ||
LocationComponent locComponent = changingBlocks.getComponent(LocationComponent.class); | ||
Block currentBlock = worldprovider.getBlock(locComponent.getWorldPosition(new Vector3f())); | ||
String currentBlockFamilyStage = currentBlock.getURI().toString(); | ||
Set<String> keySet = blockAnimation.blockFamilyStages.keySet(); | ||
List<String> keyList = new ArrayList<>(keySet); | ||
SimpleUri currentBlockFamilyStage = new SimpleUri(currentBlock.getURI().getModuleName(), | ||
currentBlock.getURI().getIdentifier()); | ||
Set<SimpleUri> keySet = blockAnimation.blockFamilyStages.keySet(); | ||
List<SimpleUri> keyList = new ArrayList<>(keySet); | ||
int currentstageIndex = keyList.indexOf(currentBlockFamilyStage); | ||
skaldarnar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int lastStageIndex = blockAnimation.blockFamilyStages.size() - 1; | ||
if (lastStageIndex > currentstageIndex) { | ||
|
@@ -108,9 +98,9 @@ public void update(float delta) { | |
changingBlocks.send(new OnBlockSequenceComplete()); | ||
} | ||
} | ||
String newBlockUri = keyList.get(currentstageIndex); | ||
Block newBlock = blockManager.getBlock(newBlockUri); | ||
if (newBlockUri.equals(newBlock.getURI().toString())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
SimpleUri newBlockUri = keyList.get(currentstageIndex); | ||
Block newBlock = blockManager.getBlock(newBlockUri.toString()); | ||
if (newBlockUri.equals(new SimpleUri(newBlock.getURI().getModuleName(), newBlock.getURI().getIdentifier()))) { | ||
worldprovider.setBlock(new Vector3i(locComponent.getWorldPosition(new Vector3f()), RoundingMode.FLOOR), newBlock); | ||
blockAnimation.timeInGameMsToNextStage = blockAnimation.blockFamilyStages.get(currentBlockFamilyStage); | ||
} | ||
|
17 changes: 2 additions & 15 deletions
17
src/main/java/org/terasology/changingBlocks/OnBlockSequenceComplete.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 2 additions & 15 deletions
17
src/main/java/org/terasology/changingBlocks/conditional/BlockCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...g/terasology/changingBlocks/conditional/components/ChangeBlockBlockDirectedComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...org/terasology/changingBlocks/conditional/components/ChangeBlockBlockNearbyComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../terasology/changingBlocks/conditional/components/ChangeBlockEntityDirectedComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rg/terasology/changingBlocks/conditional/components/ChangeBlockEntityNearbyComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...org/terasology/changingBlocks/conditional/components/ConditionalBlockChangeComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
orBlockUri
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?)