From 955061fd99e0066a1b013f7e59becbb039c7184e Mon Sep 17 00:00:00 2001 From: DarkWeird Date: Mon, 7 Sep 2020 17:52:14 +0300 Subject: [PATCH 1/2] feature(reintegrate-gestaltv7): initial changes for gestaltv7 integrate - import fixes. --- src/main/java/org/terasology/biomesAPI/Biome.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/terasology/biomesAPI/Biome.java b/src/main/java/org/terasology/biomesAPI/Biome.java index 912fb06..3832234 100644 --- a/src/main/java/org/terasology/biomesAPI/Biome.java +++ b/src/main/java/org/terasology/biomesAPI/Biome.java @@ -15,7 +15,7 @@ */ package org.terasology.biomesAPI; -import org.terasology.naming.Name; +import org.terasology.gestalt.naming.Name; /** * Biomes can be assigned to different blocks during worldgen as well as on runtime, to provide additional metadata From e4764100caf2f3900f1e351d14b43381669ebe1c Mon Sep 17 00:00:00 2001 From: DarkWeird Date: Wed, 9 Sep 2020 17:06:51 +0300 Subject: [PATCH 2/2] feature(reintegrate-gestaltv7): gestalt-v7 compability (package) --- .../java/org/terasology/biomesAPI/Biome.java | 27 ++--- .../terasology/biomesAPI/BiomeManager.java | 98 ++++++++----------- .../terasology/biomesAPI/BiomeRegistry.java | 41 +++----- .../biomesAPI/BiomesMetricsMode.java | 25 ++--- .../biomesAPI/OnBiomeChangedEvent.java | 23 +---- 5 files changed, 72 insertions(+), 142 deletions(-) diff --git a/src/main/java/org/terasology/biomesAPI/Biome.java b/src/main/java/org/terasology/biomesAPI/Biome.java index 3832234..08f4aae 100644 --- a/src/main/java/org/terasology/biomesAPI/Biome.java +++ b/src/main/java/org/terasology/biomesAPI/Biome.java @@ -1,18 +1,5 @@ -/* - * Copyright 2018 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 2020 The Terasology Foundation +// SPDX-License-Identifier: Apache-2.0 package org.terasology.biomesAPI; import org.terasology.gestalt.naming.Name; @@ -28,8 +15,8 @@ public interface Biome { /** - * @return An identifier that includes both the Module the biome originates from - * and a unique biome id (unique to that module). + * @return An identifier that includes both the Module the biome originates from and a unique biome id (unique to + * that module). */ Name getId(); @@ -41,9 +28,9 @@ public interface Biome { /** * Biome hashCode must be deterministic, non-zero, and unique for every biome. *

- * Please consider overriding this method to return constant values, hard-coded for each of the biomes. - * No assumptions should however be made from any external module using biomes about their constant value, - * i.e. modules should always retrieve biome hash using this function, and not hard-code any constant values. + * Please consider overriding this method to return constant values, hard-coded for each of the biomes. No + * assumptions should however be made from any external module using biomes about their constant value, i.e. modules + * should always retrieve biome hash using this function, and not hard-code any constant values. * * @return Hashcode of the biome */ diff --git a/src/main/java/org/terasology/biomesAPI/BiomeManager.java b/src/main/java/org/terasology/biomesAPI/BiomeManager.java index 3417cfa..e5ba3e7 100644 --- a/src/main/java/org/terasology/biomesAPI/BiomeManager.java +++ b/src/main/java/org/terasology/biomesAPI/BiomeManager.java @@ -1,47 +1,33 @@ -/* - * Copyright 2018 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 2020 The Terasology Foundation +// SPDX-License-Identifier: Apache-2.0 package org.terasology.biomesAPI; import com.google.common.base.Preconditions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.terasology.entitySystem.entity.EntityManager; -import org.terasology.entitySystem.entity.EntityRef; -import org.terasology.entitySystem.event.ReceiveEvent; -import org.terasology.entitySystem.systems.BaseComponentSystem; -import org.terasology.entitySystem.systems.RegisterSystem; -import org.terasology.logic.location.LocationComponent; -import org.terasology.logic.players.PlayerCharacterComponent; -import org.terasology.logic.players.event.OnPlayerSpawnedEvent; +import org.terasology.engine.entitySystem.entity.EntityManager; +import org.terasology.engine.entitySystem.entity.EntityRef; +import org.terasology.engine.entitySystem.event.ReceiveEvent; +import org.terasology.engine.entitySystem.systems.BaseComponentSystem; +import org.terasology.engine.entitySystem.systems.RegisterSystem; +import org.terasology.engine.logic.location.LocationComponent; +import org.terasology.engine.logic.players.PlayerCharacterComponent; +import org.terasology.engine.logic.players.event.OnPlayerSpawnedEvent; +import org.terasology.engine.physics.events.MovedEvent; +import org.terasology.engine.registry.CoreRegistry; +import org.terasology.engine.registry.In; +import org.terasology.engine.registry.Share; +import org.terasology.engine.rendering.nui.NUIManager; +import org.terasology.engine.rendering.nui.layers.ingame.metrics.DebugMetricsSystem; +import org.terasology.engine.world.WorldProvider; +import org.terasology.engine.world.block.Block; +import org.terasology.engine.world.chunks.CoreChunk; +import org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager; +import org.terasology.engine.world.chunks.blockdata.ExtraDataSystem; +import org.terasology.engine.world.chunks.blockdata.RegisterExtraData; import org.terasology.math.geom.Vector3f; import org.terasology.math.geom.Vector3i; -import org.terasology.physics.events.MovedEvent; -import org.terasology.registry.CoreRegistry; -import org.terasology.registry.In; -import org.terasology.registry.Share; -import org.terasology.world.WorldProvider; -import org.terasology.world.block.Block; -import org.terasology.world.chunks.CoreChunk; -import org.terasology.world.chunks.blockdata.ExtraBlockDataManager; -import org.terasology.world.chunks.blockdata.ExtraDataSystem; -import org.terasology.world.chunks.blockdata.RegisterExtraData; -import org.terasology.rendering.nui.NUIManager; -import org.terasology.rendering.nui.layers.ingame.metrics.DebugMetricsSystem; - -import java.util.Collection; + import java.util.HashMap; import java.util.List; import java.util.Map; @@ -52,26 +38,28 @@ @RegisterSystem @ExtraDataSystem public class BiomeManager extends BaseComponentSystem implements BiomeRegistry { + private static final Logger LOGGER = LoggerFactory.getLogger(BiomeManager.class); + private final Map biomeMap = new HashMap<>(); + @In + DebugMetricsSystem debugMetricsSystem; @In private EntityManager entityManager; - @In private NUIManager nuiManager; - @In private WorldProvider worldProvider; - - @In - DebugMetricsSystem debugMetricsSystem; - - private final Map biomeMap = new HashMap<>(); - - private static final Logger LOGGER = LoggerFactory.getLogger(BiomeManager.class); - private BiomesMetricsMode metricsMode; private int biomeHashIndex; + /** + * Blocks have id, no matter what kind of blocks they are. + */ + @RegisterExtraData(name = "BiomesAPI.biomeHash", bitSize = 16) + public static boolean hasBiome(Block block) { + return true; + } + @Override public Optional getBiome(Vector3i pos) { return getBiome(pos.x, pos.y, pos.z); @@ -121,17 +109,10 @@ public void preBegin() { debugMetricsSystem.register(metricsMode); } - /** - * Blocks have id, no matter what kind of blocks they are. - */ - @RegisterExtraData(name = "BiomesAPI.biomeHash", bitSize = 16) - public static boolean hasBiome(Block block) { - return true; - } - @Override public void registerBiome(Biome biome) { - Preconditions.checkArgument(!biomeMap.containsKey(biome.biomeHash()), "Registering biome with same hash as one of previously registered biomes!"); + Preconditions.checkArgument(!biomeMap.containsKey(biome.biomeHash()), "Registering biome with same hash as " + + "one of previously registered biomes!"); biomeMap.put(biome.biomeHash(), biome); LOGGER.info("Registered biome " + biome.getId() + " with id " + biome.biomeHash()); } @@ -163,10 +144,11 @@ public void checkBiomeChangeEvent(MovedEvent event, EntityRef entity) { } @ReceiveEvent(components = PlayerCharacterComponent.class) - public void checkPlayerSpawnedEvent(OnPlayerSpawnedEvent event, EntityRef entity, LocationComponent locationComponent) { + public void checkPlayerSpawnedEvent(OnPlayerSpawnedEvent event, EntityRef entity, + LocationComponent locationComponent) { Vector3i spawnPos = new Vector3i(locationComponent.getWorldPosition()); getBiome(spawnPos) - .ifPresent(spawnBiome -> metricsMode.setBiome(spawnBiome.getId().toString())); + .ifPresent(spawnBiome -> metricsMode.setBiome(spawnBiome.getId().toString())); } } diff --git a/src/main/java/org/terasology/biomesAPI/BiomeRegistry.java b/src/main/java/org/terasology/biomesAPI/BiomeRegistry.java index 85fd083..007cc93 100644 --- a/src/main/java/org/terasology/biomesAPI/BiomeRegistry.java +++ b/src/main/java/org/terasology/biomesAPI/BiomeRegistry.java @@ -1,23 +1,10 @@ -/* - * Copyright 2018 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 2020 The Terasology Foundation +// SPDX-License-Identifier: Apache-2.0 package org.terasology.biomesAPI; -import org.terasology.entitySystem.systems.ComponentSystem; +import org.terasology.engine.entitySystem.systems.ComponentSystem; +import org.terasology.engine.world.chunks.CoreChunk; import org.terasology.math.geom.Vector3i; -import org.terasology.world.chunks.CoreChunk; import java.util.Collection; import java.util.Optional; @@ -26,8 +13,8 @@ public interface BiomeRegistry { /** * This method must be called on every startup to register biomes with this module. *

- * Biomes should be ideally registered through new {@link ComponentSystem}, in the method - * {@link ComponentSystem#preBegin()}. + * Biomes should be ideally registered through new {@link ComponentSystem}, in the method {@link + * ComponentSystem#preBegin()}. * * @param biome Biome to register */ @@ -37,9 +24,9 @@ public interface BiomeRegistry { * Sets specified biome at position in world. * * @param biome Biome to set - * @param x x position of the block to set - * @param y y position of the block to set - * @param z z position of the block to set + * @param x x position of the block to set + * @param y y position of the block to set + * @param z z position of the block to set */ void setBiome(Biome biome, int x, int y, int z); @@ -48,9 +35,9 @@ public interface BiomeRegistry { * * @param biome Biome to set * @param chunk Chunk where to set the biome - * @param relX x position of the block to set, relative to the chunk - * @param relY y position of the block to set, relative to the chunk - * @param relZ z position of the block to set, relative to the chunk + * @param relX x position of the block to set, relative to the chunk + * @param relY y position of the block to set, relative to the chunk + * @param relZ z position of the block to set, relative to the chunk */ void setBiome(Biome biome, CoreChunk chunk, int relX, int relY, int relZ); @@ -58,7 +45,7 @@ public interface BiomeRegistry { * Sets specified biome at position in world. * * @param biome Biome to set - * @param pos Position of the block to set + * @param pos Position of the block to set */ void setBiome(Biome biome, Vector3i pos); @@ -67,7 +54,7 @@ public interface BiomeRegistry { * * @param biome Biome to set * @param chunk Chunk where to set the biome - * @param pos Position of the block to set + * @param pos Position of the block to set */ void setBiome(Biome biome, CoreChunk chunk, Vector3i pos); diff --git a/src/main/java/org/terasology/biomesAPI/BiomesMetricsMode.java b/src/main/java/org/terasology/biomesAPI/BiomesMetricsMode.java index 084e15b..3ad423f 100644 --- a/src/main/java/org/terasology/biomesAPI/BiomesMetricsMode.java +++ b/src/main/java/org/terasology/biomesAPI/BiomesMetricsMode.java @@ -1,27 +1,14 @@ -/* - * Copyright 2020 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 2020 The Terasology Foundation +// SPDX-License-Identifier: Apache-2.0 package org.terasology.biomesAPI; -import org.terasology.rendering.nui.layers.ingame.metrics.MetricsMode; +import org.terasology.engine.rendering.nui.layers.ingame.metrics.MetricsMode; /** * Display the name of the biome the player is currently located in in the debug overlay. *

- * Current biome is set when OnBiomeChanged event is triggered - * biomeName is polled whenever MetricsMode values are updated + * Current biome is set when OnBiomeChanged event is triggered biomeName is polled whenever MetricsMode values are + * updated */ class BiomesMetricsMode extends MetricsMode { @@ -33,7 +20,7 @@ class BiomesMetricsMode extends MetricsMode { @Override public String getMetrics() { - return getName()+"\n"+biomeName; + return getName() + "\n" + biomeName; } @Override diff --git a/src/main/java/org/terasology/biomesAPI/OnBiomeChangedEvent.java b/src/main/java/org/terasology/biomesAPI/OnBiomeChangedEvent.java index d4daff9..bece08c 100644 --- a/src/main/java/org/terasology/biomesAPI/OnBiomeChangedEvent.java +++ b/src/main/java/org/terasology/biomesAPI/OnBiomeChangedEvent.java @@ -1,29 +1,16 @@ -/* - * Copyright 2018 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 2020 The Terasology Foundation +// SPDX-License-Identifier: Apache-2.0 package org.terasology.biomesAPI; -import org.terasology.entitySystem.event.Event; +import org.terasology.engine.entitySystem.event.Event; /** * This event is thrown to entities with {@link org.terasology.logic.players.PlayerCharacterComponent} whenever they * change the biome they are in. */ public class OnBiomeChangedEvent implements Event { - private Biome oldBiome; - private Biome newBiome; + private final Biome oldBiome; + private final Biome newBiome; public OnBiomeChangedEvent(Biome oldBiome, Biome newBiome) { this.oldBiome = oldBiome;