fix foliage seed handling
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
d56d08204c
commit
822424af3f
@ -1734,6 +1734,7 @@ Catch errors in pathfinding threads
|
||||
Remove old data classes
|
||||
Update default block cursor size
|
||||
Creature template -> object template
|
||||
Fix foliage saving seed to template
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
package electrosphere.client.ui.menu.ingame;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
@ -239,7 +237,7 @@ public class MenuGeneratorsLevelEditor {
|
||||
Realm realm = Globals.realmManager.getRealms().iterator().next();
|
||||
CollisionEngine clientCollisionEngine = Globals.clientSceneWrapper.getCollisionEngine(); //using client collision engine so ray doesn't collide with player entity
|
||||
Vector3d cursorPos = clientCollisionEngine.rayCastPosition(new Vector3d(centerPos), new Vector3d(eyePos).mul(-1.0), CollisionEngine.DEFAULT_INTERACT_DISTANCE).add(cursorVerticalOffset);
|
||||
FoliageUtils.serverSpawnTreeFoliage(realm, cursorPos, data.getId(), new Random().nextLong());
|
||||
FoliageUtils.serverSpawnTreeFoliage(realm, cursorPos, data.getId());
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
package electrosphere.client.ui.menu.script;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.graalvm.polyglot.HostAccess.Export;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
@ -69,7 +67,7 @@ public class ScriptLevelEditorUtils {
|
||||
cursorPos = new Vector3d(centerPos).add(new Vector3d(eyePos).normalize().mul(-CollisionEngine.DEFAULT_INTERACT_DISTANCE));
|
||||
}
|
||||
cursorPos = cursorPos.add(cursorVerticalOffset);
|
||||
FoliageUtils.serverSpawnTreeFoliage(realm, cursorPos, Globals.selectedSpawntype.getId(), new Random().nextLong());
|
||||
FoliageUtils.serverSpawnTreeFoliage(realm, cursorPos, Globals.selectedSpawntype.getId());
|
||||
} else {
|
||||
LoggerInterface.loggerEngine.INFO("spawn " + Globals.selectedSpawntype.getId() + "!");
|
||||
Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(Globals.playerCamera));
|
||||
|
||||
@ -273,7 +273,6 @@ public class EntityDataStrings {
|
||||
*/
|
||||
public static final String FOLIAGE_TYPE = "foliageType";
|
||||
public static final String FOLIAGE_AMBIENT_TREE = "foliageAmbientTree";
|
||||
public static final String FOLIAGE_SEED = "foliageSeed";
|
||||
public static final String FOLIAGE_IS_SEEDED = "foliageIsSeeded";
|
||||
|
||||
/*
|
||||
|
||||
@ -68,6 +68,7 @@ import electrosphere.entity.types.collision.CollisionObjUtils;
|
||||
import electrosphere.entity.types.creature.CreatureUtils;
|
||||
import electrosphere.entity.types.creature.ObjectInventoryData;
|
||||
import electrosphere.entity.types.creature.ObjectTemplate;
|
||||
import electrosphere.entity.types.item.ItemUtils;
|
||||
import electrosphere.game.data.collidable.CollidableTemplate;
|
||||
import electrosphere.game.data.common.CommonEntityType;
|
||||
import electrosphere.game.data.creature.type.CreatureData;
|
||||
@ -833,6 +834,33 @@ public class CommonEntityUtils {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawns a server-side object
|
||||
* @param type The type of object to spawn
|
||||
* @return The object
|
||||
*/
|
||||
public static Entity serverSpawnTemplateObject(Realm realm, Vector3d position, String type, ObjectTemplate template){
|
||||
Entity rVal = CommonEntityUtils.serverSpawnBasicObject(realm, position, type);
|
||||
|
||||
//apply inventory data
|
||||
if(template.getInventoryData() != null){
|
||||
ObjectInventoryData inventoryData = template.getInventoryData();
|
||||
if(inventoryData.getNaturalItems() != null && inventoryData.getNaturalItems().size() > 0){
|
||||
for(EntitySerialization serializedItem : inventoryData.getNaturalItems()){
|
||||
ItemUtils.serverCreateContainerItem(rVal, Globals.gameConfigCurrent.getItemMap().getItem(serializedItem.getSubtype()));
|
||||
}
|
||||
}
|
||||
if(inventoryData.getEquipItems() != null && inventoryData.getEquipItems().size() > 0){
|
||||
throw new Error("Unsupported currently");
|
||||
}
|
||||
if(inventoryData.getToolbarItems() != null && inventoryData.getToolbarItems().size() > 0){
|
||||
throw new Error("Unsupported currently");
|
||||
}
|
||||
}
|
||||
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the object to a given player
|
||||
* @param player The player
|
||||
|
||||
@ -27,19 +27,24 @@ import org.joml.Vector3d;
|
||||
*/
|
||||
public class FoliageUtils {
|
||||
|
||||
/**
|
||||
* Default seed
|
||||
*/
|
||||
public static final long DEFAULT_SEED = 0;
|
||||
|
||||
/**
|
||||
* Spawns a basic foliage object
|
||||
* @param type The type of foliage object
|
||||
* @return The entity for the foliage
|
||||
*/
|
||||
public static Entity clientSpawnBasicFoliage(String type, long seed){
|
||||
public static Entity clientSpawnBasicFoliage(String type){
|
||||
FoliageType rawType = Globals.gameConfigCurrent.getFoliageMap().getType(type);
|
||||
Entity rVal;
|
||||
if(
|
||||
rawType.getGraphicsTemplate().getProceduralModel() != null &&
|
||||
rawType.getGraphicsTemplate().getProceduralModel().getTreeModel()!=null
|
||||
){
|
||||
rVal = ProceduralTree.clientGenerateProceduralTree(type, 0);
|
||||
rVal = ProceduralTree.clientGenerateProceduralTree(type, DEFAULT_SEED);
|
||||
} else {
|
||||
rVal = EntityCreationUtils.createClientSpatialEntity();
|
||||
}
|
||||
@ -56,7 +61,6 @@ public class FoliageUtils {
|
||||
//
|
||||
//
|
||||
rVal.putData(EntityDataStrings.FOLIAGE_TYPE, rawType);
|
||||
rVal.putData(EntityDataStrings.FOLIAGE_SEED, seed);
|
||||
rVal.putData(EntityDataStrings.FOLIAGE_IS_SEEDED, true);
|
||||
|
||||
//audio
|
||||
@ -77,14 +81,14 @@ public class FoliageUtils {
|
||||
* @param seed the seed for the tree
|
||||
* @return the tree entity
|
||||
*/
|
||||
public static Entity serverSpawnTreeFoliage(Realm realm, Vector3d position, String type, long seed){
|
||||
public static Entity serverSpawnTreeFoliage(Realm realm, Vector3d position, String type){
|
||||
FoliageType rawType = Globals.gameConfigCurrent.getFoliageMap().getType(type);
|
||||
Entity rVal;
|
||||
if(
|
||||
rawType.getGraphicsTemplate().getProceduralModel() != null &&
|
||||
rawType.getGraphicsTemplate().getProceduralModel().getTreeModel()!=null
|
||||
){
|
||||
rVal = ProceduralTree.serverGenerateProceduralTree(realm, position, rawType, seed);
|
||||
rVal = ProceduralTree.serverGenerateProceduralTree(realm, position, rawType, DEFAULT_SEED);
|
||||
} else {
|
||||
rVal = EntityCreationUtils.createServerEntity(realm, position);
|
||||
}
|
||||
@ -104,7 +108,6 @@ public class FoliageUtils {
|
||||
//
|
||||
ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.FOLIAGE);
|
||||
rVal.putData(EntityDataStrings.FOLIAGE_TYPE, rawType);
|
||||
rVal.putData(EntityDataStrings.FOLIAGE_SEED, seed);
|
||||
rVal.putData(EntityDataStrings.FOLIAGE_IS_SEEDED, true);
|
||||
|
||||
//position entity
|
||||
@ -117,15 +120,6 @@ public class FoliageUtils {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the seed for a given foliage item
|
||||
* @param entity The entity
|
||||
* @return The seed
|
||||
*/
|
||||
public static long getFoliageSeed(Entity entity){
|
||||
return (long)entity.getData(EntityDataStrings.FOLIAGE_SEED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type of foliage
|
||||
* @param entity the entity
|
||||
@ -165,12 +159,11 @@ public class FoliageUtils {
|
||||
Vector3d position = EntityUtils.getPosition(foliage);
|
||||
Quaterniond rotation = EntityUtils.getRotation(foliage);
|
||||
if(FoliageUtils.hasSeed(foliage)){
|
||||
long seed = FoliageUtils.getFoliageSeed(foliage);
|
||||
NetworkMessage message = EntityMessage.constructCreateMessage(
|
||||
id,
|
||||
EntityType.FOLIAGE.getValue(),
|
||||
type.getId(),
|
||||
seed + "",
|
||||
DEFAULT_SEED + "",
|
||||
position.x,
|
||||
position.y,
|
||||
position.z,
|
||||
|
||||
@ -258,7 +258,7 @@ public class EntityProtocol implements ClientProtocolTemplate<EntityMessage> {
|
||||
static Entity spawnFoliage(EntityMessage message){
|
||||
LoggerInterface.loggerNetworking.DEBUG("[CLIENT] Spawn foliage " + message.getentityID() + " at " + message.getpositionX() + " " + message.getpositionY() + " " + message.getpositionZ());
|
||||
String type = message.getentitySubtype();
|
||||
Entity newlySpawnedEntity = FoliageUtils.clientSpawnBasicFoliage(type,Long.parseLong(message.getcreatureTemplate()));
|
||||
Entity newlySpawnedEntity = FoliageUtils.clientSpawnBasicFoliage(type);
|
||||
ClientEntityUtils.initiallyPositionEntity(
|
||||
newlySpawnedEntity,
|
||||
new Vector3d(message.getpositionX(),message.getpositionY(),message.getpositionZ()),
|
||||
|
||||
@ -43,7 +43,7 @@ public class EnvironmentGenerator {
|
||||
0,
|
||||
ServerWorldData.convertWorldToReal(worldPos.z) + rand.nextFloat() * 16
|
||||
);
|
||||
FoliageUtils.serverSpawnTreeFoliage(realm, position, "oak", rand.nextLong());
|
||||
FoliageUtils.serverSpawnTreeFoliage(realm, position, "oak");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,8 +117,7 @@ public class ServerContentGenerator {
|
||||
height,
|
||||
realZ
|
||||
),
|
||||
type,
|
||||
random.nextLong()
|
||||
type
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,15 +65,15 @@ public class ContentSerialization {
|
||||
EntitySerialization serializedEntity = new EntitySerialization();
|
||||
serializedEntity.setPosition(EntityUtils.getPosition(entity));
|
||||
serializedEntity.setRotation(EntityUtils.getRotation(entity));
|
||||
if(CommonEntityUtils.getObjectTemplate(entity) != null){
|
||||
serializedEntity.setTemplate(Utilities.stringify(CommonEntityUtils.getObjectTemplate(entity)));
|
||||
}
|
||||
EntityType type = CommonEntityUtils.getEntityType(entity);
|
||||
if(type != null){
|
||||
switch(type){
|
||||
case CREATURE: {
|
||||
serializedEntity.setType(EntityType.CREATURE.getValue());
|
||||
serializedEntity.setSubtype(CommonEntityUtils.getEntitySubtype(entity));
|
||||
if(CommonEntityUtils.getObjectTemplate(entity) != null){
|
||||
serializedEntity.setTemplate(Utilities.stringify(CommonEntityUtils.getObjectTemplate(entity)));
|
||||
}
|
||||
} break;
|
||||
case ITEM: {
|
||||
if(!AttachUtils.isAttached(entity)){
|
||||
@ -84,7 +84,6 @@ public class ContentSerialization {
|
||||
case FOLIAGE: {
|
||||
serializedEntity.setType(EntityType.FOLIAGE.getValue());
|
||||
serializedEntity.setSubtype(CommonEntityUtils.getEntitySubtype(entity));
|
||||
serializedEntity.setTemplate(FoliageUtils.getFoliageSeed(entity) + "");
|
||||
} break;
|
||||
case COMMON: {
|
||||
serializedEntity.setType(EntityType.COMMON.getValue());
|
||||
@ -121,15 +120,17 @@ public class ContentSerialization {
|
||||
if(serializedEntity.getSubtype() == null){
|
||||
throw new Error("Subtype undefined!");
|
||||
}
|
||||
ObjectTemplate template = null;
|
||||
if(serializedEntity.getTemplate() != null && serializedEntity.getTemplate().length() > 0){
|
||||
try{
|
||||
template = Utilities.deserialize(serializedEntity.getTemplate(), ObjectTemplate.class);
|
||||
} catch(Exception e){
|
||||
String message = serializedEntity.getTemplate() + "\n";
|
||||
throw new Error(message, e);
|
||||
}
|
||||
}
|
||||
switch(EntityTypes.fromInt(serializedEntity.getType())){
|
||||
case CREATURE: {
|
||||
ObjectTemplate template = null;
|
||||
if(serializedEntity.getTemplate() != null){
|
||||
template = Utilities.deserialize(serializedEntity.getTemplate(), ObjectTemplate.class);
|
||||
}
|
||||
|
||||
//
|
||||
//Spawn the creature itself
|
||||
rVal = CreatureUtils.serverSpawnBasicCreature(realm, serializedEntity.getPosition(), serializedEntity.getSubtype(), template);
|
||||
CreatureUtils.serverApplyTemplate(realm, rVal, template);
|
||||
EntityUtils.getRotation(rVal).set(serializedEntity.getRotation());
|
||||
@ -139,12 +140,15 @@ public class ContentSerialization {
|
||||
EntityUtils.getRotation(rVal).set(serializedEntity.getRotation());
|
||||
} break;
|
||||
case COMMON: {
|
||||
rVal = CommonEntityUtils.serverSpawnBasicObject(realm, serializedEntity.getPosition(), serializedEntity.getSubtype());
|
||||
if(template == null){
|
||||
rVal = CommonEntityUtils.serverSpawnBasicObject(realm, serializedEntity.getPosition(), serializedEntity.getSubtype());
|
||||
} else {
|
||||
rVal = CommonEntityUtils.serverSpawnTemplateObject(realm, serializedEntity.getPosition(), serializedEntity.getSubtype(), template);
|
||||
}
|
||||
EntityUtils.getRotation(rVal).set(serializedEntity.getRotation());
|
||||
} break;
|
||||
case FOLIAGE: {
|
||||
long seed = Long.parseLong(serializedEntity.getTemplate());
|
||||
rVal = FoliageUtils.serverSpawnTreeFoliage(realm, serializedEntity.getPosition(), serializedEntity.getSubtype(), seed);
|
||||
rVal = FoliageUtils.serverSpawnTreeFoliage(realm, serializedEntity.getPosition(), serializedEntity.getSubtype());
|
||||
EntityUtils.getRotation(rVal).set(serializedEntity.getRotation());
|
||||
} break;
|
||||
case ENGINE: {
|
||||
@ -160,15 +164,12 @@ public class ContentSerialization {
|
||||
*/
|
||||
public static Entity clientHydrateEntitySerialization(EntitySerialization serializedEntity){
|
||||
Entity rVal = null;
|
||||
ObjectTemplate template = null;
|
||||
if(serializedEntity.getTemplate() != null && serializedEntity.getTemplate().length() > 0){
|
||||
template = Utilities.deserialize(serializedEntity.getTemplate(), ObjectTemplate.class);
|
||||
}
|
||||
switch(EntityTypes.fromInt(serializedEntity.getType())){
|
||||
case CREATURE: {
|
||||
ObjectTemplate template = null;
|
||||
if(serializedEntity.getTemplate() != null){
|
||||
template = Utilities.deserialize(serializedEntity.getTemplate(), ObjectTemplate.class);
|
||||
}
|
||||
|
||||
//
|
||||
//Spawn the creature itself
|
||||
rVal = CreatureUtils.clientSpawnBasicCreature(serializedEntity.getSubtype(), template);
|
||||
CreatureUtils.clientApplyTemplate(rVal, template);
|
||||
EntityUtils.getRotation(rVal).set(serializedEntity.getRotation());
|
||||
@ -182,8 +183,7 @@ public class ContentSerialization {
|
||||
EntityUtils.getRotation(rVal).set(serializedEntity.getRotation());
|
||||
} break;
|
||||
case FOLIAGE: {
|
||||
long seed = Long.parseLong(serializedEntity.getTemplate());
|
||||
rVal = FoliageUtils.clientSpawnBasicFoliage(serializedEntity.getSubtype(), seed);
|
||||
rVal = FoliageUtils.clientSpawnBasicFoliage(serializedEntity.getSubtype());
|
||||
EntityUtils.getRotation(rVal).set(serializedEntity.getRotation());
|
||||
} break;
|
||||
case ENGINE: {
|
||||
|
||||
@ -47,7 +47,7 @@ public class SpawnAllEntitiesTests extends EntityTestTemplate {
|
||||
|
||||
FoliageTypeLoader foliageTypeMap = Globals.gameConfigCurrent.getFoliageMap();
|
||||
for(FoliageType foliage : foliageTypeMap.getTypes()){
|
||||
FoliageUtils.serverSpawnTreeFoliage(Globals.realmManager.first(), new Vector3d(0.1,0.1,0.1), foliage.getId(), 0);
|
||||
FoliageUtils.serverSpawnTreeFoliage(Globals.realmManager.first(), new Vector3d(0.1,0.1,0.1), foliage.getId());
|
||||
}
|
||||
|
||||
CommonEntityMap commonEntityMap = Globals.gameConfigCurrent.getObjectTypeMap();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user