Skip to content

Commit

Permalink
JOML method replacements for (WorldProvider, BlockEntityRegistry)
Browse files Browse the repository at this point in the history
  • Loading branch information
pollend committed Apr 20, 2020
1 parent 12f4964 commit 5ea60e5
Show file tree
Hide file tree
Showing 9 changed files with 489 additions and 44 deletions.
25 changes: 23 additions & 2 deletions engine-tests/src/main/java/org/terasology/MapWorldProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.terasology;

import com.google.common.collect.Maps;
import org.joml.Vector3ic;
import org.terasology.entitySystem.entity.EntityRef;
import org.terasology.math.ChunkMath;
import org.terasology.math.Region3i;
Expand Down Expand Up @@ -89,6 +90,11 @@ public Block setBlock(Vector3i pos, Block type) {
return blocks.put(pos, type);
}

@Override
public Block setBlock(Vector3ic pos, Block type) {
return null;
}

@Override
public Block getBlock(int x, int y, int z) {
Vector3i pos = new Vector3i(x, y, z);
Expand Down Expand Up @@ -132,11 +138,21 @@ public ChunkViewCore getLocalView(Vector3i chunkPos) {
return null;
}

@Override
public ChunkViewCore getLocalView(Vector3ic chunkPos) {
return null;
}

@Override
public ChunkViewCore getWorldViewAround(Vector3i chunk) {
return null;
}

@Override
public ChunkViewCore getWorldViewAround(Vector3ic chunk) {
return null;
}

@Override
public byte getLight(int x, int y, int z) {
return 0;
Expand All @@ -151,12 +167,17 @@ public byte getSunlight(int x, int y, int z) {
public byte getTotalLight(int x, int y, int z) {
return 0;
}

@Override
public int setExtraData(int index, Vector3i pos, int value) {
return 0;
}


@Override
public int setExtraData(int index, Vector3ic pos, int value) {
return 0;
}

@Override
public int getExtraData(int index, int x, int y, int z) {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.terasology.testUtil;

import com.google.common.collect.Maps;
import org.joml.Vector3ic;
import org.terasology.entitySystem.entity.EntityRef;
import org.terasology.math.Region3i;
import org.terasology.math.geom.Vector3i;
Expand Down Expand Up @@ -85,11 +86,21 @@ public ChunkViewCore getLocalView(Vector3i chunkPos) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}

@Override
public ChunkViewCore getLocalView(Vector3ic chunkPos) {
return null;
}

@Override
public ChunkViewCore getWorldViewAround(Vector3i chunk) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}

@Override
public ChunkViewCore getWorldViewAround(Vector3ic chunk) {
return null;
}

@Override
public boolean isBlockRelevant(int x, int y, int z) {
return true; //To change body of implemented methods use File | Settings | File Templates.
Expand All @@ -109,6 +120,11 @@ public Block setBlock(Vector3i pos, Block type) {
return old;
}

@Override
public Block setBlock(Vector3ic pos, Block type) {
return null;
}

@Override
public Map<Vector3i, Block> setBlocks(Map<Vector3i, Block> blocksToPlace) {
Map<Vector3i, Block> result = new HashMap<>(blocks.size());
Expand Down Expand Up @@ -142,18 +158,23 @@ public byte getSunlight(int x, int y, int z) {
public byte getTotalLight(int x, int y, int z) {
return 0; //To change body of implemented methods use File | Settings | File Templates.
}

@Override
public int setExtraData(int index, Vector3i pos, int value) {
Integer prevValue = getExtraDataLayer(index).put(pos, value);
return prevValue == null ? 0 : prevValue;
}


@Override
public int setExtraData(int index, Vector3ic pos, int value) {
return 0;
}

@Override
public int getExtraData(int index, int x, int y, int z) {
return getExtraDataLayer(index).getOrDefault(new Vector3i(x, y, z), 0);
}

private Map<Vector3i, Integer> getExtraDataLayer(int index) {
while (extraData.size() <= index) {
extraData.add(Maps.newHashMap());
Expand Down
76 changes: 76 additions & 0 deletions engine/src/main/java/org/terasology/world/BlockEntityRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.terasology.world;

import org.joml.Vector3fc;
import org.joml.Vector3ic;
import org.terasology.entitySystem.Component;
import org.terasology.entitySystem.entity.EntityRef;
import org.terasology.math.geom.Vector3f;
Expand Down Expand Up @@ -45,56 +47,130 @@ public interface BlockEntityRegistry {
*
* @param blockPosition
* @return The block entity for the location if it exists, or the null entity
* @deprecated
*/
EntityRef getExistingBlockEntityAt(Vector3i blockPosition);

/**
* This method returns the block entity at the given location, but will not produce a temporary entity if
* one isn't currently in memory.
*
* @param blockPosition
* @return The block entity for the location if it exists, or the null entity
*/
EntityRef getExistingBlockEntityAt(Vector3ic blockPosition);


/**
* This method is the same as setBlock, except if the old and new block types are part of the same family the
* entity will be force updated (usually they are not in this situation).
*
* @param position
* @param type
* @return The previous block type, or null if the change failed due to the chunk not being available
* @deprecated
*/
Block setBlockForceUpdateEntity(Vector3i position, Block type);

/**
* This method is the same as setBlock, except if the old and new block types are part of the same family the
* entity will be force updated (usually they are not in this situation).
*
* @param position
* @param type
* @return The previous block type, or null if the change failed due to the chunk not being available
*/
Block setBlockForceUpdateEntity(Vector3ic position, Block type);


/**
* This method is the same as setBlock, except the specified components are not altered during the update
*
* @param position
* @param type
* @param components
* @return The previous block type, or null if the change failed due to the chunk not being available
* @deprecated
*/
Block setBlockRetainComponent(Vector3i position, Block type, Class<? extends Component>... components);

/**
* This method is the same as setBlock, except the specified components are not altered during the update
*
* @param position
* @param type
* @param components
* @return The previous block type, or null if the change failed due to the chunk not being available
*/
Block setBlockRetainComponent(Vector3ic position, Block type, Class<? extends Component>... components);


/**
* @param position
* @return The block entity for the location, creating it if it doesn't exist
* @deprecated
*/
EntityRef getBlockEntityAt(Vector3f position);

/**
* @param position
* @return The block entity for the location, creating it if it doesn't exist
*/
EntityRef getBlockEntityAt(Vector3fc position);


/**
* @param blockPosition
* @return The block entity for the location, creating it if it doesn't exist
* @deprecated
*/
EntityRef getBlockEntityAt(Vector3i blockPosition);

/**
* @param blockPosition
* @return The block entity for the location, creating it if it doesn't exist
*/
EntityRef getBlockEntityAt(Vector3ic blockPosition);


/**
* @param blockPosition
* @return The block controller entity for this location, or block entity if it exists.
* @deprecated
*/
EntityRef getExistingEntityAt(Vector3i blockPosition);

/**
* @param blockPosition
* @return The block controller entity for this location, or block entity if it exists.
*/
EntityRef getExistingEntityAt(Vector3ic blockPosition);


/**
* @param blockPosition
* @return The block controller entity for this location, or block entity.
* @deprecated
*/
EntityRef getEntityAt(Vector3i blockPosition);

/**
* @param blockPosition
* @return The block controller entity for this location, or block entity.
*/
EntityRef getEntityAt(Vector3ic blockPosition);


/**
* @param blockPos
* @return Whether the entity at this position is permanent
* @deprecated
*/
boolean hasPermanentBlockEntity(Vector3i blockPos);

/**
* @param blockPos
* @return Whether the entity at this position is permanent
*/
boolean hasPermanentBlockEntity(Vector3ic blockPos);
}
Loading

0 comments on commit 5ea60e5

Please sign in to comment.