Skip to content

Commit

Permalink
fix(ecs-gestalt): Migrate Components to gestalt's Components. (#67)
Browse files Browse the repository at this point in the history
Ref: MovingBlocks/Terasology#4753

Co-authored-by: Tobias Nett <skaldarnar@googlemail.com>
  • Loading branch information
DarkWeird and skaldarnar committed Aug 25, 2021
1 parent c9d264a commit ef05c81
Show file tree
Hide file tree
Showing 36 changed files with 367 additions and 614 deletions.
Original file line number Diff line number Diff line change
@@ -1,45 +1,49 @@
/*
* 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 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.structureTemplates.components;

import org.joml.Vector3i;
import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.entitySystem.prefab.Prefab;
import org.terasology.engine.world.block.family.BlockFamily;
import org.terasology.gestalt.entitysystem.component.Component;
import org.terasology.reflection.MappedContainer;
import org.terasology.structureTemplates.events.SpawnStructureEvent;

import java.util.List;
import java.util.stream.Collectors;

/**
* This component is intended to be used in structure templates.
*
* It adds items (incl. block items) to one ore more chests when the entity receives a
* {@link SpawnStructureEvent}.
*/
public class AddItemsToChestComponent implements Component {
public class AddItemsToChestComponent implements Component<AddItemsToChestComponent> {
public List<ChestToFill> chestsToFill;

@Override
public void copyFrom(AddItemsToChestComponent other) {
this.chestsToFill = other.chestsToFill.stream()
.map(ChestToFill::copy)
.collect(Collectors.toList());
}

@MappedContainer
public static class ChestToFill {
/**
* Position of the chest to be filled
*/
public Vector3i position;
public List<Item> items;

ChestToFill copy() {
ChestToFill newChestToFill = new ChestToFill();
newChestToFill.position = new Vector3i(this.position);
newChestToFill.items = this.items.stream()
.map(Item::copy)
.collect(Collectors.toList());
return newChestToFill;
}
}

/**
Expand All @@ -65,5 +69,14 @@ public static class Item {
* The field {@link #amount} gets only used if {@link #blockFamiliy} != null.
*/
public int amount = 1;

Item copy() {
Item newItem = new Item();
newItem.slot = this.slot;
newItem.itemPrefab = this.itemPrefab;
newItem.blockFamiliy = this.blockFamiliy;
newItem.amount = this.amount;
return newItem;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
/*
* 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 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.structureTemplates.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.world.block.Block;
import org.terasology.gestalt.entitysystem.component.Component;

/**
* Block entities that have this component will be copied as the specified blocks when a structure template gets
* created.
*
*/
public class BlockPlaceholderComponent implements Component {
public class BlockPlaceholderComponent implements Component<BlockPlaceholderComponent> {
public Block block;

@Override
public void copyFrom(BlockPlaceholderComponent other) {
this.block = other.block;
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
/*
* 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 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.structureTemplates.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.world.block.Block;
import org.terasology.gestalt.entitysystem.component.EmptyComponent;
import org.terasology.structureTemplates.events.GetBlockPredicateEvent;

import java.util.function.Predicate;
Expand All @@ -25,5 +12,5 @@
* Marks a prefab as describing a condition for blocks. Send a {@link GetBlockPredicateEvent} to an entity
* with this component to get a {@link Predicate} that takes a {@link Block}.
*/
public class BlockPredicateComponent implements Component {
public class BlockPredicateComponent extends EmptyComponent<BlockPredicateComponent> {
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
/*
* Copyright 2017 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 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.structureTemplates.components;

import org.joml.Vector3i;
import org.terasology.engine.entitySystem.Component;
import org.terasology.gestalt.entitysystem.component.Component;
import org.terasology.structureTemplates.util.BlockRegionTransform;

/**
* Stores the data to construct a {@link BlockRegionTransform}
*/
public class BlockRegionTransformComponent implements Component {
public class BlockRegionTransformComponent implements Component<BlockRegionTransformComponent> {
public int counterClockWiseHorizontal90DegreeRotations = 0;

public Vector3i offset;

@Override
public void copyFrom(BlockRegionTransformComponent other) {
this.counterClockWiseHorizontal90DegreeRotations = other.counterClockWiseHorizontal90DegreeRotations;
this.offset = other.offset;
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +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 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.structureTemplates.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.entitySystem.prefab.Prefab;
import org.terasology.engine.world.block.BlockRegion;
import org.terasology.gestalt.entitysystem.component.Component;
import org.terasology.reflection.MappedContainer;
import org.terasology.structureTemplates.events.CheckSpawnConditionEvent;
import org.terasology.structureTemplates.events.GetBlockPredicateEvent;

import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
*
Expand All @@ -37,9 +25,16 @@
*
* The condition prefab must contain the component {@link BlockPredicateComponent}.
*/
public class CheckBlockRegionConditionComponent implements Component {
public class CheckBlockRegionConditionComponent implements Component<CheckBlockRegionConditionComponent> {
public List<BlockRegionConditionCheck> checksToPerform;

@Override
public void copyFrom(CheckBlockRegionConditionComponent other) {
this.checksToPerform = other.checksToPerform.stream()
.map(BlockRegionConditionCheck::copy)
.collect(Collectors.toList());
}

@MappedContainer
public static class BlockRegionConditionCheck {
/**
Expand All @@ -50,5 +45,12 @@ public static class BlockRegionConditionCheck {
* Region which should be checked against the condition.
*/
public BlockRegion region;

BlockRegionConditionCheck copy() {
BlockRegionConditionCheck newObj = new BlockRegionConditionCheck();
newObj.condition = this.condition;
newObj.region = new BlockRegion(this.region);
return newObj;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
/*
* Copyright 2018 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.structureTemplates.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.gestalt.entitysystem.component.Component;

public class CompletionTimeComponent implements Component {
public class CompletionTimeComponent implements Component<CompletionTimeComponent> {
public long completionDelay;

@Override
public void copyFrom(CompletionTimeComponent other) {
this.completionDelay = other.completionDelay;
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
/*
* Copyright 2017 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 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.structureTemplates.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.network.FieldReplicateType;
import org.terasology.engine.network.Replicate;
import org.terasology.engine.world.block.BlockUri;
import org.terasology.gestalt.entitysystem.component.Component;

/**
* Shows a fall animation until it reaches target height.
* Once there is a block at the target height this entity will be destroyed.
*/

@Replicate(FieldReplicateType.SERVER_TO_CLIENT)
public class FallingBlockComponent implements Component {
public class FallingBlockComponent implements Component<FallingBlockComponent> {

@Replicate(FieldReplicateType.SERVER_TO_CLIENT)
public long stopGameTimeInMs;
Expand All @@ -39,4 +26,11 @@ public class FallingBlockComponent implements Component {
*/
@Replicate(FieldReplicateType.SERVER_TO_CLIENT)
public String blockUri;

@Override
public void copyFrom(FallingBlockComponent other) {
this.stopGameTimeInMs = other.stopGameTimeInMs;
this.startGameTimeInMs = other.startGameTimeInMs;
this.blockUri = other.blockUri;
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
/*
* Copyright 2017 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 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.structureTemplates.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.gestalt.entitysystem.component.EmptyComponent;

/**
* This component can be added to a structure template to exchange its placement algorithm with one
* where you can see blocks falling down and forming the new structure.
*/
public class FallingBlocksPlacementAlgorithmComponent implements Component {
public class FallingBlocksPlacementAlgorithmComponent extends EmptyComponent<FallingBlocksPlacementAlgorithmComponent> {

}

0 comments on commit ef05c81

Please sign in to comment.