From 645882644a74402f428c33817f0bca03728b04cd Mon Sep 17 00:00:00 2001 From: DarkWeird Date: Mon, 7 Sep 2020 17:52:15 +0300 Subject: [PATCH 1/3] feature(reintegrate-gestaltv7): initial changes for gestaltv7 integrate - import fixes. --- .../alchemy/system/RegisterAlchemyRecipes.java | 2 +- .../herbalism/system/HerbIconAssetResolver.java | 12 ++++++------ .../herbalism/system/HerbalismCommonSystem.java | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/terasology/alchemy/system/RegisterAlchemyRecipes.java b/src/main/java/org/terasology/alchemy/system/RegisterAlchemyRecipes.java index a544b47..6c02717 100644 --- a/src/main/java/org/terasology/alchemy/system/RegisterAlchemyRecipes.java +++ b/src/main/java/org/terasology/alchemy/system/RegisterAlchemyRecipes.java @@ -17,13 +17,13 @@ import com.google.common.base.Predicate; import org.terasology.alchemy.Alchemy; -import org.terasology.assets.ResourceUrn; import org.terasology.entitySystem.entity.EntityManager; import org.terasology.entitySystem.entity.EntityRef; import org.terasology.entitySystem.prefab.Prefab; import org.terasology.entitySystem.prefab.PrefabManager; import org.terasology.entitySystem.systems.BaseComponentSystem; import org.terasology.entitySystem.systems.RegisterSystem; +import org.terasology.gestalt.assets.ResourceUrn; import org.terasology.herbalism.component.HerbalismStationRecipeComponent; import org.terasology.herbalism.ui.HerbalismCraftingStationRecipe; import org.terasology.multiBlock.Basic2DSizeFilter; diff --git a/src/main/java/org/terasology/herbalism/system/HerbIconAssetResolver.java b/src/main/java/org/terasology/herbalism/system/HerbIconAssetResolver.java index 4f2584c..0be0eb7 100644 --- a/src/main/java/org/terasology/herbalism/system/HerbIconAssetResolver.java +++ b/src/main/java/org/terasology/herbalism/system/HerbIconAssetResolver.java @@ -16,17 +16,17 @@ package org.terasology.herbalism.system; import com.google.common.collect.ImmutableSet; -import org.terasology.assets.AssetDataProducer; -import org.terasology.assets.ResourceUrn; -import org.terasology.assets.management.AssetManager; -import org.terasology.assets.module.annotations.RegisterAssetDataProducer; -import org.terasology.naming.Name; +import org.terasology.gestalt.assets.AssetDataProducer; +import org.terasology.gestalt.assets.ResourceUrn; +import org.terasology.gestalt.assets.management.AssetManager; +import org.terasology.gestalt.assets.module.annotations.RegisterAssetDataProducer; +import org.terasology.gestalt.naming.Name; import org.terasology.rendering.assets.texture.Texture; import org.terasology.rendering.assets.texture.TextureData; import org.terasology.rendering.assets.texture.TextureRegionAsset; import org.terasology.rendering.assets.texture.TextureUtil; -import java.awt.*; +import java.awt.Color; import java.awt.image.BufferedImage; import java.io.IOException; import java.nio.ByteBuffer; diff --git a/src/main/java/org/terasology/herbalism/system/HerbalismCommonSystem.java b/src/main/java/org/terasology/herbalism/system/HerbalismCommonSystem.java index 6fb4dee..509cb3e 100644 --- a/src/main/java/org/terasology/herbalism/system/HerbalismCommonSystem.java +++ b/src/main/java/org/terasology/herbalism/system/HerbalismCommonSystem.java @@ -24,7 +24,6 @@ import org.terasology.alterationEffects.speed.MultiJumpAlterationEffect; import org.terasology.alterationEffects.speed.SwimSpeedAlterationEffect; import org.terasology.alterationEffects.speed.WalkSpeedAlterationEffect; -import org.terasology.assets.management.AssetManager; import org.terasology.context.Context; import org.terasology.entitySystem.prefab.PrefabManager; import org.terasology.entitySystem.systems.BaseComponentSystem; @@ -35,6 +34,7 @@ import org.terasology.genome.breed.MonoploidBreedingAlgorithm; import org.terasology.genome.breed.mutator.GeneMutator; import org.terasology.genome.genomeMap.SeedBasedGenomeMap; +import org.terasology.gestalt.assets.management.AssetManager; import org.terasology.herbalism.HerbEffectRegistry; import org.terasology.herbalism.HerbGeneMutator; import org.terasology.herbalism.HerbNameProvider; From 5fece0f7a66fa65894bd3e2a2a35167a014aface Mon Sep 17 00:00:00 2001 From: DarkWeird Date: Wed, 9 Sep 2020 17:06:53 +0300 Subject: [PATCH 2/3] feature(reintegrate-gestaltv7): gestalt-v7 compability (package) --- assets/ui/HerbalismStation.ui | 386 +++++++++--------- .../alchemy/system/AlchemyCategory.java | 96 +++-- .../system/AlchemyInGameHelpCommonSystem.java | 34 +- .../system/RegisterAlchemyRecipes.java | 66 ++- .../alchemy/system/SeedingHerbRecipe.java | 136 +++--- .../herbalism/DefaultHerbEffectRegistry.java | 39 +- .../herbalism/HerbEffectRegistry.java | 27 +- .../herbalism/HerbNameProvider.java | 42 +- .../component/GeneratedHerbComponent.java | 23 +- .../herbalism/component/HerbComponent.java | 19 +- .../herbalism/component/HerbHueComponent.java | 19 +- .../HerbalismStationRecipeComponent.java | 23 +- .../component/PollinatingHerbComponent.java | 19 +- .../component/PredefinedHerbComponent.java | 23 +- .../herbalism/generator/Blocks.java | 27 +- .../generator/HerbAGrowthDefinition.java | 52 +-- .../generator/HerbDesertSpawnDefinition.java | 21 +- .../generator/HerbForestSpawnDefinition.java | 21 +- .../generator/HerbPlainsSpawnDefinition.java | 21 +- .../generator/HerbTundraSpawnDefinition.java | 21 +- .../system/HerbDropAuthoritySystem.java | 156 +++---- .../system/HerbIconAssetResolver.java | 68 ++- .../system/HerbalismAuthoritySystem.java | 62 ++- .../system/HerbalismClientSystem.java | 71 ++-- .../system/HerbalismCommonSystem.java | 75 ++-- .../HerbalismStationIngredientPredicate.java | 36 +- .../ui/HerbalismCraftingStationRecipe.java | 178 ++++---- .../herbalism/ui/HerbalismStationWindow.java | 41 +- .../ui/HerbalismStationWindowSystem.java | 68 ++- 29 files changed, 843 insertions(+), 1027 deletions(-) diff --git a/assets/ui/HerbalismStation.ui b/assets/ui/HerbalismStation.ui index 14baa86..70eb7ab 100644 --- a/assets/ui/HerbalismStation.ui +++ b/assets/ui/HerbalismStation.ui @@ -1,198 +1,198 @@ { - "type": "HerbalismStationWindow", - "skin": "WorkstationCrafting:CraftingStation", - "contents": { + "type": "HerbalismStationWindow", + "skin": "WorkstationCrafting:CraftingStation", + "contents": { + "type": "relativeLayout", + "contents": [ + { "type": "relativeLayout", "contents": [ - { - "type": "relativeLayout", - "contents": [ - { - "type": "ScrollableArea", - "content": { - "type": "InventoryGrid", - "id": "ingredientsInventory" - }, - "layoutInfo": { - "width": 128, - "height": 250, - "position-left": { - "offset": 0 - }, - "position-top": { - "offset": 45 - } - } - }, - { - "type": "InventoryGrid", - "id": "toolsInventory", - "layoutInfo": { - "width": 128, - "height": 56, - "position-left": { - "offset": 0 - }, - "position-top": { - "offset": 316 - } - } - }, - { - "type": "InventoryGrid", - "id": "fluidContainerInputX", - "layoutInfo": { - "width": 56, - "height": 56, - "position-left": { - "offset": 136 - }, - "position-top": { - "offset": 45 - } - } - }, - { - "type": "InventoryGrid", - "id": "fluidContainerOutput", - "layoutInfo": { - "width": 56, - "height": 56, - "position-left": { - "offset": 136 - }, - "position-top": { - "offset": 316 - } - } - }, - { - "type": "ThermometerWidget", - "id": "temperature", - "layoutInfo": { - "width": 20, - "height": 150, - "position-left": { - "offset": 212 - }, - "position-top": { - "offset": 45 - } - } - }, - { - "type": "FluidHolderWidget", - "id": "fluidContainer", - "image": "WorkstationCrafting:FluidHolder", - "layoutInfo": { - "width": 50, - "height": 150, - "position-left": { - "offset": 246 - }, - "position-top": { - "offset": 50 - } - } - }, - { - "type": "VerticalTextureProgressWidget", - "id": "burn", - "image": "WorkstationCrafting:Fire", - "layoutInfo": { - "width": 50, - "height": 50, - "position-left": { - "offset": 197 - }, - "position-top": { - "offset": 200 - } - } - }, - { - "type": "InventoryGrid", - "id": "fuelInput", - "layoutInfo": { - "width": 56, - "height": 56, - "position-left": { - "offset": 194 - }, - "position-top": { - "offset": 255 - } - } - }, - { - "type": "ScrollableArea", - "content": { - "type": "StationAvailableRecipesWidget", - "id": "availableRecipes" - }, - "layoutInfo": { - "width": 315, - "height": 250, - "position-left": { - "offset": 250 - }, - "position-top": { - "offset": 45 - } - } - }, - { - "type": "UILoadBar", - "fillTexture": "engine:statusBar", - "id": "craftingProgress", - "animate": false, - "layoutInfo": { - "width": 56, - "height": 10, - "position-left": { - "offset": 509 - }, - "position-top": { - "offset": 311 - } - } - }, - { - "type": "InventoryGrid", - "id": "resultInventory", - "layoutInfo": { - "width": 56, - "height": 56, - "position-left": { - "offset": 556 - }, - "position-top": { - "offset": 316 - } - } - }, - { - "type": "InventoryGrid", - "id": "playerInventory", - "layoutInfo": { - "width": 560, - "height": 168, - "position-left": { - "offset": 52 - }, - "position-top": { - "offset": 377 - } - } - } - ], - "layoutInfo": { - "width": 665, - "height": 550, - "position-horizontal-center": {}, - "position-vertical-center": {} - } + { + "type": "ScrollableArea", + "content": { + "type": "InventoryGrid", + "id": "ingredientsInventory" + }, + "layoutInfo": { + "width": 128, + "height": 250, + "position-left": { + "offset": 0 + }, + "position-top": { + "offset": 45 + } } - ] - } + }, + { + "type": "InventoryGrid", + "id": "toolsInventory", + "layoutInfo": { + "width": 128, + "height": 56, + "position-left": { + "offset": 0 + }, + "position-top": { + "offset": 316 + } + } + }, + { + "type": "InventoryGrid", + "id": "fluidContainerInputX", + "layoutInfo": { + "width": 56, + "height": 56, + "position-left": { + "offset": 136 + }, + "position-top": { + "offset": 45 + } + } + }, + { + "type": "InventoryGrid", + "id": "fluidContainerOutput", + "layoutInfo": { + "width": 56, + "height": 56, + "position-left": { + "offset": 136 + }, + "position-top": { + "offset": 316 + } + } + }, + { + "type": "ThermometerWidget", + "id": "temperature", + "layoutInfo": { + "width": 20, + "height": 150, + "position-left": { + "offset": 212 + }, + "position-top": { + "offset": 45 + } + } + }, + { + "type": "FluidHolderWidget", + "id": "fluidContainer", + "image": "WorkstationCrafting:FluidHolder", + "layoutInfo": { + "width": 50, + "height": 150, + "position-left": { + "offset": 246 + }, + "position-top": { + "offset": 50 + } + } + }, + { + "type": "VerticalTextureProgressWidget", + "id": "burn", + "image": "WorkstationCrafting:Fire", + "layoutInfo": { + "width": 50, + "height": 50, + "position-left": { + "offset": 197 + }, + "position-top": { + "offset": 200 + } + } + }, + { + "type": "InventoryGrid", + "id": "fuelInput", + "layoutInfo": { + "width": 56, + "height": 56, + "position-left": { + "offset": 194 + }, + "position-top": { + "offset": 255 + } + } + }, + { + "type": "ScrollableArea", + "content": { + "type": "StationAvailableRecipesWidget", + "id": "availableRecipes" + }, + "layoutInfo": { + "width": 315, + "height": 250, + "position-left": { + "offset": 250 + }, + "position-top": { + "offset": 45 + } + } + }, + { + "type": "UILoadBar", + "fillTexture": "engine:statusBar", + "id": "craftingProgress", + "animate": false, + "layoutInfo": { + "width": 56, + "height": 10, + "position-left": { + "offset": 509 + }, + "position-top": { + "offset": 311 + } + } + }, + { + "type": "InventoryGrid", + "id": "resultInventory", + "layoutInfo": { + "width": 56, + "height": 56, + "position-left": { + "offset": 556 + }, + "position-top": { + "offset": 316 + } + } + }, + { + "type": "InventoryGrid", + "id": "playerInventory", + "layoutInfo": { + "width": 560, + "height": 168, + "position-left": { + "offset": 52 + }, + "position-top": { + "offset": 377 + } + } + } + ], + "layoutInfo": { + "width": 665, + "height": 550, + "position-horizontal-center": {}, + "position-vertical-center": {} + } + } + ] + } } diff --git a/src/main/java/org/terasology/alchemy/system/AlchemyCategory.java b/src/main/java/org/terasology/alchemy/system/AlchemyCategory.java index f8ce161..0f36431 100644 --- a/src/main/java/org/terasology/alchemy/system/AlchemyCategory.java +++ b/src/main/java/org/terasology/alchemy/system/AlchemyCategory.java @@ -1,40 +1,27 @@ -/* - * Copyright 2016 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.alchemy.system; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; -import org.terasology.entitySystem.prefab.Prefab; +import org.terasology.engine.entitySystem.prefab.Prefab; +import org.terasology.engine.logic.common.DisplayNameComponent; +import org.terasology.engine.rendering.assets.font.Font; +import org.terasology.engine.rendering.nui.widgets.browser.data.DocumentData; +import org.terasology.engine.rendering.nui.widgets.browser.data.basic.FlowParagraphData; +import org.terasology.engine.rendering.nui.widgets.browser.data.basic.flow.TextFlowRenderable; +import org.terasology.engine.rendering.nui.widgets.browser.data.html.HTMLDocument; +import org.terasology.engine.rendering.nui.widgets.browser.ui.style.ContainerInteger; +import org.terasology.engine.rendering.nui.widgets.browser.ui.style.FixedContainerInteger; +import org.terasology.engine.rendering.nui.widgets.browser.ui.style.ParagraphRenderStyle; +import org.terasology.engine.rendering.nui.widgets.browser.ui.style.TextRenderStyle; +import org.terasology.engine.utilities.Assets; import org.terasology.inGameHelpAPI.ItemsCategoryInGameHelpRegistry; import org.terasology.inGameHelpAPI.components.HelpItem; import org.terasology.inGameHelpAPI.components.ItemHelpComponent; import org.terasology.inGameHelpAPI.systems.HelpCategory; import org.terasology.inGameHelpAPI.ui.ItemWidget; import org.terasology.inGameHelpAPI.ui.WidgetFlowRenderable; -import org.terasology.logic.common.DisplayNameComponent; -import org.terasology.rendering.assets.font.Font; -import org.terasology.rendering.nui.widgets.browser.data.DocumentData; -import org.terasology.rendering.nui.widgets.browser.data.basic.FlowParagraphData; -import org.terasology.rendering.nui.widgets.browser.data.basic.flow.TextFlowRenderable; -import org.terasology.rendering.nui.widgets.browser.data.html.HTMLDocument; -import org.terasology.rendering.nui.widgets.browser.ui.style.ContainerInteger; -import org.terasology.rendering.nui.widgets.browser.ui.style.FixedContainerInteger; -import org.terasology.rendering.nui.widgets.browser.ui.style.ParagraphRenderStyle; -import org.terasology.rendering.nui.widgets.browser.ui.style.TextRenderStyle; -import org.terasology.utilities.Assets; import java.util.Map; @@ -42,20 +29,27 @@ * This help category manages how the Alchemy tab (or help document) will function in the in game help registry window. */ public class AlchemyCategory implements HelpCategory { - /** Name of this category. */ + /** + * Name of this category. + */ private final String name = "Alchemy"; - - /** Reference to the InGameHelpRegistry. This will be necessary for determining what prefabs fall under this category. */ - private ItemsCategoryInGameHelpRegistry itemsCategoryInGameHelpRegistry; - - /** Create a mapping of Strings to DocuemntData to store the item help subpages. */ + /** + * Create a mapping of Strings to DocuemntData to store the item help subpages. + */ Map items = Maps.newHashMap(); - - /** Reference to the root HTML document. */ + /** + * Reference to the root HTML document. + */ HTMLDocument rootDocument; - - /** Reference to the current document data. This is the current help document that the user is on. */ + /** + * Reference to the current document data. This is the current help document that the user is on. + */ DocumentData currentDocument; + /** + * Reference to the InGameHelpRegistry. This will be necessary for determining what prefabs fall under this + * category. + */ + private ItemsCategoryInGameHelpRegistry itemsCategoryInGameHelpRegistry; /** * Default constructor. Use this if you don't have an ItemsCategoryInGameHelpRegistry instance yet. @@ -66,8 +60,8 @@ public AlchemyCategory() { /** * Create an instance of this help category. * - * @param itemsCategoryInGameHelpRegistry Reference to the items category in game help registry. This will contain - * all known items that have an InGameHelp component. + * @param itemsCategoryInGameHelpRegistry Reference to the items category in game help registry. This will + * contain all known items that have an InGameHelp component. */ public AlchemyCategory(ItemsCategoryInGameHelpRegistry itemsCategoryInGameHelpRegistry) { this.itemsCategoryInGameHelpRegistry = itemsCategoryInGameHelpRegistry; @@ -76,8 +70,8 @@ public AlchemyCategory(ItemsCategoryInGameHelpRegistry itemsCategoryInGameHelpRe /** * Set the reference to the titular registry. * - * @param reg Reference to the items category in game help registry. This will contain all known items that have - * an InGameHelp component. + * @param reg Reference to the items category in game help registry. This will contain all known items that + * have an InGameHelp component. */ public void setRegistry(ItemsCategoryInGameHelpRegistry reg) { this.itemsCategoryInGameHelpRegistry = reg; @@ -125,10 +119,12 @@ public ContainerInteger getParagraphPaddingTop() { // Get the icon and name of this prefab, and add it to the document. FlowParagraphData imageNameParagraph = new FlowParagraphData(null); documentData.addParagraph(imageNameParagraph); - imageNameParagraph.append(new WidgetFlowRenderable(new ItemWidget(itemPrefab.getName()), 48, 48, itemPrefab.getName())); + imageNameParagraph.append(new WidgetFlowRenderable(new ItemWidget(itemPrefab.getName()), 48, 48, + itemPrefab.getName())); DisplayNameComponent displayNameComponent = itemPrefab.getComponent(DisplayNameComponent.class); if (displayNameComponent != null) { - imageNameParagraph.append(new TextFlowRenderable(displayNameComponent.name, titleRenderStyle, null)); + imageNameParagraph.append(new TextFlowRenderable(displayNameComponent.name, titleRenderStyle, + null)); } else { imageNameParagraph.append(new TextFlowRenderable(itemPrefab.getName(), titleRenderStyle, null)); } @@ -152,7 +148,8 @@ public ContainerInteger getParagraphPaddingTop() { items.put(itemPrefab.getName(), documentData); // Add this to the root document. - itemListParagraph.append(new WidgetFlowRenderable(new ItemWidget(itemPrefab.getName()), 48, 48, itemPrefab.getName())); + itemListParagraph.append(new WidgetFlowRenderable(new ItemWidget(itemPrefab.getName()), 48, 48, + itemPrefab.getName())); } } } @@ -160,7 +157,7 @@ public ContainerInteger getParagraphPaddingTop() { /** * Get the category name of this help section. * - * @return The name of this category, + * @return The name of this category, */ @Override public String getCategoryName() { @@ -170,7 +167,7 @@ public String getCategoryName() { /** * Get the document data for this category. If this category hasn't been initialized yet, then do so. * - * @return Either the root document if the current document is null, or the current document. + * @return Either the root document if the current document is null, or the current document. */ @Override public DocumentData getDocumentData() { @@ -193,13 +190,14 @@ public void resetNavigation() { /** * Handle navigation between the top and sub-documents. * - * @param hyperlink What document to navigate to. - * @return True if the document linked to exists. False if not. + * @param hyperlink What document to navigate to. + * @return True if the document linked to exists. False if not. */ @Override public boolean handleNavigate(String hyperlink) { if (items.size() == 0) { - // Handle the case where we navigate before we have shown the screen. There is probably a better way to do this. + // Handle the case where we navigate before we have shown the screen. There is probably a better way to + // do this. initialise(); } diff --git a/src/main/java/org/terasology/alchemy/system/AlchemyInGameHelpCommonSystem.java b/src/main/java/org/terasology/alchemy/system/AlchemyInGameHelpCommonSystem.java index 87ddfc4..8bad195 100644 --- a/src/main/java/org/terasology/alchemy/system/AlchemyInGameHelpCommonSystem.java +++ b/src/main/java/org/terasology/alchemy/system/AlchemyInGameHelpCommonSystem.java @@ -1,27 +1,13 @@ -/* - * Copyright 2016 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.alchemy.system; -import org.terasology.entitySystem.systems.BaseComponentSystem; -import org.terasology.entitySystem.systems.RegisterSystem; -import org.terasology.entitySystem.systems.UpdateSubscriberSystem; +import org.terasology.engine.entitySystem.systems.BaseComponentSystem; +import org.terasology.engine.entitySystem.systems.RegisterSystem; +import org.terasology.engine.entitySystem.systems.UpdateSubscriberSystem; +import org.terasology.engine.logic.players.LocalPlayer; +import org.terasology.engine.registry.CoreRegistry; import org.terasology.inGameHelpAPI.event.OnAddNewCategoryEvent; -import org.terasology.logic.players.LocalPlayer; -import org.terasology.potions.system.PotionsCategory; -import org.terasology.registry.CoreRegistry; /** * This system is used to add the AlchemyCategory help category by sending it to the appropriate handler system over in @@ -29,13 +15,15 @@ */ @RegisterSystem public class AlchemyInGameHelpCommonSystem extends BaseComponentSystem implements UpdateSubscriberSystem { - /** Flag for checking if the category has been sent. */ + /** + * Flag for checking if the category has been sent. + */ boolean hasSent = false; /** * Update the system. Though in this case, only once. * - * @param delta Time between this and the last update. + * @param delta Time between this and the last update. */ @Override public void update(float delta) { diff --git a/src/main/java/org/terasology/alchemy/system/RegisterAlchemyRecipes.java b/src/main/java/org/terasology/alchemy/system/RegisterAlchemyRecipes.java index 6c02717..e4991c6 100644 --- a/src/main/java/org/terasology/alchemy/system/RegisterAlchemyRecipes.java +++ b/src/main/java/org/terasology/alchemy/system/RegisterAlchemyRecipes.java @@ -1,28 +1,18 @@ -/* - * Copyright 2016 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.alchemy.system; import com.google.common.base.Predicate; import org.terasology.alchemy.Alchemy; -import org.terasology.entitySystem.entity.EntityManager; -import org.terasology.entitySystem.entity.EntityRef; -import org.terasology.entitySystem.prefab.Prefab; -import org.terasology.entitySystem.prefab.PrefabManager; -import org.terasology.entitySystem.systems.BaseComponentSystem; -import org.terasology.entitySystem.systems.RegisterSystem; +import org.terasology.engine.entitySystem.entity.EntityManager; +import org.terasology.engine.entitySystem.entity.EntityRef; +import org.terasology.engine.entitySystem.prefab.Prefab; +import org.terasology.engine.entitySystem.prefab.PrefabManager; +import org.terasology.engine.entitySystem.systems.BaseComponentSystem; +import org.terasology.engine.entitySystem.systems.RegisterSystem; +import org.terasology.engine.registry.In; +import org.terasology.engine.world.block.BlockManager; +import org.terasology.engine.world.block.BlockUri; import org.terasology.gestalt.assets.ResourceUrn; import org.terasology.herbalism.component.HerbalismStationRecipeComponent; import org.terasology.herbalism.ui.HerbalismCraftingStationRecipe; @@ -32,15 +22,12 @@ import org.terasology.multiBlock.recipe.LayeredMultiBlockFormItemRecipe; import org.terasology.processing.system.AnyActivityFilter; import org.terasology.processing.system.ToolTypeEntityFilter; -import org.terasology.registry.In; import org.terasology.workstation.system.WorkstationRegistry; import org.terasology.workstationCrafting.component.CraftingStationMaterialComponent; import org.terasology.workstationCrafting.component.CraftingStationRecipeComponent; import org.terasology.workstationCrafting.system.CraftInHandRecipeRegistry; import org.terasology.workstationCrafting.system.CraftingWorkstationProcess; import org.terasology.workstationCrafting.system.CraftingWorkstationProcessFactory; -import org.terasology.world.block.BlockManager; -import org.terasology.world.block.BlockUri; /** * This system registers all of the Alchemy recipes in this module. @@ -66,7 +53,8 @@ public class RegisterAlchemyRecipes extends BaseComponentSystem { @Override public void initialise() { // Register the process factory for generic Herbalism process recipes that don't use the Herbalism Station. - workstationRegistry.registerProcessFactory(Alchemy.HERBALISM_PROCESS_TYPE, new CraftingWorkstationProcessFactory()); + workstationRegistry.registerProcessFactory(Alchemy.HERBALISM_PROCESS_TYPE, + new CraftingWorkstationProcessFactory()); addWorkstationFormingRecipes(); @@ -81,7 +69,8 @@ private void addWorkstationFormingRecipes() { new ToolTypeEntityFilter("mortarAndPestle"), new Basic2DSizeFilter(3, 1), new AnyActivityFilter(), "Alchemy:HerbalismStation", null); herbalismStationRecipe.addLayer(1, 1, new BlockUriEntityFilter(new BlockUri("CoreAssets:Brick"))); - herbalismStationRecipe.addLayer(1, 1, new BlockUriEntityFilter(new BlockUri(new ResourceUrn("CoreAssets:CobbleStone"), new ResourceUrn(("Engine:EighthBlock"))))); + herbalismStationRecipe.addLayer(1, 1, new BlockUriEntityFilter(new BlockUri(new ResourceUrn("CoreAssets" + + ":CobbleStone"), new ResourceUrn(("Engine:EighthBlock"))))); multiBlockFormRecipeRegistry.addMultiBlockFormItemRecipe(herbalismStationRecipe); } @@ -91,15 +80,18 @@ private void addWorkstationFormingRecipes() { private void addHerbalismWorkstationRecipes() { // TODO: Temporarily removed for sake of testing. /* workstationRegistry.registerProcess(WorkstationCrafting.HERBALISM_PROCESS_TYPE, - new CraftingWorkstationProcess(WorkstationCrafting.HERBALISM_PROCESS_TYPE, "WorkstationCrafting:HerbPotion", new HerbalismCraftingStationRecipe()));*/ + new CraftingWorkstationProcess(WorkstationCrafting.HERBALISM_PROCESS_TYPE, + "WorkstationCrafting:HerbPotion", new HerbalismCraftingStationRecipe()));*/ // Add all the recipes marked with "HerbalismStationRecipeComponent" in their prefabs and add them to the list. for (Prefab prefab : prefabManager.listPrefabs(HerbalismStationRecipeComponent.class)) { // Get the Crafting Station recipe component of this recipe prefab. CraftingStationRecipeComponent recipeComponent = prefab.getComponent(CraftingStationRecipeComponent.class); - // We individually register each process instead of using registerProcessFactory (with CraftingWorkstationProcessFactory) - // as we need to add in some custom actions. The createProcess method in CraftingWorkstationProcessFactory won't do. + // We individually register each process instead of using registerProcessFactory (with + // CraftingWorkstationProcessFactory) + // as we need to add in some custom actions. The createProcess method in + // CraftingWorkstationProcessFactory won't do. workstationRegistry.registerProcess(Alchemy.HERBALISM_PROCESS_TYPE, new CraftingWorkstationProcess(Alchemy.HERBALISM_PROCESS_TYPE, recipeComponent.recipeId, new HerbalismCraftingStationRecipe(recipeComponent), prefab, entityManager)); @@ -110,13 +102,15 @@ private void addHerbalismWorkstationRecipes() { * This internal predicate class is used to filter out incompatible crafting station types. */ private final class StationTypeFilter implements Predicate { - /** Name of the station type. */ - private String stationType; + /** + * Name of the station type. + */ + private final String stationType; /** * Define what station this filter should look for. * - * @param stationType Name of the station being filtered. + * @param stationType Name of the station being filtered. */ private StationTypeFilter(String stationType) { this.stationType = stationType; @@ -124,12 +118,14 @@ private StationTypeFilter(String stationType) { /** * Apply an entity to this filter to see if it has the same station type. - * @param entity Reference to the entity being checked. - * @return True if the entity has the same station type. False if not. + * + * @param entity Reference to the entity being checked. + * @return True if the entity has the same station type. False if not. */ @Override public boolean apply(EntityRef entity) { - CraftingStationMaterialComponent stationMaterial = entity.getComponent(CraftingStationMaterialComponent.class); + CraftingStationMaterialComponent stationMaterial = + entity.getComponent(CraftingStationMaterialComponent.class); return stationMaterial != null && stationMaterial.stationType.equals(stationType); } } diff --git a/src/main/java/org/terasology/alchemy/system/SeedingHerbRecipe.java b/src/main/java/org/terasology/alchemy/system/SeedingHerbRecipe.java index 3667a3a..594ec6f 100644 --- a/src/main/java/org/terasology/alchemy/system/SeedingHerbRecipe.java +++ b/src/main/java/org/terasology/alchemy/system/SeedingHerbRecipe.java @@ -4,8 +4,20 @@ import com.google.common.base.Predicate; import org.terasology.anotherWorldPlants.farm.component.SeedComponent; -import org.terasology.entitySystem.entity.EntityManager; -import org.terasology.entitySystem.entity.EntityRef; +import org.terasology.engine.entitySystem.entity.EntityManager; +import org.terasology.engine.entitySystem.entity.EntityRef; +import org.terasology.engine.logic.inventory.ItemComponent; +import org.terasology.engine.registry.CoreRegistry; +import org.terasology.engine.rendering.assets.texture.TextureRegionAsset; +import org.terasology.engine.utilities.Assets; +import org.terasology.engine.world.block.Block; +import org.terasology.genome.component.GenomeComponent; +import org.terasology.genome.system.GenomeManager; +import org.terasology.herbalism.Herbalism; +import org.terasology.herbalism.component.HerbComponent; +import org.terasology.herbalism.system.HerbalismClientSystem; +import org.terasology.inventory.rendering.nui.layers.ingame.ItemIcon; +import org.terasology.nui.widgets.TooltipLine; import org.terasology.workstationCrafting.system.recipe.behaviour.ConsumeItemCraftBehaviour; import org.terasology.workstationCrafting.system.recipe.behaviour.IngredientCraftBehaviour; import org.terasology.workstationCrafting.system.recipe.behaviour.ReduceDurabilityCraftBehaviour; @@ -13,18 +25,6 @@ import org.terasology.workstationCrafting.system.recipe.hand.CraftInHandRecipe; import org.terasology.workstationCrafting.system.recipe.hand.PlayerInventorySlotResolver; import org.terasology.workstationCrafting.system.recipe.render.CraftIngredientRenderer; -import org.terasology.genome.component.GenomeComponent; -import org.terasology.genome.system.GenomeManager; -import org.terasology.herbalism.Herbalism; -import org.terasology.herbalism.component.HerbComponent; -import org.terasology.herbalism.system.HerbalismClientSystem; -import org.terasology.logic.inventory.ItemComponent; -import org.terasology.registry.CoreRegistry; -import org.terasology.rendering.assets.texture.TextureRegionAsset; -import org.terasology.rendering.nui.layers.ingame.inventory.ItemIcon; -import org.terasology.nui.widgets.TooltipLine; -import org.terasology.utilities.Assets; -import org.terasology.world.block.Block; import java.util.Arrays; import java.util.LinkedList; @@ -34,18 +34,23 @@ * A custom recipe format for seeding herb related recipes. Specifically for crafting herb seeds. */ public class SeedingHerbRecipe implements CraftInHandRecipe { - /** Define craft behavior for knifes. Specifically, reducing the knife's durability by 1 per crat. */ + /** + * Define craft behavior for knifes. Specifically, reducing the knife's durability by 1 per crat. + */ private static final IngredientCraftBehaviour KNIFE_BEHAVIOUR = new ReduceDurabilityCraftBehaviour( - new CraftInHandIngredientPredicate("WorkstationCrafting:knife"), 1, PlayerInventorySlotResolver.singleton()); + new CraftInHandIngredientPredicate("WorkstationCrafting:knife"), 1, + PlayerInventorySlotResolver.singleton()); - /** Define a herb consumption behavior. */ + /** + * Define a herb consumption behavior. + */ private static final ConsumeHerbBehaviour HERB_BEHAVIOUR = new ConsumeHerbBehaviour(); /** * Get a list of matching recipes for this character. * - * @param character The character entity that'll be doing the crafting. - * @return A list containing all matching seed recipe results. + * @param character The character entity that'll be doing the crafting. + * @return A list containing all matching seed recipe results. */ @Override public List getMatchingRecipeResults(EntityRef character) { @@ -69,8 +74,8 @@ public List getMatchingRecipeResults(EntityRef character) { /** * Ensure that this character entity actually has a knife. * - * @param character The character entity that'll be doing the crafting. - * @return The first valid knife parameter. + * @param character The character entity that'll be doing the crafting. + * @return The first valid knife parameter. */ private String getKnifeParameter(EntityRef character) { List parameters = KNIFE_BEHAVIOUR.getValidToCraft(character, 1); @@ -83,8 +88,8 @@ private String getKnifeParameter(EntityRef character) { /** * Convert a parameter (or ingredients) list into a Result. * - * @param parameters The list of parameters. - * @return A CraftInHandResult instance which hsa the methods necessary to create the final item. + * @param parameters The list of parameters. + * @return A CraftInHandResult instance which hsa the methods necessary to create the final item. */ @Override public CraftInHandResult getResultByParameters(List parameters) { @@ -95,16 +100,20 @@ public CraftInHandResult getResultByParameters(List parameters) { * This internal class is used to define the specific crafting result for the seeding herb recipe. */ public static final class Result implements CraftInHandResult { - /** List of recipe parameters required to make this result. */ - private List parameters; + /** + * List of recipe parameters required to make this result. + */ + private final List parameters; - /** List of ingredient renderers */ + /** + * List of ingredient renderers + */ private List renderers; /** * Create an instance of this class using a list of recipe parameters. * - * @param parameters List of items in the recipe that are required to craft the final product. + * @param parameters List of items in the recipe that are required to craft the final product. */ private Result(List parameters) { this.parameters = parameters; @@ -113,7 +122,7 @@ private Result(List parameters) { /** * Get the recipe parameters list. * - * @return A list containing the recipe parameters. + * @return A list containing the recipe parameters. */ @Override public List getParameters() { @@ -124,8 +133,8 @@ public List getParameters() { * Get the max consumption multiplier possible. This value multiplies the consumption effects in the * processIngredient method. * - * @param entity The entity that will be doing the crafting, and thus, has an inventory. - * @return The max multiplier. + * @param entity The entity that will be doing the crafting, and thus, has an inventory. + * @return The max multiplier. */ @Override public int getMaxMultiplier(EntityRef entity) { @@ -137,9 +146,9 @@ public int getMaxMultiplier(EntityRef entity) { /** * Craft the herb seed described in this recipe. * - * @param character The character entity doing the crafting. - * @param count The process multiplier. This multiplies the consumption effects of processIngredient. - * @return The crafted herb seed. + * @param character The character entity doing the crafting. + * @param count The process multiplier. This multiplies the consumption effects of processIngredient. + * @return The crafted herb seed. */ @Override public EntityRef craft(EntityRef character, int count) { @@ -164,12 +173,14 @@ public EntityRef craft(EntityRef character, int count) { // Add a seed component to the herb seed. SeedComponent seedComponent = new SeedComponent(); - seedComponent.blockPlaced = genomeManager.getGenomeProperty(herbSeed, Herbalism.PLANTED_BLOCK_PROPERTY, Block.class); + seedComponent.blockPlaced = genomeManager.getGenomeProperty(herbSeed, Herbalism.PLANTED_BLOCK_PROPERTY, + Block.class); herbSeed.addComponent(seedComponent); // Replace the icon with a seed bag image. ItemComponent itemComponent = herbSeed.getComponent(ItemComponent.class); - itemComponent.icon = Assets.getTextureRegion("AnotherWorldPlants:SeedBag(" + HERB_BEHAVIOUR.getHerbIconUri(parameters.get(1)) + ")").get(); + itemComponent.icon = + Assets.getTextureRegion("AnotherWorldPlants:SeedBag(" + HERB_BEHAVIOUR.getHerbIconUri(parameters.get(1)) + ")").get(); herbSeed.saveComponent(itemComponent); return herbSeed; @@ -179,9 +190,9 @@ public EntityRef craft(EntityRef character, int count) { * Check to see if it's possible for this entity to craft the given recipe with this consumption multiplier. * This multiplier multiplies the consumption effects in the processIngredient method. * - * @param entity The character entity doing the crafting. - * @param multiplier The consumption effects multiplier. - * @return True if possible to craft. False otherwise. + * @param entity The character entity doing the crafting. + * @param multiplier The consumption effects multiplier. + * @return True if possible to craft. False otherwise. */ @Override public boolean isValidForCrafting(EntityRef entity, int multiplier) { @@ -189,17 +200,14 @@ public boolean isValidForCrafting(EntityRef entity, int multiplier) { if (!KNIFE_BEHAVIOUR.isValidToCraft(entity, parameters.get(0), multiplier)) { return false; } - if (!HERB_BEHAVIOUR.isValidToCraft(entity, parameters.get(1), multiplier)) { - return false; - } - return true; + return HERB_BEHAVIOUR.isValidToCraft(entity, parameters.get(1), multiplier); } /** * Get the crafting ingredient renderers. These display the item icons in the crafting UI. * - * @param entity The entity that has the crafting UI. - * @return A list containing all of the CraftIngredientRenderers. + * @param entity The entity that has the crafting UI. + * @return A list containing all of the CraftIngredientRenderers. */ @Override public List getIngredientRenderers(EntityRef entity) { @@ -214,7 +222,7 @@ public List getIngredientRenderers(EntityRef entity) { /** * Get the crafting process duration. * - * @return 0, as this process is intended to be completed instantly. + * @return 0, as this process is intended to be completed instantly. */ @Override public long getProcessDuration() { @@ -224,7 +232,7 @@ public long getProcessDuration() { /** * Get the number of crafted items. * - * @return 1, as this process is intended only craft 1 herb seed at a time. + * @return 1, as this process is intended only craft 1 herb seed at a time. */ @Override public int getResultQuantity() { @@ -235,12 +243,13 @@ public int getResultQuantity() { * Setup the resultant herb seed's icon and tooltip lines. The former will be displayed on the crafting UI, and * the latter when the seed is moused over. * - * @param itemIcon The herb seed's item icon. + * @param itemIcon The herb seed's item icon. */ @Override public void setupResultDisplay(ItemIcon itemIcon) { itemIcon.setIcon(Assets.getTextureRegion("AnotherWorldPlants:SeedBag(" + HERB_BEHAVIOUR.getHerbIconUri(parameters.get(1)) + ")").get()); - itemIcon.setTooltipLines(Arrays.asList(new TooltipLine("Herb Seed"), HerbalismClientSystem.getHerbTooltipLine(HERB_BEHAVIOUR.getHerbName(parameters.get(1))))); + itemIcon.setTooltipLines(Arrays.asList(new TooltipLine("Herb Seed"), + HerbalismClientSystem.getHerbTooltipLine(HERB_BEHAVIOUR.getHerbName(parameters.get(1))))); } } @@ -257,7 +266,7 @@ public ConsumeHerbBehaviour() { * Apply an entity to this filter to see if it's an herb and if it has a genome. * * @param input Reference to the entity being checked. - * @return True if the entity fulfills the above conditions. False if not. + * @return True if the entity fulfills the above conditions. False if not. */ @Override public boolean apply(EntityRef input) { @@ -269,8 +278,8 @@ public boolean apply(EntityRef input) { /** * Return an integer list of workstation inventory slots this herb is present in. * - * @param parameter Name of the item being searched for. - * @return What inventory slots this item (likely a herb) is present in. + * @param parameter Name of the item being searched for. + * @return What inventory slots this item (likely a herb) is present in. */ @Override protected List getSlots(String parameter) { @@ -278,12 +287,12 @@ protected List getSlots(String parameter) { } /** - * Get the ingredient parameters and where they are located in the workstation's inventory, and return them as a String. - * If possible, add the genome parameters of the herbs to the parameter String. + * Get the ingredient parameters and where they are located in the workstation's inventory, and return them as a + * String. If possible, add the genome parameters of the herbs to the parameter String. * - * @param slots List of workstation inventory slots that the item is present in. - * @param item Reference to the herb item in question. - * @return The ingredient parameters of this item plus the genome information in a combined String. + * @param slots List of workstation inventory slots that the item is present in. + * @param item Reference to the herb item in question. + * @return The ingredient parameters of this item plus the genome information in a combined String. */ @Override protected String getParameter(List slots, EntityRef item) { @@ -291,7 +300,8 @@ protected String getParameter(List slots, EntityRef item) { final GenomeManager genomeManager = CoreRegistry.get(GenomeManager.class); String herbName = genomeManager.getGenomeProperty(item, Herbalism.NAME_PROPERTY, String.class); - String herbIconUri = (genomeManager.getGenomeProperty(item, Herbalism.ICON_PROPERTY, TextureRegionAsset.class)).getUrn().toString(); + String herbIconUri = (genomeManager.getGenomeProperty(item, Herbalism.ICON_PROPERTY, + TextureRegionAsset.class)).getUrn().toString(); return super.getParameter(slots, item) + "|" + genome.genes + "|" + herbName + "|" + herbIconUri; } @@ -299,8 +309,8 @@ protected String getParameter(List slots, EntityRef item) { /** * Extract the seed genome from the seeding herb recipe parameters. * - * @param parameter The recipe parameters in one String. - * @return A String containing the seed genome. + * @param parameter The recipe parameters in one String. + * @return A String containing the seed genome. */ public String getSeedGenome(String parameter) { return parameter.split("\\|")[1]; @@ -309,8 +319,8 @@ public String getSeedGenome(String parameter) { /** * Extract the herb name from the seeding herb recipe parameters. * - * @param parameter The recipe parameters in one String. - * @return A String containing the herb name. + * @param parameter The recipe parameters in one String. + * @return A String containing the herb name. */ public String getHerbName(String parameter) { return parameter.split("\\|")[2]; @@ -319,8 +329,8 @@ public String getHerbName(String parameter) { /** * Extract the herb icon URI from the seeding herb recipe parameters. * - * @param parameter The recipe parameters in one String. - * @return A String containing the herb icon URI. + * @param parameter The recipe parameters in one String. + * @return A String containing the herb icon URI. */ public String getHerbIconUri(String parameter) { return parameter.split("\\|")[3]; diff --git a/src/main/java/org/terasology/herbalism/DefaultHerbEffectRegistry.java b/src/main/java/org/terasology/herbalism/DefaultHerbEffectRegistry.java index 60d217d..36e6471 100644 --- a/src/main/java/org/terasology/herbalism/DefaultHerbEffectRegistry.java +++ b/src/main/java/org/terasology/herbalism/DefaultHerbEffectRegistry.java @@ -1,25 +1,12 @@ -/* - * Copyright 2014 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.herbalism; import org.terasology.anotherWorld.util.ChanceRandomizer; -import org.terasology.entitySystem.systems.BaseComponentSystem; -import org.terasology.entitySystem.systems.RegisterSystem; +import org.terasology.engine.entitySystem.systems.BaseComponentSystem; +import org.terasology.engine.entitySystem.systems.RegisterSystem; +import org.terasology.engine.registry.Share; import org.terasology.potions.HerbEffect; -import org.terasology.registry.Share; /** * This class is used for storing and retrieving the default herb effects in a registry format. @@ -27,8 +14,10 @@ @RegisterSystem @Share(HerbEffectRegistry.class) public class DefaultHerbEffectRegistry extends BaseComponentSystem implements HerbEffectRegistry { - /** Randomizer for selecting herb effects. */ - private ChanceRandomizer herbEffectRandomizer = new ChanceRandomizer<>(1000); + /** + * Randomizer for selecting herb effects. + */ + private final ChanceRandomizer herbEffectRandomizer = new ChanceRandomizer<>(1000); @Override public void postBegin() { @@ -37,8 +26,9 @@ public void postBegin() { /** * Register an herb effect into the registry. It can later be retrieved. - * @param rarity How often should this effect occur. - * @param herbEffect What the effect is. + * + * @param rarity How often should this effect occur. + * @param herbEffect What the effect is. */ @Override public void registerHerbEffect(float rarity, HerbEffect herbEffect) { @@ -47,8 +37,9 @@ public void registerHerbEffect(float rarity, HerbEffect herbEffect) { /** * Return an herb effect based on the input value. Though, the effect returned is random. - * @param value Value of the effect. - * @return A random herb effect. + * + * @param value Value of the effect. + * @return A random herb effect. */ @Override public HerbEffect getHerbEffect(float value) { diff --git a/src/main/java/org/terasology/herbalism/HerbEffectRegistry.java b/src/main/java/org/terasology/herbalism/HerbEffectRegistry.java index 21cb4c6..821f2f6 100644 --- a/src/main/java/org/terasology/herbalism/HerbEffectRegistry.java +++ b/src/main/java/org/terasology/herbalism/HerbEffectRegistry.java @@ -1,18 +1,5 @@ -/* - * Copyright 2014 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.herbalism; import org.terasology.potions.HerbEffect; @@ -23,15 +10,17 @@ public interface HerbEffectRegistry { /** * Register a herb effect and its rarity of happening. - * @param rarity How often should this effect occur. - * @param herbEffect What the effect is. + * + * @param rarity How often should this effect occur. + * @param herbEffect What the effect is. */ void registerHerbEffect(float rarity, HerbEffect herbEffect); /** * Get a herb effect based on its value in the herb effect array. - * @param value Value of the effect. - * @return The HerbEffect. + * + * @param value Value of the effect. + * @return The HerbEffect. */ HerbEffect getHerbEffect(float value); } diff --git a/src/main/java/org/terasology/herbalism/HerbNameProvider.java b/src/main/java/org/terasology/herbalism/HerbNameProvider.java index d8f5b6d..cb67313 100644 --- a/src/main/java/org/terasology/herbalism/HerbNameProvider.java +++ b/src/main/java/org/terasology/herbalism/HerbNameProvider.java @@ -1,23 +1,10 @@ -/* - * Copyright 2016 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.herbalism; +import org.terasology.engine.utilities.Assets; import org.terasology.namegenerator.data.NameGeneratorComponent; import org.terasology.namegenerator.generators.MarkovNameGenerator; -import org.terasology.utilities.Assets; import java.util.List; @@ -25,20 +12,26 @@ * Randomly provides names for herbs from a predetermined list. */ public class HerbNameProvider { - /** Markov name generator for a generation of herbs. */ + /** + * Markov name generator for a generation of herbs. + */ private final MarkovNameGenerator generaGen; - /** Markov name generator for a family of herbs. */ + /** + * Markov name generator for a family of herbs. + */ private final MarkovNameGenerator familyGen; /** * Create an instance of this class using an input seed for the randomization. * - * @param seed An integer value used for randomizing the output names. + * @param seed An integer value used for randomizing the output names. */ public HerbNameProvider(int seed) { - final List families = Assets.getPrefab("NameGenerator:floweringPlantsFamilies").get().getComponent(NameGeneratorComponent.class).nameList; - final List generas = Assets.getPrefab("NameGenerator:floweringPlantsGenera").get().getComponent(NameGeneratorComponent.class).nameList; + final List families = + Assets.getPrefab("NameGenerator:floweringPlantsFamilies").get().getComponent(NameGeneratorComponent.class).nameList; + final List generas = + Assets.getPrefab("NameGenerator:floweringPlantsGenera").get().getComponent(NameGeneratorComponent.class).nameList; generaGen = new MarkovNameGenerator(seed, generas); familyGen = new MarkovNameGenerator(seed + 937623, families); @@ -47,11 +40,12 @@ public HerbNameProvider(int seed) { /** * Get a herb name (generation + family) using an input seed. * - * @param seed An integer value used for randomly picking the output name. - * @return A randomized name for an herb. + * @param seed An integer value used for randomly picking the output name. + * @return A randomized name for an herb. */ public String getName(String seed) { int length = seed.length(); - return generaGen.getName(4, 8, seed.substring(0, length / 2).hashCode()) + " " + familyGen.getName(4, 8, seed.substring(0, length).hashCode()); + return generaGen.getName(4, 8, seed.substring(0, length / 2).hashCode()) + " " + familyGen.getName(4, 8, + seed.substring(0, length).hashCode()); } } diff --git a/src/main/java/org/terasology/herbalism/component/GeneratedHerbComponent.java b/src/main/java/org/terasology/herbalism/component/GeneratedHerbComponent.java index 56c1182..7b5a67d 100644 --- a/src/main/java/org/terasology/herbalism/component/GeneratedHerbComponent.java +++ b/src/main/java/org/terasology/herbalism/component/GeneratedHerbComponent.java @@ -1,26 +1,15 @@ -/* - * Copyright 2014 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.herbalism.component; -import org.terasology.entitySystem.Component; +import org.terasology.engine.entitySystem.Component; /** * This component is used for storing the base genome of a generated herb. */ public final class GeneratedHerbComponent implements Component { - /** A string description of this herb's base genome. */ + /** + * A string description of this herb's base genome. + */ public String herbBaseGenome; } diff --git a/src/main/java/org/terasology/herbalism/component/HerbComponent.java b/src/main/java/org/terasology/herbalism/component/HerbComponent.java index faacaf6..bc2ad0d 100644 --- a/src/main/java/org/terasology/herbalism/component/HerbComponent.java +++ b/src/main/java/org/terasology/herbalism/component/HerbComponent.java @@ -1,21 +1,8 @@ -/* - * Copyright 2014 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.herbalism.component; -import org.terasology.entitySystem.Component; +import org.terasology.engine.entitySystem.Component; /** * Add this component to an item to indicate that it is a herb. diff --git a/src/main/java/org/terasology/herbalism/component/HerbHueComponent.java b/src/main/java/org/terasology/herbalism/component/HerbHueComponent.java index cde1778..1972690 100644 --- a/src/main/java/org/terasology/herbalism/component/HerbHueComponent.java +++ b/src/main/java/org/terasology/herbalism/component/HerbHueComponent.java @@ -1,21 +1,8 @@ -/* - * Copyright 2014 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.herbalism.component; -import org.terasology.entitySystem.Component; +import org.terasology.engine.entitySystem.Component; import java.util.List; diff --git a/src/main/java/org/terasology/herbalism/component/HerbalismStationRecipeComponent.java b/src/main/java/org/terasology/herbalism/component/HerbalismStationRecipeComponent.java index bd19d67..81dc3ca 100644 --- a/src/main/java/org/terasology/herbalism/component/HerbalismStationRecipeComponent.java +++ b/src/main/java/org/terasology/herbalism/component/HerbalismStationRecipeComponent.java @@ -1,27 +1,14 @@ -/* - * Copyright 2016 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.herbalism.component; -import org.terasology.entitySystem.Component; +import org.terasology.engine.entitySystem.Component; import java.util.List; /** - * Add this Component to any recipe prefab that is supposed to be creatable in a HerbalismStation or similar. - * Include in prefab along with CraftingStationRecipeComponent to work properly. + * Add this Component to any recipe prefab that is supposed to be creatable in a HerbalismStation or similar. Include in + * prefab along with CraftingStationRecipeComponent to work properly. */ public class HerbalismStationRecipeComponent implements Component { // The following variables are unused. diff --git a/src/main/java/org/terasology/herbalism/component/PollinatingHerbComponent.java b/src/main/java/org/terasology/herbalism/component/PollinatingHerbComponent.java index 9bbd446..80bba39 100644 --- a/src/main/java/org/terasology/herbalism/component/PollinatingHerbComponent.java +++ b/src/main/java/org/terasology/herbalism/component/PollinatingHerbComponent.java @@ -1,21 +1,8 @@ -/* - * Copyright 2014 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.herbalism.component; -import org.terasology.entitySystem.Component; +import org.terasology.engine.entitySystem.Component; /** * Add this component to an item (specficially an herb) to indicate that it's pollinating. diff --git a/src/main/java/org/terasology/herbalism/component/PredefinedHerbComponent.java b/src/main/java/org/terasology/herbalism/component/PredefinedHerbComponent.java index 89bd322..131427c 100644 --- a/src/main/java/org/terasology/herbalism/component/PredefinedHerbComponent.java +++ b/src/main/java/org/terasology/herbalism/component/PredefinedHerbComponent.java @@ -1,25 +1,12 @@ -/* - * Copyright 2016 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.herbalism.component; -import org.terasology.entitySystem.Component; +import org.terasology.engine.entitySystem.Component; /** - * Add this component to an item to indicate that it is a predefined herb. That is, a prefab was directly used to generate - * this. + * Add this component to an item to indicate that it is a predefined herb. That is, a prefab was directly used to + * generate this. */ public final class PredefinedHerbComponent implements Component { public String herbBaseGenome; diff --git a/src/main/java/org/terasology/herbalism/generator/Blocks.java b/src/main/java/org/terasology/herbalism/generator/Blocks.java index ca8b4e2..b771f27 100644 --- a/src/main/java/org/terasology/herbalism/generator/Blocks.java +++ b/src/main/java/org/terasology/herbalism/generator/Blocks.java @@ -1,23 +1,10 @@ -/* - * Copyright 2016 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.herbalism.generator; -import org.terasology.registry.CoreRegistry; -import org.terasology.world.block.Block; -import org.terasology.world.block.BlockManager; +import org.terasology.engine.registry.CoreRegistry; +import org.terasology.engine.world.block.Block; +import org.terasology.engine.world.block.BlockManager; /** * A utility class used for simplifying getting blocks from the BlockManager. @@ -29,8 +16,8 @@ private Blocks() { /** * Gets a block from the BlockManager using the blockID. * - * @param blockId ID of the block. - * @return The block type with the matching ID. + * @param blockId ID of the block. + * @return The block type with the matching ID. */ public static Block getBlock(String blockId) { return CoreRegistry.get(BlockManager.class).getBlock(blockId); diff --git a/src/main/java/org/terasology/herbalism/generator/HerbAGrowthDefinition.java b/src/main/java/org/terasology/herbalism/generator/HerbAGrowthDefinition.java index 480d6b7..8898dea 100644 --- a/src/main/java/org/terasology/herbalism/generator/HerbAGrowthDefinition.java +++ b/src/main/java/org/terasology/herbalism/generator/HerbAGrowthDefinition.java @@ -1,33 +1,20 @@ -/* - * Copyright 2014 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.herbalism.generator; import com.google.common.base.Function; import com.google.common.base.Predicate; import org.terasology.anotherWorld.LocalParameters; -import org.terasology.entitySystem.entity.EntityRef; +import org.terasology.engine.entitySystem.entity.EntityRef; +import org.terasology.engine.registry.CoreRegistry; +import org.terasology.engine.world.BlockEntityRegistry; +import org.terasology.engine.world.WorldProvider; +import org.terasology.engine.world.block.BlockManager; +import org.terasology.engine.world.block.BlockUri; +import org.terasology.engine.world.generator.plugin.RegisterPlugin; import org.terasology.genome.component.GenomeComponent; import org.terasology.gf.grass.ReplaceBlockGrowthDefinition; import org.terasology.math.geom.Vector3i; -import org.terasology.registry.CoreRegistry; -import org.terasology.world.BlockEntityRegistry; -import org.terasology.world.WorldProvider; -import org.terasology.world.block.BlockManager; -import org.terasology.world.block.BlockUri; -import org.terasology.world.generator.plugin.RegisterPlugin; import java.util.Arrays; @@ -43,7 +30,8 @@ public class HerbAGrowthDefinition extends ReplaceBlockGrowthDefinition { */ public HerbAGrowthDefinition() { super(ID, Arrays.asList( - new BlockUri("Alchemy:HerbGrowA"), new BlockUri("Alchemy:HerbGrownA"), new BlockUri("CoreAssets:DeadBush")), + new BlockUri("Alchemy:HerbGrowA"), new BlockUri("Alchemy:HerbGrownA"), new BlockUri("CoreAssets" + + ":DeadBush")), 50 * 1000, 200 * 1000, new Predicate() { @Override @@ -63,16 +51,18 @@ public Float apply(LocalParameters input) { /** * Replace this particular herb plant block with the next stage of the herb plant block. * - * @param worldProvider WorldProvider instance to interface with the game world blocks. - * @param blockManager BlockManager instance to get the specific block type. - * @param plant Reference to the herb plant. - * @param position World position of the plant block in Vector3 coordinates. - * @param nextStage Next stage of the herb plant (block) growth. - * @param isLast Whether this is the last stage of herb plant growth. + * @param worldProvider WorldProvider instance to interface with the game world blocks. + * @param blockManager BlockManager instance to get the specific block type. + * @param plant Reference to the herb plant. + * @param position World position of the plant block in Vector3 coordinates. + * @param nextStage Next stage of the herb plant (block) growth. + * @param isLast Whether this is the last stage of herb plant growth. */ @Override - protected void replaceBlock(WorldProvider worldProvider, BlockManager blockManager, EntityRef plant, Vector3i position, BlockUri nextStage, boolean isLast) { - // If this is not the last stage of herb plant growth, continue as normal. Otherwise, just call the parent method. + protected void replaceBlock(WorldProvider worldProvider, BlockManager blockManager, EntityRef plant, + Vector3i position, BlockUri nextStage, boolean isLast) { + // If this is not the last stage of herb plant growth, continue as normal. Otherwise, just call the parent + // method. if (!isLast) { // We need to copy the genome between growth stages. Otherwise it will be lost upon replacing this block. final GenomeComponent genome = plant.getComponent(GenomeComponent.class); diff --git a/src/main/java/org/terasology/herbalism/generator/HerbDesertSpawnDefinition.java b/src/main/java/org/terasology/herbalism/generator/HerbDesertSpawnDefinition.java index a02c114..8f973d7 100644 --- a/src/main/java/org/terasology/herbalism/generator/HerbDesertSpawnDefinition.java +++ b/src/main/java/org/terasology/herbalism/generator/HerbDesertSpawnDefinition.java @@ -1,26 +1,13 @@ -/* - * Copyright 2016 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.herbalism.generator; import org.terasology.anotherWorld.AnotherWorldBiomes; import org.terasology.anotherWorld.decorator.BlockCollectionPredicate; +import org.terasology.engine.world.block.BlockUri; +import org.terasology.engine.world.generator.plugin.RegisterPlugin; import org.terasology.gf.PlantType; import org.terasology.gf.generator.StaticBlockFloraSpawnDefinition; -import org.terasology.world.block.BlockUri; -import org.terasology.world.generator.plugin.RegisterPlugin; import java.util.Arrays; diff --git a/src/main/java/org/terasology/herbalism/generator/HerbForestSpawnDefinition.java b/src/main/java/org/terasology/herbalism/generator/HerbForestSpawnDefinition.java index cc38c9b..609fbef 100644 --- a/src/main/java/org/terasology/herbalism/generator/HerbForestSpawnDefinition.java +++ b/src/main/java/org/terasology/herbalism/generator/HerbForestSpawnDefinition.java @@ -1,26 +1,13 @@ -/* - * Copyright 2016 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.herbalism.generator; import org.terasology.anotherWorld.AnotherWorldBiomes; import org.terasology.anotherWorld.decorator.BlockCollectionPredicate; +import org.terasology.engine.world.block.BlockUri; +import org.terasology.engine.world.generator.plugin.RegisterPlugin; import org.terasology.gf.PlantType; import org.terasology.gf.generator.StaticBlockFloraSpawnDefinition; -import org.terasology.world.block.BlockUri; -import org.terasology.world.generator.plugin.RegisterPlugin; import java.util.Arrays; diff --git a/src/main/java/org/terasology/herbalism/generator/HerbPlainsSpawnDefinition.java b/src/main/java/org/terasology/herbalism/generator/HerbPlainsSpawnDefinition.java index 2c758c9..d548632 100644 --- a/src/main/java/org/terasology/herbalism/generator/HerbPlainsSpawnDefinition.java +++ b/src/main/java/org/terasology/herbalism/generator/HerbPlainsSpawnDefinition.java @@ -1,26 +1,13 @@ -/* - * Copyright 2016 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.herbalism.generator; import org.terasology.anotherWorld.AnotherWorldBiomes; import org.terasology.anotherWorld.decorator.BlockCollectionPredicate; +import org.terasology.engine.world.block.BlockUri; +import org.terasology.engine.world.generator.plugin.RegisterPlugin; import org.terasology.gf.PlantType; import org.terasology.gf.generator.StaticBlockFloraSpawnDefinition; -import org.terasology.world.block.BlockUri; -import org.terasology.world.generator.plugin.RegisterPlugin; import java.util.Arrays; diff --git a/src/main/java/org/terasology/herbalism/generator/HerbTundraSpawnDefinition.java b/src/main/java/org/terasology/herbalism/generator/HerbTundraSpawnDefinition.java index 955f98b..80b2334 100644 --- a/src/main/java/org/terasology/herbalism/generator/HerbTundraSpawnDefinition.java +++ b/src/main/java/org/terasology/herbalism/generator/HerbTundraSpawnDefinition.java @@ -1,26 +1,13 @@ -/* - * Copyright 2016 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.herbalism.generator; import org.terasology.anotherWorld.AnotherWorldBiomes; import org.terasology.anotherWorld.decorator.BlockCollectionPredicate; +import org.terasology.engine.world.block.BlockUri; +import org.terasology.engine.world.generator.plugin.RegisterPlugin; import org.terasology.gf.PlantType; import org.terasology.gf.generator.StaticBlockFloraSpawnDefinition; -import org.terasology.world.block.BlockUri; -import org.terasology.world.generator.plugin.RegisterPlugin; import java.util.Arrays; diff --git a/src/main/java/org/terasology/herbalism/system/HerbDropAuthoritySystem.java b/src/main/java/org/terasology/herbalism/system/HerbDropAuthoritySystem.java index cfba2d0..26048da 100644 --- a/src/main/java/org/terasology/herbalism/system/HerbDropAuthoritySystem.java +++ b/src/main/java/org/terasology/herbalism/system/HerbDropAuthoritySystem.java @@ -1,26 +1,25 @@ -/* - * Copyright 2014 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.herbalism.system; -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.RegisterMode; -import org.terasology.entitySystem.systems.RegisterSystem; +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.RegisterMode; +import org.terasology.engine.entitySystem.systems.RegisterSystem; +import org.terasology.engine.logic.destruction.DoDestroyEvent; +import org.terasology.engine.logic.inventory.ItemComponent; +import org.terasology.engine.logic.inventory.events.DropItemEvent; +import org.terasology.engine.logic.location.LocationComponent; +import org.terasology.engine.physics.events.ImpulseEvent; +import org.terasology.engine.registry.In; +import org.terasology.engine.rendering.assets.texture.TextureRegionAsset; +import org.terasology.engine.utilities.random.FastRandom; +import org.terasology.engine.utilities.random.Random; +import org.terasology.engine.world.WorldProvider; +import org.terasology.engine.world.block.entity.CreateBlockDropsEvent; +import org.terasology.engine.world.block.entity.damage.BlockDamageModifierComponent; import org.terasology.genome.breed.BiodiversityGenerator; import org.terasology.genome.component.GenomeComponent; import org.terasology.genome.system.GenomeManager; @@ -29,22 +28,10 @@ import org.terasology.herbalism.component.GeneratedHerbComponent; import org.terasology.herbalism.component.HerbComponent; import org.terasology.herbalism.component.PredefinedHerbComponent; -import org.terasology.logic.health.DoDestroyEvent; -import org.terasology.logic.inventory.InventoryManager; -import org.terasology.logic.inventory.ItemComponent; -import org.terasology.logic.inventory.events.DropItemEvent; -import org.terasology.logic.location.LocationComponent; +import org.terasology.inventory.logic.InventoryManager; import org.terasology.math.TeraMath; import org.terasology.math.geom.Vector2i; import org.terasology.math.geom.Vector3f; -import org.terasology.physics.events.ImpulseEvent; -import org.terasology.registry.In; -import org.terasology.rendering.assets.texture.TextureRegionAsset; -import org.terasology.utilities.random.FastRandom; -import org.terasology.utilities.random.Random; -import org.terasology.world.WorldProvider; -import org.terasology.world.block.entity.CreateBlockDropsEvent; -import org.terasology.world.block.entity.damage.BlockDamageModifierComponent; /** * Authority system for managing what happens when a herb drops onto the world. @@ -60,7 +47,9 @@ public class HerbDropAuthoritySystem extends BaseComponentSystem { @In private InventoryManager inventoryManager; - /** Random number generator. */ + /** + * Random number generator. + */ private Random random; /** @@ -74,9 +63,9 @@ public void preBegin() { /** * When a destroyed block drops an item that has a GeneratedHerbComponent, intercept and consume the event. * - * @param event Information about the block drop. - * @param blockEntity The block entity in question that was destroyed. - * @param component Used as a delimiter to filter out block drops that are not generated herbs. + * @param event Information about the block drop. + * @param blockEntity The block entity in question that was destroyed. + * @param component Used as a delimiter to filter out block drops that are not generated herbs. */ @ReceiveEvent public void whenBlockDropped(CreateBlockDropsEvent event, EntityRef blockEntity, GeneratedHerbComponent component) { @@ -86,9 +75,9 @@ public void whenBlockDropped(CreateBlockDropsEvent event, EntityRef blockEntity, /** * When a destroyed block drops an item that has a HerbComponent, intercept and consume the event. * - * @param event Information about the block drop. - * @param blockEntity The block entity in question that was destroyed. - * @param component Used as a delimiter to filter out block drops that are not herbs. + * @param event Information about the block drop. + * @param blockEntity The block entity in question that was destroyed. + * @param component Used as a delimiter to filter out block drops that are not herbs. */ @ReceiveEvent public void whenBlockDropped(CreateBlockDropsEvent event, EntityRef blockEntity, HerbComponent component) { @@ -98,20 +87,24 @@ public void whenBlockDropped(CreateBlockDropsEvent event, EntityRef blockEntity, /** * When a grown herb block (or plant) is destroyed, determine if it should drop an herb item. * - * @param event Information about the destruction. - * @param entity Reference to the herb block entity. - * @param herbComp Used as a delimiter to filter out blocks that are not herbs. - * @param genomeComponent Genome of the herb block. - * @param locationComp Where was the herb block located in the world. + * @param event Information about the destruction. + * @param entity Reference to the herb block entity. + * @param herbComp Used as a delimiter to filter out blocks that are not herbs. + * @param genomeComponent Genome of the herb block. + * @param locationComp Where was the herb block located in the world. */ @ReceiveEvent - public void onGrownHerbDestroyed(DoDestroyEvent event, EntityRef entity, HerbComponent herbComp, GenomeComponent genomeComponent, LocationComponent locationComp) { + public void onGrownHerbDestroyed(DoDestroyEvent event, EntityRef entity, HerbComponent herbComp, + GenomeComponent genomeComponent, LocationComponent locationComp) { // Get the block damage modifier and set the block drop chance to 1 (that is, 0%). - BlockDamageModifierComponent blockDamageModifierComponent = event.getDamageType().getComponent(BlockDamageModifierComponent.class); + BlockDamageModifierComponent blockDamageModifierComponent = + event.getDamageType().getComponent(BlockDamageModifierComponent.class); float chanceOfBlockDrop = 1; - // This check is done to ensure that the herb destroyed is actually a plant (or block). If it's an item, it cannot - // have this component. Thus, it'll be impossible to drop a herb from it. Otherwise, proceed normally by adjusting + // This check is done to ensure that the herb destroyed is actually a plant (or block). If it's an item, it + // cannot + // have this component. Thus, it'll be impossible to drop a herb from it. Otherwise, proceed normally by + // adjusting // the drop rate using the blockAnnihilationChance. if (blockDamageModifierComponent != null) { chanceOfBlockDrop = 1 - blockDamageModifierComponent.blockAnnihilationChance; @@ -144,19 +137,23 @@ public void onGrownHerbDestroyed(DoDestroyEvent event, EntityRef entity, HerbCom /** * When a generated herb is destroyed, determine if it should drop an herb item. * - * @param event Information about the destruction. - * @param entity Reference to the herb block entity. - * @param herbComp Used as a delimiter to filter out blocks that are not generated herbs. - * @param locationComp Where was the herb block located in the world. + * @param event Information about the destruction. + * @param entity Reference to the herb block entity. + * @param herbComp Used as a delimiter to filter out blocks that are not generated herbs. + * @param locationComp Where was the herb block located in the world. */ @ReceiveEvent - public void onGeneratedHerbDestroyed(DoDestroyEvent event, EntityRef entity, GeneratedHerbComponent herbComp, LocationComponent locationComp) { + public void onGeneratedHerbDestroyed(DoDestroyEvent event, EntityRef entity, GeneratedHerbComponent herbComp, + LocationComponent locationComp) { // Get the block damage modifier and set the block drop chance to 1 (that is, 0%). - BlockDamageModifierComponent blockDamageModifierComponent = event.getDamageType().getComponent(BlockDamageModifierComponent.class); + BlockDamageModifierComponent blockDamageModifierComponent = + event.getDamageType().getComponent(BlockDamageModifierComponent.class); float chanceOfBlockDrop = 1; - // This check is done to ensure that the herb destroyed is actually a plant (or block). If it's an item, it cannot - // have this component. Thus, it'll be impossible to drop a herb from it. Otherwise, proceed normally by adjusting + // This check is done to ensure that the herb destroyed is actually a plant (or block). If it's an item, it + // cannot + // have this component. Thus, it'll be impossible to drop a herb from it. Otherwise, proceed normally by + // adjusting // the drop rate using the blockAnnihilationChance. if (blockDamageModifierComponent != null) { chanceOfBlockDrop = 1 - blockDamageModifierComponent.blockAnnihilationChance; @@ -168,9 +165,11 @@ public void onGeneratedHerbDestroyed(DoDestroyEvent event, EntityRef entity, Gen final Vector3f position = locationComp.getWorldPosition(); // Using a BiodiversityGenerator, create a new set of (mutated) genes. - BiodiversityGenerator generator = new BiodiversityGenerator(worldProvider.getSeed(), 0, new HerbGeneMutator(), herbBaseGenome, + BiodiversityGenerator generator = new BiodiversityGenerator(worldProvider.getSeed(), 0, + new HerbGeneMutator(), herbBaseGenome, 3, 0.0002f); - final String generatedGenes = generator.generateGenes(new Vector2i(TeraMath.floorToInt(position.x + 0.5f), TeraMath.floorToInt(position.z + 0.5f))); + final String generatedGenes = generator.generateGenes(new Vector2i(TeraMath.floorToInt(position.x + 0.5f) + , TeraMath.floorToInt(position.z + 0.5f))); // Create a herb. EntityRef herb = entityManager.create("Alchemy:HerbBase"); @@ -181,7 +180,8 @@ public void onGeneratedHerbDestroyed(DoDestroyEvent event, EntityRef entity, Gen genomeComponent.genes = generatedGenes; herb.addComponent(genomeComponent); - // Set the icon of the herb. Due to a glitch with PredefinedHerbs, the icon setting has been temporarily disabled. + // Set the icon of the herb. Due to a glitch with PredefinedHerbs, the icon setting has been temporarily + // disabled. final ItemComponent item = herb.getComponent(ItemComponent.class); //item.icon = genomeManager.getGenomeProperty(herb, Herbalism.ICON_PROPERTY, TextureRegionAsset.class); herb.saveComponent(item); @@ -196,19 +196,23 @@ public void onGeneratedHerbDestroyed(DoDestroyEvent event, EntityRef entity, Gen /** * When a predefined herb is destroyed, determine if it should drop an herb item. * - * @param event Information about the destruction. - * @param entity Reference to the herb block entity. - * @param herbComp Used as a delimiter to filter out blocks that are not predefined herbs. - * @param locationComp Where was the herb block located in the world. + * @param event Information about the destruction. + * @param entity Reference to the herb block entity. + * @param herbComp Used as a delimiter to filter out blocks that are not predefined herbs. + * @param locationComp Where was the herb block located in the world. */ @ReceiveEvent - public void onPredefinedHerbDestroyed(DoDestroyEvent event, EntityRef entity, PredefinedHerbComponent herbComp, LocationComponent locationComp) { + public void onPredefinedHerbDestroyed(DoDestroyEvent event, EntityRef entity, PredefinedHerbComponent herbComp, + LocationComponent locationComp) { // Get the block damage modifier and set the block drop chance to 1 (that is, 0%). - BlockDamageModifierComponent blockDamageModifierComponent = event.getDamageType().getComponent(BlockDamageModifierComponent.class); + BlockDamageModifierComponent blockDamageModifierComponent = + event.getDamageType().getComponent(BlockDamageModifierComponent.class); float chanceOfBlockDrop = 1; - // This check is done to ensure that the herb destroyed is actually a plant (or block). If it's an item, it cannot - // have this component. Thus, it'll be impossible to drop a herb from it. Otherwise, proceed normally by adjusting + // This check is done to ensure that the herb destroyed is actually a plant (or block). If it's an item, it + // cannot + // have this component. Thus, it'll be impossible to drop a herb from it. Otherwise, proceed normally by + // adjusting // the drop rate using the blockAnnihilationChance. if (blockDamageModifierComponent != null) { chanceOfBlockDrop = 1 - blockDamageModifierComponent.blockAnnihilationChance; @@ -231,16 +235,18 @@ public void onPredefinedHerbDestroyed(DoDestroyEvent event, EntityRef entity, Pr /** * Determine whether the given item should be dropped onto the world. * - * @param event Information about the entity's destruction. - * @param blockDamageModifierComponent And damage modifiers for the block. - * @param dropItem The item to be dropped onto the world. - * @return True if the item should be dropped, false if not. + * @param event Information about the entity's destruction. + * @param blockDamageModifierComponent And damage modifiers for the block. + * @param dropItem The item to be dropped onto the world. + * @return True if the item should be dropped, false if not. */ - private boolean shouldDropToWorld(DoDestroyEvent event, BlockDamageModifierComponent blockDamageModifierComponent, EntityRef dropItem) { + private boolean shouldDropToWorld(DoDestroyEvent event, BlockDamageModifierComponent blockDamageModifierComponent + , EntityRef dropItem) { // Get the instigator of this entity's destruction. EntityRef instigator = event.getInstigator(); - // If there are no block damage modifiers, no direct pickup, or giving the item directly to the instigator fails, + // If there are no block damage modifiers, no direct pickup, or giving the item directly to the instigator + // fails, // return true. return blockDamageModifierComponent == null || !blockDamageModifierComponent.directPickup || !inventoryManager.giveItem(instigator, instigator, dropItem); diff --git a/src/main/java/org/terasology/herbalism/system/HerbIconAssetResolver.java b/src/main/java/org/terasology/herbalism/system/HerbIconAssetResolver.java index 0be0eb7..c04341e 100644 --- a/src/main/java/org/terasology/herbalism/system/HerbIconAssetResolver.java +++ b/src/main/java/org/terasology/herbalism/system/HerbIconAssetResolver.java @@ -1,30 +1,17 @@ -/* - * Copyright 2016 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.herbalism.system; import com.google.common.collect.ImmutableSet; +import org.terasology.engine.rendering.assets.texture.Texture; +import org.terasology.engine.rendering.assets.texture.TextureData; +import org.terasology.engine.rendering.assets.texture.TextureRegionAsset; +import org.terasology.engine.rendering.assets.texture.TextureUtil; import org.terasology.gestalt.assets.AssetDataProducer; import org.terasology.gestalt.assets.ResourceUrn; import org.terasology.gestalt.assets.management.AssetManager; import org.terasology.gestalt.assets.module.annotations.RegisterAssetDataProducer; import org.terasology.gestalt.naming.Name; -import org.terasology.rendering.assets.texture.Texture; -import org.terasology.rendering.assets.texture.TextureData; -import org.terasology.rendering.assets.texture.TextureRegionAsset; -import org.terasology.rendering.assets.texture.TextureUtil; import java.awt.Color; import java.awt.image.BufferedImage; @@ -38,17 +25,21 @@ * This class is used to provide asset data for the creation of herb icons. */ @RegisterAssetDataProducer -public class HerbIconAssetResolver implements AssetDataProducer { - /** Constant used for storing the name of this module. */ +public class HerbIconAssetResolver implements AssetDataProducer { + /** + * Constant used for storing the name of this module. + */ private static final Name HERBALISM_MODULE = new Name("herbalism"); - /** AssetManager which will be used to manage the herb assets. */ - private AssetManager assetManager; + /** + * AssetManager which will be used to manage the herb assets. + */ + private final AssetManager assetManager; /** * Create a new instance of this class using an instance of AssetManager to later work with assets. * - * @param assetManager Instance of an asset manager that will be used to interface with multiple assets. + * @param assetManager Instance of an asset manager that will be used to interface with multiple assets. */ public HerbIconAssetResolver(AssetManager assetManager) { this.assetManager = assetManager; @@ -57,16 +48,16 @@ public HerbIconAssetResolver(AssetManager assetManager) { /** * Create a URI for this herb using the given iconURI and the herb hue values. * - * @param iconUri String containing the herb icon's URI. - * @param hueValues Float array containing the herb colors. - * @return URI for the herb icon containing both the base URI and all of the hue values. + * @param iconUri String containing the herb icon's URI. + * @param hueValues Float array containing the herb colors. + * @return URI for the herb icon containing both the base URI and all of the hue values. */ public static String getHerbUri(String iconUri, float[] hueValues) { StringBuilder sb = new StringBuilder(); sb.append("Alchemy:Herb("); sb.append(iconUri); for (float hueValue : hueValues) { - sb.append(",").append(String.valueOf(hueValue)); + sb.append(",").append(hueValue); } sb.append(")"); @@ -74,8 +65,8 @@ public static String getHerbUri(String iconUri, float[] hueValues) { } /** - * Get the available set of resource URNs that this AssetDataProducer can provide data for. See parent interface - * for the full description. + * Get the available set of resource URNs that this AssetDataProducer can provide data for. See parent interface for + * the full description. * * @return An empty set - meaning this producer cannot provide data for any resource URN. */ @@ -88,8 +79,8 @@ public Set getAvailableAssetUrns() { * The names of modules for which this producer can produce asset data with the given resource name for. In this * case, if the resource name starts with herb, the Herbalism module is returned. * - * @param resourceName The name of a resource. - * @return A set containing either nothing, or only the Herbalism module, which contains the resource. + * @param resourceName The name of a resource. + * @return A set containing either nothing, or only the Herbalism module, which contains the resource. */ @Override public Set getModulesProviding(Name resourceName) { @@ -100,11 +91,10 @@ public Set getModulesProviding(Name resourceName) { } /** - * See interface for full description. - * For herb icons, URN redirects will be not be allowed. + * See interface for full description. For herb icons, URN redirects will be not be allowed. * - * @param urn The URN to redirect. - * @return The original URN. + * @param urn The URN to redirect. + * @return The original URN. */ @Override public ResourceUrn redirect(ResourceUrn urn) { @@ -114,9 +104,9 @@ public ResourceUrn redirect(ResourceUrn urn) { /** * Get the asset data for this herb from this URN. Specifically, the herb icon image with the herb hues applied. * - * @param urn The URN to get AssetData from. - * @return An optional with the herb TextureData, if available. - * @throws IOException If there is an error producing the AssetData. + * @param urn The URN to get AssetData from. + * @return An optional with the herb TextureData, if available. + * @throws IOException If there is an error producing the AssetData. */ @Override public Optional getAssetData(ResourceUrn urn) throws IOException { diff --git a/src/main/java/org/terasology/herbalism/system/HerbalismAuthoritySystem.java b/src/main/java/org/terasology/herbalism/system/HerbalismAuthoritySystem.java index fbbd8d4..befb74e 100644 --- a/src/main/java/org/terasology/herbalism/system/HerbalismAuthoritySystem.java +++ b/src/main/java/org/terasology/herbalism/system/HerbalismAuthoritySystem.java @@ -1,27 +1,20 @@ -/* - * Copyright 2014 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.herbalism.system; import org.terasology.anotherWorldPlants.farm.component.FarmSoilComponent; import org.terasology.anotherWorldPlants.farm.event.SeedPlanted; -import org.terasology.entitySystem.entity.EntityRef; -import org.terasology.entitySystem.event.ReceiveEvent; -import org.terasology.entitySystem.systems.BaseComponentSystem; -import org.terasology.entitySystem.systems.RegisterMode; -import org.terasology.entitySystem.systems.RegisterSystem; +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.RegisterMode; +import org.terasology.engine.entitySystem.systems.RegisterSystem; +import org.terasology.engine.registry.In; +import org.terasology.engine.utilities.random.FastRandom; +import org.terasology.engine.world.BlockEntityRegistry; +import org.terasology.engine.world.WorldProvider; +import org.terasology.engine.world.block.Block; +import org.terasology.engine.world.block.BlockComponent; import org.terasology.genome.component.GenomeComponent; import org.terasology.genome.system.GenomeManager; import org.terasology.gf.PlantedSaplingComponent; @@ -29,12 +22,6 @@ import org.terasology.herbalism.component.PollinatingHerbComponent; import org.terasology.math.geom.Vector3i; import org.terasology.randomUpdate.RandomUpdateEvent; -import org.terasology.registry.In; -import org.terasology.utilities.random.FastRandom; -import org.terasology.world.BlockEntityRegistry; -import org.terasology.world.WorldProvider; -import org.terasology.world.block.Block; -import org.terasology.world.block.BlockComponent; /** * Authority system for Herbalism. Specifically for the planting and pollination of herb species. @@ -51,9 +38,9 @@ public class HerbalismAuthoritySystem extends BaseComponentSystem { /** * When an herb is planted, add a genome component to it. * - * @param event Details of the herb seed being planted. - * @param seedItem The herb seed item itself. - * @param genomeComponent The genome component to be added onto the planted seed entity. + * @param event Details of the herb seed being planted. + * @param seedItem The herb seed item itself. + * @param genomeComponent The genome component to be added onto the planted seed entity. */ @ReceiveEvent public void herbPlanted(SeedPlanted event, EntityRef seedItem, GenomeComponent genomeComponent) { @@ -70,14 +57,16 @@ public void herbPlanted(SeedPlanted event, EntityRef seedItem, GenomeComponent g /** * For every RandomUpdateEvent, manages how a herb will pollinate. This will work for herbs that are slated * - * @param event Details of the random update. - * @param herb The herb item in question being updated. - * @param genome Genome of the herb. - * @param pollinatingHerbComponent Details of the herb's pollination. - * @param block The herb plant's block component. This is physically where the herb is located on the world. + * @param event Details of the random update. + * @param herb The herb item in question being updated. + * @param genome Genome of the herb. + * @param pollinatingHerbComponent Details of the herb's pollination. + * @param block The herb plant's block component. This is physically where the herb is located on the + * world. */ @ReceiveEvent - public void herbPollination(RandomUpdateEvent event, EntityRef herb, GenomeComponent genome, PollinatingHerbComponent pollinatingHerbComponent, BlockComponent block) { + public void herbPollination(RandomUpdateEvent event, EntityRef herb, GenomeComponent genome, + PollinatingHerbComponent pollinatingHerbComponent, BlockComponent block) { Vector3i blockPosition = block.getPosition(); FastRandom random = new FastRandom(); @@ -98,7 +87,8 @@ public void herbPollination(RandomUpdateEvent event, EntityRef herb, GenomeCompo Vector3i plantLocation = new Vector3i(resultX, resultY, resultZ); if (worldProvider.getBlock(plantLocation).isPenetrable() && blockEntityRegistry.getEntityAt(new Vector3i(resultX, resultY - 1, resultZ)).hasComponent(FarmSoilComponent.class)) { - Block plantedBlock = genomeManager.getGenomeProperty(herb, Herbalism.PLANTED_BLOCK_PROPERTY, Block.class); + Block plantedBlock = genomeManager.getGenomeProperty(herb, + Herbalism.PLANTED_BLOCK_PROPERTY, Block.class); worldProvider.setBlock(plantLocation, plantedBlock); EntityRef plantedHerbEntity = blockEntityRegistry.getEntityAt(plantLocation); plantedHerbEntity.addComponent(new PlantedSaplingComponent()); diff --git a/src/main/java/org/terasology/herbalism/system/HerbalismClientSystem.java b/src/main/java/org/terasology/herbalism/system/HerbalismClientSystem.java index 81c4d65..2435fea 100644 --- a/src/main/java/org/terasology/herbalism/system/HerbalismClientSystem.java +++ b/src/main/java/org/terasology/herbalism/system/HerbalismClientSystem.java @@ -3,20 +3,20 @@ package org.terasology.herbalism.system; import org.terasology.anotherWorldPlants.farm.component.SeedComponent; -import org.terasology.entitySystem.entity.EntityRef; -import org.terasology.entitySystem.event.ReceiveEvent; -import org.terasology.entitySystem.systems.BaseComponentSystem; -import org.terasology.entitySystem.systems.RegisterMode; -import org.terasology.entitySystem.systems.RegisterSystem; +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.RegisterMode; +import org.terasology.engine.entitySystem.systems.RegisterSystem; +import org.terasology.engine.registry.In; +import org.terasology.engine.utilities.Assets; import org.terasology.genome.component.GenomeComponent; import org.terasology.genome.system.GenomeManager; import org.terasology.herbalism.Herbalism; import org.terasology.herbalism.component.HerbComponent; -import org.terasology.potions.component.PotionComponent; -import org.terasology.registry.In; -import org.terasology.rendering.nui.layers.ingame.inventory.GetItemTooltip; +import org.terasology.inventory.rendering.nui.layers.ingame.GetItemTooltip; import org.terasology.nui.widgets.TooltipLine; -import org.terasology.utilities.Assets; +import org.terasology.potions.component.PotionComponent; /** * Client system for Herbalism that handles tooltips. @@ -26,12 +26,23 @@ public class HerbalismClientSystem extends BaseComponentSystem { @In private GenomeManager genomeManager; + /** + * Get a custom tooltip line with a unique skin for herbs. + * + * @param herbName Name of the herb. + * @return The customized tooltip line. + */ + public static TooltipLine getHerbTooltipLine(String herbName) { + return new TooltipLine("Specie: " + herbName, Assets.getSkin("Alchemy:herbTooltip").get()); + } + /** * Modify the herb item's tooltip to add information about its genome. - * @param tooltip The item's current tooltip. This is displayed when mousing over the item. - * @param item Reference to the herb item itself. - * @param herb Herb component of the item. - * @param genome Genome component of the item. + * + * @param tooltip The item's current tooltip. This is displayed when mousing over the item. + * @param item Reference to the herb item itself. + * @param herb Herb component of the item. + * @param genome Genome component of the item. */ @ReceiveEvent public void getHerbTooltip(GetItemTooltip tooltip, EntityRef item, HerbComponent herb, GenomeComponent genome) { @@ -40,10 +51,11 @@ public void getHerbTooltip(GetItemTooltip tooltip, EntityRef item, HerbComponent /** * Modify the seed item's tooltip to add information about its genome. - * @param tooltip The item's current tooltip. This is displayed when mousing over the item. - * @param item Reference to the seed item itself. - * @param seed Seed component of the item. - * @param genome Genome component of the item. + * + * @param tooltip The item's current tooltip. This is displayed when mousing over the item. + * @param item Reference to the seed item itself. + * @param seed Seed component of the item. + * @param genome Genome component of the item. */ @ReceiveEvent public void getHerbTooltip(GetItemTooltip tooltip, EntityRef item, SeedComponent seed, GenomeComponent genome) { @@ -52,10 +64,11 @@ public void getHerbTooltip(GetItemTooltip tooltip, EntityRef item, SeedComponent /** * Modify the potion item's tooltip to add information about its genome. - * @param tooltip The item's current tooltip. This is displayed when mousing over the item. - * @param item Reference to the seed item itself. - * @param potion Potion component of the item. - * @param genome Genome component of the item. + * + * @param tooltip The item's current tooltip. This is displayed when mousing over the item. + * @param item Reference to the seed item itself. + * @param potion Potion component of the item. + * @param genome Genome component of the item. */ @ReceiveEvent public void getHerbTooltip(GetItemTooltip tooltip, EntityRef item, PotionComponent potion, GenomeComponent genome) { @@ -63,22 +76,14 @@ public void getHerbTooltip(GetItemTooltip tooltip, EntityRef item, PotionCompone } /** - * Append the species information to the given item's tooltip. This tooltip is displayed when mousing over the item. + * Append the species information to the given item's tooltip. This tooltip is displayed when mousing over the + * item. * - * @param tooltip The item's current tooltip. - * @param item Reference to the item entity. + * @param tooltip The item's current tooltip. + * @param item Reference to the item entity. */ private void appendSpecie(GetItemTooltip tooltip, EntityRef item) { String herbName = genomeManager.getGenomeProperty(item, Herbalism.NAME_PROPERTY, String.class); tooltip.getTooltipLines().add(getHerbTooltipLine(herbName)); } - - /** - * Get a custom tooltip line with a unique skin for herbs. - * @param herbName Name of the herb. - * @return The customized tooltip line. - */ - public static TooltipLine getHerbTooltipLine(String herbName) { - return new TooltipLine("Specie: " + herbName, Assets.getSkin("Alchemy:herbTooltip").get()); - } } diff --git a/src/main/java/org/terasology/herbalism/system/HerbalismCommonSystem.java b/src/main/java/org/terasology/herbalism/system/HerbalismCommonSystem.java index 509cb3e..6e13429 100644 --- a/src/main/java/org/terasology/herbalism/system/HerbalismCommonSystem.java +++ b/src/main/java/org/terasology/herbalism/system/HerbalismCommonSystem.java @@ -1,18 +1,5 @@ -/* - * Copyright 2016 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.herbalism.system; import com.google.common.base.Function; @@ -24,10 +11,17 @@ import org.terasology.alterationEffects.speed.MultiJumpAlterationEffect; import org.terasology.alterationEffects.speed.SwimSpeedAlterationEffect; import org.terasology.alterationEffects.speed.WalkSpeedAlterationEffect; -import org.terasology.context.Context; -import org.terasology.entitySystem.prefab.PrefabManager; -import org.terasology.entitySystem.systems.BaseComponentSystem; -import org.terasology.entitySystem.systems.RegisterSystem; +import org.terasology.engine.context.Context; +import org.terasology.engine.entitySystem.prefab.PrefabManager; +import org.terasology.engine.entitySystem.systems.BaseComponentSystem; +import org.terasology.engine.entitySystem.systems.RegisterSystem; +import org.terasology.engine.registry.In; +import org.terasology.engine.rendering.assets.texture.TextureRegionAsset; +import org.terasology.engine.utilities.Assets; +import org.terasology.engine.utilities.random.FastRandom; +import org.terasology.engine.world.WorldProvider; +import org.terasology.engine.world.block.Block; +import org.terasology.engine.world.block.BlockManager; import org.terasology.genome.GenomeDefinition; import org.terasology.genome.GenomeRegistry; import org.terasology.genome.breed.BreedingAlgorithm; @@ -44,13 +38,6 @@ import org.terasology.potions.effect.AlterationToHerbEffectWrapper; import org.terasology.potions.effect.DoNothingEffect; import org.terasology.potions.effect.HealEffect; -import org.terasology.registry.In; -import org.terasology.rendering.assets.texture.TextureRegionAsset; -import org.terasology.utilities.Assets; -import org.terasology.utilities.random.FastRandom; -import org.terasology.world.WorldProvider; -import org.terasology.world.block.Block; -import org.terasology.world.block.BlockManager; /** * Common system for Herbalism that handles the registration of herb effects and genome properties. @@ -73,21 +60,30 @@ public class HerbalismCommonSystem extends BaseComponentSystem { private Context context; /** - * Before beginning execution of this component system, register the herb effects and the genome definition for the herbs. + * Before beginning execution of this component system, register the herb effects and the genome definition for the + * herbs. */ @Override public void preBegin() { // Registering all of the default herb effects into the registry. herbEffectRegistry.registerHerbEffect(1f, new DoNothingEffect()); herbEffectRegistry.registerHerbEffect(1f, new HealEffect()); - herbEffectRegistry.registerHerbEffect(1f, new AlterationToHerbEffectWrapper(new WalkSpeedAlterationEffect(context), 1f, 1f)); - herbEffectRegistry.registerHerbEffect(1f, new AlterationToHerbEffectWrapper(new SwimSpeedAlterationEffect(context), 1f, 1f)); - herbEffectRegistry.registerHerbEffect(1f, new AlterationToHerbEffectWrapper(new RegenerationAlterationEffect(context), 1f, 100f)); - herbEffectRegistry.registerHerbEffect(1f, new AlterationToHerbEffectWrapper(new WaterBreathingAlterationEffect(context), 1f, 1f)); - herbEffectRegistry.registerHerbEffect(1f, new AlterationToHerbEffectWrapper(new JumpSpeedAlterationEffect(context), 1f, 1f)); - herbEffectRegistry.registerHerbEffect(1f, new AlterationToHerbEffectWrapper(new MultiJumpAlterationEffect(context), 1f, 1f)); - herbEffectRegistry.registerHerbEffect(1f, new AlterationToHerbEffectWrapper(new DamageOverTimeAlterationEffect(context), 1f, 1f)); - herbEffectRegistry.registerHerbEffect(1f, new AlterationToHerbEffectWrapper(new CureAllDamageOverTimeAlterationEffect(context), 1f, 1f)); + herbEffectRegistry.registerHerbEffect(1f, + new AlterationToHerbEffectWrapper(new WalkSpeedAlterationEffect(context), 1f, 1f)); + herbEffectRegistry.registerHerbEffect(1f, + new AlterationToHerbEffectWrapper(new SwimSpeedAlterationEffect(context), 1f, 1f)); + herbEffectRegistry.registerHerbEffect(1f, + new AlterationToHerbEffectWrapper(new RegenerationAlterationEffect(context), 1f, 100f)); + herbEffectRegistry.registerHerbEffect(1f, + new AlterationToHerbEffectWrapper(new WaterBreathingAlterationEffect(context), 1f, 1f)); + herbEffectRegistry.registerHerbEffect(1f, + new AlterationToHerbEffectWrapper(new JumpSpeedAlterationEffect(context), 1f, 1f)); + herbEffectRegistry.registerHerbEffect(1f, + new AlterationToHerbEffectWrapper(new MultiJumpAlterationEffect(context), 1f, 1f)); + herbEffectRegistry.registerHerbEffect(1f, + new AlterationToHerbEffectWrapper(new DamageOverTimeAlterationEffect(context), 1f, 1f)); + herbEffectRegistry.registerHerbEffect(1f, + new AlterationToHerbEffectWrapper(new CureAllDamageOverTimeAlterationEffect(context), 1f, 1f)); // Defining a herb name provider. final HerbNameProvider herbNameProvider = new HerbNameProvider(worldProvider.getSeed().hashCode()); @@ -141,13 +137,15 @@ public String apply(String input) { } }); // This is for defining the icon of the herb, and how it can vary based on the herb hues. - herbGenomeMap.addProperty(Herbalism.ICON_PROPERTY, new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, TextureRegionAsset.class, + herbGenomeMap.addProperty(Herbalism.ICON_PROPERTY, new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + TextureRegionAsset.class, new Function() { @Override public TextureRegionAsset apply(String input) { String type = input.substring(0, 1); String genes = input.substring(1, 10); - HerbHueComponent herbHue = prefabManager.getPrefab("Alchemy:HerbHue" + type).getComponent(HerbHueComponent.class); + HerbHueComponent herbHue = + prefabManager.getPrefab("Alchemy:HerbHue" + type).getComponent(HerbHueComponent.class); FastRandom rnd = new FastRandom(genes.hashCode() + 3497987); float[] hueValues = new float[herbHue.hueRanges.size()]; @@ -158,7 +156,8 @@ public TextureRegionAsset apply(String input) { hueValues[i] = rnd.nextFloat(min, max); } - return Assets.getTextureRegion(HerbIconAssetResolver.getHerbUri("Alchemy:Herb" + type, hueValues)).get(); + return Assets.getTextureRegion(HerbIconAssetResolver.getHerbUri("Alchemy:Herb" + type, + hueValues)).get(); } }); herbGenomeMap.addProperty(Herbalism.PLANTED_BLOCK_PROPERTY, new int[]{0}, Block.class, diff --git a/src/main/java/org/terasology/herbalism/system/HerbalismStationIngredientPredicate.java b/src/main/java/org/terasology/herbalism/system/HerbalismStationIngredientPredicate.java index d1baa3a..bfdf36f 100644 --- a/src/main/java/org/terasology/herbalism/system/HerbalismStationIngredientPredicate.java +++ b/src/main/java/org/terasology/herbalism/system/HerbalismStationIngredientPredicate.java @@ -1,37 +1,26 @@ -/* - * Copyright 2016 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.herbalism.system; import com.google.common.base.Predicate; +import org.terasology.engine.entitySystem.entity.EntityRef; +import org.terasology.herbalism.component.HerbComponent; import org.terasology.potions.component.EmptyPotionComponent; import org.terasology.workstationCrafting.component.CraftingStationIngredientComponent; -import org.terasology.entitySystem.entity.EntityRef; -import org.terasology.herbalism.component.HerbComponent; /** * This predicate class is used to filter out items that are not compatible with HerbalismStations. */ public class HerbalismStationIngredientPredicate implements Predicate { - /** Item type to check for. */ - private String itemType; + /** + * Item type to check for. + */ + private final String itemType; /** * Define what item type this filter should look for. * - * @param itemType Item type name being filtered. + * @param itemType Item type name being filtered. */ public HerbalismStationIngredientPredicate(String itemType) { this.itemType = itemType; @@ -40,8 +29,8 @@ public HerbalismStationIngredientPredicate(String itemType) { /** * Apply an entity to this filter to see if it's compatible with HerbalismStations and it has the same item type. * - * @param input Reference to the entity being checked. - * @return True if the entity fulfills the above conditions. False if not. + * @param input Reference to the entity being checked. + * @return True if the entity fulfills the above conditions. False if not. */ @Override public boolean apply(EntityRef input) { @@ -49,7 +38,8 @@ public boolean apply(EntityRef input) { EmptyPotionComponent epComponent = input.getComponent(EmptyPotionComponent.class); CraftingStationIngredientComponent component = input.getComponent(CraftingStationIngredientComponent.class); - // If this contains a valid instance of (HerbComponent or EmptyPotionComponent, CraftingStationIngredientComponent, + // If this contains a valid instance of (HerbComponent or EmptyPotionComponent, + // CraftingStationIngredientComponent, // and the input's type matches the itemType of this predicate, return true. return (hComponent != null || epComponent != null) && component != null && component.type.equalsIgnoreCase(itemType); } diff --git a/src/main/java/org/terasology/herbalism/ui/HerbalismCraftingStationRecipe.java b/src/main/java/org/terasology/herbalism/ui/HerbalismCraftingStationRecipe.java index 34d60d0..61c0642 100644 --- a/src/main/java/org/terasology/herbalism/ui/HerbalismCraftingStationRecipe.java +++ b/src/main/java/org/terasology/herbalism/ui/HerbalismCraftingStationRecipe.java @@ -4,8 +4,17 @@ import com.google.common.base.Predicate; import org.terasology.durability.components.DurabilityComponent; -import org.terasology.entitySystem.entity.EntityRef; -import org.terasology.entitySystem.prefab.Prefab; +import org.terasology.engine.entitySystem.entity.EntityRef; +import org.terasology.engine.entitySystem.prefab.Prefab; +import org.terasology.engine.registry.CoreRegistry; +import org.terasology.engine.utilities.Assets; +import org.terasology.genome.component.GenomeComponent; +import org.terasology.genome.system.GenomeManager; +import org.terasology.herbalism.Herbalism; +import org.terasology.herbalism.system.HerbalismClientSystem; +import org.terasology.herbalism.system.HerbalismStationIngredientPredicate; +import org.terasology.inventory.rendering.nui.layers.ingame.ItemIcon; +import org.terasology.nui.widgets.TooltipLine; import org.terasology.potions.component.EmptyPotionComponent; import org.terasology.potions.component.PotionComponent; import org.terasology.workstationCrafting.component.CraftingStationRecipeComponent; @@ -15,52 +24,47 @@ import org.terasology.workstationCrafting.system.recipe.behaviour.InventorySlotTypeResolver; import org.terasology.workstationCrafting.system.recipe.render.result.ItemRecipeResultFactory; import org.terasology.workstationCrafting.system.recipe.workstation.AbstractWorkstationRecipe; -import org.terasology.genome.component.GenomeComponent; -import org.terasology.genome.system.GenomeManager; -import org.terasology.herbalism.Herbalism; -import org.terasology.herbalism.system.HerbalismClientSystem; -import org.terasology.herbalism.system.HerbalismStationIngredientPredicate; -import org.terasology.registry.CoreRegistry; -import org.terasology.rendering.nui.layers.ingame.inventory.ItemIcon; -import org.terasology.nui.widgets.TooltipLine; -import org.terasology.utilities.Assets; import java.util.Arrays; import java.util.List; /** - * A custom workstation recipe format for herbalism related recipes. Note that this is only intended to be used with the HerbalismCraftingStations. - * Potions specifically. + * A custom workstation recipe format for herbalism related recipes. Note that this is only intended to be used with the + * HerbalismCraftingStations. Potions specifically. */ public class HerbalismCraftingStationRecipe extends AbstractWorkstationRecipe { /** - * Create the Herbalism Crafting Station's recipe based on the assigned CraftingStationRecipeComponent (i.e. the recipe parameters). + * Create the Herbalism Crafting Station's recipe based on the assigned CraftingStationRecipeComponent (i.e. the + * recipe parameters). * - * @param recipe The titular recipe applicable to this HerbalismStation. + * @param recipe The titular recipe applicable to this HerbalismStation. */ public HerbalismCraftingStationRecipe(CraftingStationRecipeComponent recipe) { String oldPotionContainerName = ""; - // Search through the recipe components to find the first empty potion bottle. If it's found, break out of the loop. + // Search through the recipe components to find the first empty potion bottle. If it's found, break out of + // the loop. // Otherwise, the oldPotionContainerName will be an empty string. for (String component : recipe.recipeComponents) { oldPotionContainerName = component.split("\\*")[1]; Prefab potionTest = Assets.getPrefab(oldPotionContainerName).get(); if (potionTest != null && !potionTest.hasComponent(EmptyPotionComponent.class)) { break; - } - else { + } else { oldPotionContainerName = ""; } } // Add the fluid behavior and required heat and duration based on the recipe's parameters. - addFluidBehaviour(new ConsumeFluidBehaviour("CoreAssets:Water", 0.2f, new InventorySlotTypeResolver("FLUID_INPUT"))); + addFluidBehaviour(new ConsumeFluidBehaviour("CoreAssets:Water", 0.2f, new InventorySlotTypeResolver( + "FLUID_INPUT"))); setRequiredHeat(recipe.requiredTemperature); setProcessingDuration(recipe.processingDuration); // Create and set the custom result factory. - PotionRecipeResultFactory potionRecipeResultFactory = new PotionRecipeResultFactory(Assets.getPrefab(recipe.recipeId).get(), recipe.itemResult.split("\\*")[1], 1, oldPotionContainerName); + PotionRecipeResultFactory potionRecipeResultFactory = + new PotionRecipeResultFactory(Assets.getPrefab(recipe.recipeId).get(), + recipe.itemResult.split("\\*")[1], 1, oldPotionContainerName); setResultFactory(potionRecipeResultFactory); // Add each of the ingredient (consumption) behaviors by parsing through the recipe components. @@ -69,7 +73,8 @@ public HerbalismCraftingStationRecipe(CraftingStationRecipeComponent recipe) { int count = Integer.parseInt(split[0]); String type = split[1]; - // If the first item in this recipe is an empty potion container, add it as a ConsumePotionContainerBehaviour. + // If the first item in this recipe is an empty potion container, add it as a + // ConsumePotionContainerBehaviour. if (!oldPotionContainerName.equals("")) { addIngredientBehaviour(new ConsumePotionContainerBehaviour(new HerbalismStationIngredientPredicate(type), count, new InventorySlotTypeResolver("INPUT"), potionRecipeResultFactory)); } @@ -84,27 +89,30 @@ public HerbalismCraftingStationRecipe(CraftingStationRecipeComponent recipe) { * This internal class is used for creating and defining the resultant potion. */ private final class PotionRecipeResultFactory extends ItemRecipeResultFactory { - private String toolTip; /** Potion's tooltip. This id displayed by default when mouse hovered over. */ - private String oldPotionContainerName = ""; /** Name of the potion's container to be used. */ - private EntityRef potionBottleRef; /** Reference to the current potion bottle. */ - - private DurabilityComponent lastDurability; /** Reference to the last potion bottle's durability. */ - private String lastPotionBottleName = ""; /** Name of the last potion bottle used. */ + private final String toolTip; + /** + * Potion's tooltip. This id displayed by default when mouse hovered over. + */ + private String oldPotionContainerName = ""; + /** + * Name of the potion's container to be used. + */ + private EntityRef potionBottleRef; + /** + * Reference to the current potion bottle. + */ + private DurabilityComponent lastDurability; /** - * Set the reference to the current potion bottle. - * - * #param ref Reference to the potion bottle entity. + * Reference to the last potion bottle's durability. */ - public void setPotionBottleRef(EntityRef ref) { - potionBottleRef = ref; - } + private String lastPotionBottleName = ""; /** Name of the last potion bottle used. */ /** * Constructor for when the potion doesn't use bottles and the toolTip can be the default one. * - * @param prefab Prefab of the potion to be created. - * @param count Number of the potions to be created. + * @param prefab Prefab of the potion to be created. + * @param count Number of the potions to be created. */ private PotionRecipeResultFactory(Prefab prefab, int count) { super(prefab, count); @@ -114,9 +122,9 @@ private PotionRecipeResultFactory(Prefab prefab, int count) { /** * Constructor for when the potion doesn't use bottles but the toolTip needs to be replaced. * - * @param prefab Prefab of the potion to be created. - * @param toolTip Potion's tooltip to be displayed. - * @param count Number of the potions to be created. + * @param prefab Prefab of the potion to be created. + * @param toolTip Potion's tooltip to be displayed. + * @param count Number of the potions to be created. */ private PotionRecipeResultFactory(Prefab prefab, String toolTip, int count) { super(prefab, count); @@ -126,10 +134,10 @@ private PotionRecipeResultFactory(Prefab prefab, String toolTip, int count) { /** * Constructor for when the potion uses bottles. * - * @param prefab Prefab of the potion to be created. - * @param toolTip Potion's tooltip to be displayed. - * @param count Number of the potions to be created. - * @param oldContainerName Name of the empty potion container. + * @param prefab Prefab of the potion to be created. + * @param toolTip Potion's tooltip to be displayed. + * @param count Number of the potions to be created. + * @param oldContainerName Name of the empty potion container. */ private PotionRecipeResultFactory(Prefab prefab, String toolTip, int count, String oldContainerName) { super(prefab, count); @@ -137,11 +145,20 @@ private PotionRecipeResultFactory(Prefab prefab, String toolTip, int count, Stri oldPotionContainerName = oldContainerName; } + /** + * Set the reference to the current potion bottle. + *

+ * #param ref Reference to the potion bottle entity. + */ + public void setPotionBottleRef(EntityRef ref) { + potionBottleRef = ref; + } + /** * Setup the display of the resultant item. This includes the icon and description text. * - * @param parameters List of parameters of this particular recipe component. - * @param itemIcon Graphical icon of this item. + * @param parameters List of parameters of this particular recipe component. + * @param itemIcon Graphical icon of this item. */ @Override public void setupDisplay(List parameters, ItemIcon itemIcon) { @@ -161,9 +178,9 @@ public void setupDisplay(List parameters, ItemIcon itemIcon) { /** * Create the resultant potion(s)(item) using the given recipe components. * - * @param parameters All of the recipe components necessary for brewing this potion. - * @param multiplier The number of potions that are created by this recipe. - * @return A reference to the resultant potion item. + * @param parameters All of the recipe components necessary for brewing this potion. + * @param multiplier The number of potions that are created by this recipe. + * @return A reference to the resultant potion item. */ @Override public EntityRef createResult(List parameters, int multiplier) { @@ -193,7 +210,8 @@ public EntityRef createResult(List parameters, int multiplier) { if (!oldPotionContainerName.equals("")) { DurabilityComponent potionBottleDurabilityComponent = null; - // If the current potion bottle ref exists, then copy the durability and name over to the appropriate instance + // If the current potion bottle ref exists, then copy the durability and name over to the + // appropriate instance // variables. if (potionBottleRef != null && potionBottleRef.exists()) { potionBottleDurabilityComponent = potionBottleRef.getComponent(DurabilityComponent.class); @@ -201,7 +219,8 @@ public EntityRef createResult(List parameters, int multiplier) { lastPotionBottleName = potionBottleRef.getParentPrefab().getUrn().toString(); potionComponent.bottlePrefab = lastPotionBottleName; } - // Otherwise, use the last durability value as the potionBottleDurabilityComponent - i.e., the one to be + // Otherwise, use the last durability value as the potionBottleDurabilityComponent - i.e., the + // one to be // used for this potion. This is necessary as when there's only one bottle in the workstation input, // consuming it will cause the potionBottleRef to become non-existent. Hence, why I'm using the last // known values instead. @@ -213,12 +232,12 @@ public EntityRef createResult(List parameters, int multiplier) { // It's either taken from the entity ref, or from the recipe parameters list if the former is empty. if (!lastPotionBottleName.equals("")) { potionComponent.bottlePrefab = lastPotionBottleName; - } - else { + } else { potionComponent.bottlePrefab = oldPotionContainerName; } - // Create a new Durability component, and copy over the values from the old bottle's Durability component, + // Create a new Durability component, and copy over the values from the old bottle's Durability + // component, // as long as the last durability exists. Lastly, add this new component to the resultant potion. if (potionBottleDurabilityComponent != null) { DurabilityComponent durabilityComponent = new DurabilityComponent(); @@ -237,29 +256,34 @@ public EntityRef createResult(List parameters, int multiplier) { * This internal class is used to define the custom consumption behavior of potion bottles during crafting. */ private final class ConsumePotionContainerBehaviour extends ConsumeItemCraftBehaviour { - /** Reference to the potion crafting result factory. */ - private PotionRecipeResultFactory potionRecipeResultFactory; + /** + * Reference to the potion crafting result factory. + */ + private final PotionRecipeResultFactory potionRecipeResultFactory; /** * Constructor which creates the baseline for this item consumption behavior. * - * @param matcher Predicate matcher for filtering out items that are not empty potion containers. - * @param count Number of potion containers to consume while crafting. - * @param resolver To manage the inventory changes during this behavior. - * @param potionRecipeResultFactory Reference to the associated potion result factory. + * @param matcher Predicate matcher for filtering out items that are not empty potion containers. + * @param count Number of potion containers to consume while crafting. + * @param resolver To manage the inventory changes during this behavior. + * @param potionRecipeResultFactory Reference to the associated potion result factory. */ - private ConsumePotionContainerBehaviour(Predicate matcher, int count, InventorySlotResolver resolver, PotionRecipeResultFactory potionRecipeResultFactory) { + private ConsumePotionContainerBehaviour(Predicate matcher, int count, + InventorySlotResolver resolver, + PotionRecipeResultFactory potionRecipeResultFactory) { super(matcher, count, resolver); this.potionRecipeResultFactory = potionRecipeResultFactory; } /** - * Get the ingredient parameters and where they are located in the workstation's inventory, and return them as a String. - * If the current item being checked is an empty potion bottle, give the result factory class that information. + * Get the ingredient parameters and where they are located in the workstation's inventory, and return them as a + * String. If the current item being checked is an empty potion bottle, give the result factory class that + * information. * - * @param slots List of workstation inventory slots that the item is present in. - * @param item Reference to the recipe component item in question. - * @return The ingredient parameters of this item in a combined String. + * @param slots List of workstation inventory slots that the item is present in. + * @param item Reference to the recipe component item in question. + * @return The ingredient parameters of this item in a combined String. */ @Override protected String getParameter(List slots, EntityRef item) { @@ -277,34 +301,36 @@ private final class ConsumeHerbIngredientBehaviour extends ConsumeItemCraftBehav /** * Constructor which creates the baseline for this item consumption behavior. * - * @param matcher Predicate matcher for filtering out items that are not herbs. - * @param count Number of herbs of this type to consume while crafting. - * @param resolver To manage the inventory changes during this behavior. + * @param matcher Predicate matcher for filtering out items that are not herbs. + * @param count Number of herbs of this type to consume while crafting. + * @param resolver To manage the inventory changes during this behavior. */ - private ConsumeHerbIngredientBehaviour(Predicate matcher, int count, InventorySlotResolver resolver) { + private ConsumeHerbIngredientBehaviour(Predicate matcher, int count, + InventorySlotResolver resolver) { super(matcher, count, resolver); } /** - * Get the ingredient parameters and where they are located in the workstation's inventory, and return them as a String. - * If possible, add the genome parameters of the herbs to the parameter String. + * Get the ingredient parameters and where they are located in the workstation's inventory, and return them as a + * String. If possible, add the genome parameters of the herbs to the parameter String. * - * @param slots List of workstation inventory slots that the item is present in. - * @param item Reference to the herb item in question. - * @return The ingredient parameters of this item plus the genome information in a combined String. + * @param slots List of workstation inventory slots that the item is present in. + * @param item Reference to the herb item in question. + * @return The ingredient parameters of this item plus the genome information in a combined String. */ @Override protected String getParameter(List slots, EntityRef item) { final GenomeComponent genome = item.getComponent(GenomeComponent.class); - final String herbName = CoreRegistry.get(GenomeManager.class).getGenomeProperty(item, Herbalism.NAME_PROPERTY, String.class); + final String herbName = CoreRegistry.get(GenomeManager.class).getGenomeProperty(item, + Herbalism.NAME_PROPERTY, String.class); return super.getParameter(slots, item) + "|" + genome.genomeId + "|" + genome.genes + "|" + herbName; } /** * Return an integer list of workstation inventory slots this herb is present in. * - * @param parameter Name of the item being searched for. - * @return What inventory slots this item (likely a herb) is present in. + * @param parameter Name of the item being searched for. + * @return What inventory slots this item (likely a herb) is present in. */ @Override protected List getSlots(String parameter) { diff --git a/src/main/java/org/terasology/herbalism/ui/HerbalismStationWindow.java b/src/main/java/org/terasology/herbalism/ui/HerbalismStationWindow.java index adecc03..efc4cea 100644 --- a/src/main/java/org/terasology/herbalism/ui/HerbalismStationWindow.java +++ b/src/main/java/org/terasology/herbalism/ui/HerbalismStationWindow.java @@ -4,27 +4,27 @@ package org.terasology.herbalism.ui; import org.terasology.alchemy.Alchemy; -import org.terasology.workstationCrafting.ui.workstation.StationAvailableRecipesWidget; -import org.terasology.engine.Time; -import org.terasology.entitySystem.entity.EntityRef; +import org.terasology.engine.core.Time; +import org.terasology.engine.entitySystem.entity.EntityRef; +import org.terasology.engine.logic.players.LocalPlayer; +import org.terasology.engine.registry.CoreRegistry; +import org.terasology.engine.rendering.nui.BaseInteractionScreen; import org.terasology.fluid.component.FluidComponent; import org.terasology.fluid.component.FluidInventoryComponent; import org.terasology.fluid.system.FluidRegistry; import org.terasology.fluid.ui.FluidContainerWidget; import org.terasology.heat.component.HeatProducerComponent; import org.terasology.heat.ui.ThermometerWidget; -import org.terasology.logic.players.LocalPlayer; +import org.terasology.inventory.rendering.nui.layers.ingame.InventoryGrid; import org.terasology.math.TeraMath; -import org.terasology.processing.ui.VerticalTextureProgressWidget; -import org.terasology.processing.ui.WorkstationScreenUtils; -import org.terasology.registry.CoreRegistry; -import org.terasology.rendering.nui.BaseInteractionScreen; import org.terasology.nui.databinding.Binding; import org.terasology.nui.databinding.ReadOnlyBinding; -import org.terasology.rendering.nui.layers.ingame.inventory.InventoryGrid; import org.terasology.nui.widgets.UILoadBar; +import org.terasology.processing.ui.VerticalTextureProgressWidget; +import org.terasology.processing.ui.WorkstationScreenUtils; import org.terasology.workstation.component.WorkstationInventoryComponent; import org.terasology.workstation.component.WorkstationProcessingComponent; +import org.terasology.workstationCrafting.ui.workstation.StationAvailableRecipesWidget; import java.util.List; @@ -84,7 +84,7 @@ public void initialise() { /** * Upon opening the HerbalismStation window, setup the UI widgets. * - * @param station EntityRef of the workstation in question. + * @param station EntityRef of the workstation in question. */ @Override protected void initializeWithInteractionTarget(final EntityRef station) { @@ -92,7 +92,8 @@ protected void initializeWithInteractionTarget(final EntityRef station) { WorkstationInventoryComponent workstationInventory = station.getComponent(WorkstationInventoryComponent.class); // Get the slot assignments of this inventory. - WorkstationInventoryComponent.SlotAssignment fluidInputAssignments = workstationInventory.slotAssignments.get("FLUID_INPUT"); + WorkstationInventoryComponent.SlotAssignment fluidInputAssignments = + workstationInventory.slotAssignments.get("FLUID_INPUT"); // Setup the inventory grids for the following widgets. WorkstationScreenUtils.setupInventoryGrid(station, ingredientsInventory, "INPUT"); @@ -175,7 +176,8 @@ public String get() { @Override public String get() { FluidInventoryComponent fluidInventory = station.getComponent(FluidInventoryComponent.class); - final FluidComponent fluid = fluidInventory.fluidSlots.get(waterSlot).getComponent(FluidComponent.class); + final FluidComponent fluid = + fluidInventory.fluidSlots.get(waterSlot).getComponent(FluidComponent.class); if (fluid == null) { return "0ml"; } else { @@ -199,7 +201,8 @@ public Float get() { } long gameTime = CoreRegistry.get(Time.class).getGameTimeInMs(); - HeatProducerComponent.FuelSourceConsume lastConsumed = consumedFuel.get(consumedFuel.size() - 1); + HeatProducerComponent.FuelSourceConsume lastConsumed = + consumedFuel.get(consumedFuel.size() - 1); if (gameTime > lastConsumed.startTime + lastConsumed.burnLength) { return 0f; } @@ -218,11 +221,13 @@ public void set(Float value) { // Return a progress bar indicating the current progress of crafting (if currently running). @Override public Boolean get() { - WorkstationProcessingComponent processing = station.getComponent(WorkstationProcessingComponent.class); + WorkstationProcessingComponent processing = + station.getComponent(WorkstationProcessingComponent.class); if (processing == null) { return false; } - WorkstationProcessingComponent.ProcessDef herbalismProcess = processing.processes.get(Alchemy.HERBALISM_PROCESS_TYPE); + WorkstationProcessingComponent.ProcessDef herbalismProcess = + processing.processes.get(Alchemy.HERBALISM_PROCESS_TYPE); return herbalismProcess != null; } @@ -235,11 +240,13 @@ public void set(Boolean value) { new Binding() { @Override public Float get() { - WorkstationProcessingComponent processing = station.getComponent(WorkstationProcessingComponent.class); + WorkstationProcessingComponent processing = + station.getComponent(WorkstationProcessingComponent.class); if (processing == null) { return 1f; } - WorkstationProcessingComponent.ProcessDef herbalismProcess = processing.processes.get(Alchemy.HERBALISM_PROCESS_TYPE); + WorkstationProcessingComponent.ProcessDef herbalismProcess = + processing.processes.get(Alchemy.HERBALISM_PROCESS_TYPE); if (herbalismProcess == null) { return 1f; } diff --git a/src/main/java/org/terasology/herbalism/ui/HerbalismStationWindowSystem.java b/src/main/java/org/terasology/herbalism/ui/HerbalismStationWindowSystem.java index ca220f7..c876538 100644 --- a/src/main/java/org/terasology/herbalism/ui/HerbalismStationWindowSystem.java +++ b/src/main/java/org/terasology/herbalism/ui/HerbalismStationWindowSystem.java @@ -1,31 +1,18 @@ -/* - * Copyright 2016 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.herbalism.ui; -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.characters.interactions.InteractionScreenComponent; -import org.terasology.logic.inventory.events.BeforeItemPutInInventory; -import org.terasology.logic.inventory.events.BeforeItemRemovedFromInventory; -import org.terasology.logic.inventory.events.InventorySlotStackSizeChangedEvent; -import org.terasology.registry.In; -import org.terasology.rendering.nui.NUIManager; +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.characters.interactions.InteractionScreenComponent; +import org.terasology.engine.registry.In; +import org.terasology.engine.rendering.nui.NUIManager; +import org.terasology.inventory.logic.events.BeforeItemPutInInventory; +import org.terasology.inventory.logic.events.BeforeItemRemovedFromInventory; +import org.terasology.inventory.logic.events.InventorySlotStackSizeChangedEvent; import org.terasology.workstation.component.WorkstationInventoryComponent; import org.terasology.workstationCrafting.event.CraftingStationUpgraded; @@ -47,9 +34,9 @@ public void initialise() { /** * Just before an item is placed into one of the herbalism station's inventory slots, update the UI screen. * - * @param event Details of this event. - * @param entity Entity reference to the workstation. May not be a HerbalismStation though. - * @param inventory Inventory of the workstation. + * @param event Details of this event. + * @param entity Entity reference to the workstation. May not be a HerbalismStation though. + * @param inventory Inventory of the workstation. */ @ReceiveEvent public void itemPutIntoInventorySlot(BeforeItemPutInInventory event, EntityRef entity, @@ -64,11 +51,12 @@ public void itemPutIntoInventorySlot(BeforeItemPutInInventory event, EntityRef e } /** - * When one of the item stack sizes present in the herbalism station's inventory slots changes, update the UI screen. + * When one of the item stack sizes present in the herbalism station's inventory slots changes, update the UI + * screen. * - * @param event Details of this event. - * @param entity Entity reference to the workstation. May not be a HerbalismStation though. - * @param inventory Inventory of the workstation. + * @param event Details of this event. + * @param entity Entity reference to the workstation. May not be a HerbalismStation though. + * @param inventory Inventory of the workstation. */ @ReceiveEvent public void itemPutIntoInventorySlot(InventorySlotStackSizeChangedEvent event, EntityRef entity, @@ -85,9 +73,9 @@ public void itemPutIntoInventorySlot(InventorySlotStackSizeChangedEvent event, E /** * Just before an item is removed from one of the herbalism station's inventory slots, update the UI screen. * - * @param event Details of this event. - * @param entity Entity reference to the workstation. May not be a HerbalismStation though. - * @param inventory Inventory of the workstation. + * @param event Details of this event. + * @param entity Entity reference to the workstation. May not be a HerbalismStation though. + * @param inventory Inventory of the workstation. */ @ReceiveEvent public void itemRemovedFromInventorySlot(BeforeItemRemovedFromInventory event, EntityRef entity, @@ -104,13 +92,13 @@ public void itemRemovedFromInventorySlot(BeforeItemRemovedFromInventory event, E /** * When the herbalism station has been upgraded, update the UI screen. * - * @param event Details of this event. - * @param entity Entity reference to the workstation. May not be a HerbalismStation though. - * @param inventory Inventory of the workstation. + * @param event Details of this event. + * @param entity Entity reference to the workstation. May not be a HerbalismStation though. + * @param inventory Inventory of the workstation. */ @ReceiveEvent public void onCraftingStationUpgraded(CraftingStationUpgraded event, EntityRef entity, - WorkstationInventoryComponent inventory) { + WorkstationInventoryComponent inventory) { if (entity.getComponent(InteractionScreenComponent.class).screen.equalsIgnoreCase("Alchemy:HerbalismStation")) { HerbalismStationWindow screen = (HerbalismStationWindow) nuiManager.getScreen("Alchemy:HerbalismStation"); From 6d05f7dbc1144cd099057ea06e932584259baf6f Mon Sep 17 00:00:00 2001 From: DarkWeird Date: Wed, 16 Sep 2020 12:55:58 +0300 Subject: [PATCH 3/3] feature(reintegrate-gestaltv7): fix package names for modules --- .../terasology/herbalism/generator/HerbAGrowthDefinition.java | 2 +- .../herbalism/generator/HerbDesertSpawnDefinition.java | 4 ++-- .../herbalism/generator/HerbForestSpawnDefinition.java | 4 ++-- .../herbalism/generator/HerbPlainsSpawnDefinition.java | 4 ++-- .../herbalism/generator/HerbTundraSpawnDefinition.java | 4 ++-- .../terasology/herbalism/system/HerbalismAuthoritySystem.java | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/terasology/herbalism/generator/HerbAGrowthDefinition.java b/src/main/java/org/terasology/herbalism/generator/HerbAGrowthDefinition.java index 8898dea..0c1a8be 100644 --- a/src/main/java/org/terasology/herbalism/generator/HerbAGrowthDefinition.java +++ b/src/main/java/org/terasology/herbalism/generator/HerbAGrowthDefinition.java @@ -13,7 +13,7 @@ import org.terasology.engine.world.block.BlockUri; import org.terasology.engine.world.generator.plugin.RegisterPlugin; import org.terasology.genome.component.GenomeComponent; -import org.terasology.gf.grass.ReplaceBlockGrowthDefinition; +import org.terasology.growingflora.grass.ReplaceBlockGrowthDefinition; import org.terasology.math.geom.Vector3i; import java.util.Arrays; diff --git a/src/main/java/org/terasology/herbalism/generator/HerbDesertSpawnDefinition.java b/src/main/java/org/terasology/herbalism/generator/HerbDesertSpawnDefinition.java index 8f973d7..f0bc342 100644 --- a/src/main/java/org/terasology/herbalism/generator/HerbDesertSpawnDefinition.java +++ b/src/main/java/org/terasology/herbalism/generator/HerbDesertSpawnDefinition.java @@ -6,8 +6,8 @@ import org.terasology.anotherWorld.decorator.BlockCollectionPredicate; import org.terasology.engine.world.block.BlockUri; import org.terasology.engine.world.generator.plugin.RegisterPlugin; -import org.terasology.gf.PlantType; -import org.terasology.gf.generator.StaticBlockFloraSpawnDefinition; +import org.terasology.growingflora.PlantType; +import org.terasology.growingflora.generator.StaticBlockFloraSpawnDefinition; import java.util.Arrays; diff --git a/src/main/java/org/terasology/herbalism/generator/HerbForestSpawnDefinition.java b/src/main/java/org/terasology/herbalism/generator/HerbForestSpawnDefinition.java index 609fbef..0cf5031 100644 --- a/src/main/java/org/terasology/herbalism/generator/HerbForestSpawnDefinition.java +++ b/src/main/java/org/terasology/herbalism/generator/HerbForestSpawnDefinition.java @@ -6,8 +6,8 @@ import org.terasology.anotherWorld.decorator.BlockCollectionPredicate; import org.terasology.engine.world.block.BlockUri; import org.terasology.engine.world.generator.plugin.RegisterPlugin; -import org.terasology.gf.PlantType; -import org.terasology.gf.generator.StaticBlockFloraSpawnDefinition; +import org.terasology.growingflora.PlantType; +import org.terasology.growingflora.generator.StaticBlockFloraSpawnDefinition; import java.util.Arrays; diff --git a/src/main/java/org/terasology/herbalism/generator/HerbPlainsSpawnDefinition.java b/src/main/java/org/terasology/herbalism/generator/HerbPlainsSpawnDefinition.java index d548632..ba85f0d 100644 --- a/src/main/java/org/terasology/herbalism/generator/HerbPlainsSpawnDefinition.java +++ b/src/main/java/org/terasology/herbalism/generator/HerbPlainsSpawnDefinition.java @@ -6,8 +6,8 @@ import org.terasology.anotherWorld.decorator.BlockCollectionPredicate; import org.terasology.engine.world.block.BlockUri; import org.terasology.engine.world.generator.plugin.RegisterPlugin; -import org.terasology.gf.PlantType; -import org.terasology.gf.generator.StaticBlockFloraSpawnDefinition; +import org.terasology.growingflora.PlantType; +import org.terasology.growingflora.generator.StaticBlockFloraSpawnDefinition; import java.util.Arrays; diff --git a/src/main/java/org/terasology/herbalism/generator/HerbTundraSpawnDefinition.java b/src/main/java/org/terasology/herbalism/generator/HerbTundraSpawnDefinition.java index 80b2334..b2a4464 100644 --- a/src/main/java/org/terasology/herbalism/generator/HerbTundraSpawnDefinition.java +++ b/src/main/java/org/terasology/herbalism/generator/HerbTundraSpawnDefinition.java @@ -6,8 +6,8 @@ import org.terasology.anotherWorld.decorator.BlockCollectionPredicate; import org.terasology.engine.world.block.BlockUri; import org.terasology.engine.world.generator.plugin.RegisterPlugin; -import org.terasology.gf.PlantType; -import org.terasology.gf.generator.StaticBlockFloraSpawnDefinition; +import org.terasology.growingflora.PlantType; +import org.terasology.growingflora.generator.StaticBlockFloraSpawnDefinition; import java.util.Arrays; diff --git a/src/main/java/org/terasology/herbalism/system/HerbalismAuthoritySystem.java b/src/main/java/org/terasology/herbalism/system/HerbalismAuthoritySystem.java index befb74e..48146f7 100644 --- a/src/main/java/org/terasology/herbalism/system/HerbalismAuthoritySystem.java +++ b/src/main/java/org/terasology/herbalism/system/HerbalismAuthoritySystem.java @@ -17,11 +17,11 @@ import org.terasology.engine.world.block.BlockComponent; import org.terasology.genome.component.GenomeComponent; import org.terasology.genome.system.GenomeManager; -import org.terasology.gf.PlantedSaplingComponent; +import org.terasology.growingflora.PlantedSaplingComponent; +import org.terasology.growingflora.randomUpdate.RandomUpdateEvent; import org.terasology.herbalism.Herbalism; import org.terasology.herbalism.component.PollinatingHerbComponent; import org.terasology.math.geom.Vector3i; -import org.terasology.randomUpdate.RandomUpdateEvent; /** * Authority system for Herbalism. Specifically for the planting and pollination of herb species.