Generate custom ores in custom dimension - minecraft

I have recently created a custom dimension using data packs in Minecraft 1.16.5.
This dimension is a part of a mod that I am writing and I am currently trying to generate custom ores in that dimension; However, I was not able to generate ores in a custom dimension the same way that I generate ores in the Overworld or Nether. As I mentioned the dimension is handled via data packs (.json files) but the biomes are handled in game code (.java). I am very new to Java & modding, any suggestions would be appreciated.
Thanks in advance.
Minecraft version : 1.16.5
Forge version : 36.2.9
The current code for Overworld & Nether ore gen :
public class OreGeneration
{
public static void generateOres(final BiomeLoadingEvent event)
{
// Gigalium :
if(!(event.getCategory().equals(Biome.Category.THEEND)))
{
// Nether :
if(event.getCategory().equals(Biome.Category.NETHER))
{
generateOre(event.getGeneration(), OreFeatureConfig.FillerBlockType.NETHERRACK, BlockInit.GIGALIUM_NETHER_ORE.get().defaultBlockState(), 6, 25, 50, 2);
generateOre(event.getGeneration(), OreFeatureConfig.FillerBlockType.NETHERRACK, BlockInit.GIGALIUM_NETHER_ORE.get().defaultBlockState(), 4, 51, 120, 2);
}
// Overworld :
if(event.getCategory().equals(Biome.Category.SWAMP) || event.getCategory().equals(Biome.Category.TAIGA))
{
generateOre(event.getGeneration(), OreFeatureConfig.FillerBlockType.NATURAL_STONE, BlockInit.GIGALIUM_ORE.get().defaultBlockState(), 5, 12, 15, 2);
generateOre(event.getGeneration(), OreFeatureConfig.FillerBlockType.NATURAL_STONE, BlockInit.GIGALIUM_ORE.get().defaultBlockState(), 4, 16, 20, 2);
}
if(!(event.getCategory().equals(Biome.Category.SWAMP) && event.getCategory().equals(Biome.Category.TAIGA)))
{
generateOre(event.getGeneration(), OreFeatureConfig.FillerBlockType.NATURAL_STONE, BlockInit.GIGALIUM_ORE.get().defaultBlockState(), 4, 10, 13, 1);
generateOre(event.getGeneration(), OreFeatureConfig.FillerBlockType.NATURAL_STONE, BlockInit.GIGALIUM_ORE.get().defaultBlockState(), 3, 14, 18, 1);
}
}
}
private static void generateOre(BiomeGenerationSettingsBuilder settings, RuleTest fillerType, BlockState state, int veinSize, int minHeight, int maxHeight, int amount)
{
settings.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Feature.ORE.configured(new OreFeatureConfig(fillerType, state, veinSize)).decorated(Placement.RANGE.configured(new TopSolidRangeConfig(minHeight, 0, maxHeight))).squared().count(amount));
}
}
Dimension code :
{
"type": "gigawhat_gigamod:gigaland",
"generator": {
"type": "minecraft:noise",
"seed": 0,
"settings": {
"bedrock_roof_position": -10,
"bedrock_floor_position": 0,
"sea_level": 80,
"disable_mob_generation": true,
"default_block": {
"Name": "gigawhat_gigamod:gigastone"
},
"default_fluid": {
"Name": "minecraft:water",
"Properties": {
"level": "0"
}
},
"noise": {
"height": 256,
"density_factor": 1,
"density_offset": -0.46875,
"size_horizontal": 1,
"size_vertical": 2,
"simplex_surface_noise": true,
"random_density_offset": true,
"amplified": true,
"sampling": {
"xz_scale": 1,
"y_scale": 1,
"xz_factor": 80,
"y_factor": 160
},
"bottom_slide": {
"target": -30,
"size": 0,
"offset": 0
},
"top_slide": {
"target": -10,
"size": 3,
"offset": 0
}
},
"structures": {
"structures": {}
}
},
"biome_source": {
"type": "minecraft:fixed",
"biome": "gigawhat_gigamod:gigaland_main_biome"
}
}
}
Biome Init code :
public class ModBiomes
{
public static final DeferredRegister<Biome> BIOMES = DeferredRegister.create(ForgeRegistries.BIOMES, Gigamod.MOD_ID);
public static final RegistryObject<Biome> GIGALAND_MAIN_BIOME = BIOMES.register("gigaland_main_biome", () -> makeGigalandMainBiome(() -> ModConfiguredSurfaceBuilders.GIGALAND_SURFACE, 0.205f, 0.02f));
private static Biome makeGigalandMainBiome(final Supplier<ConfiguredSurfaceBuilder<?>> surfaceBuilder, float depth, float scale)
{
MobSpawnInfo.Builder mobspawninfo$builder = new MobSpawnInfo.Builder();
BiomeGenerationSettings.Builder biomegenerationsettings$builder = (new BiomeGenerationSettings.Builder()).surfaceBuilder(surfaceBuilder);
DefaultBiomeFeatures.addDefaultOverworldLandStructures(biomegenerationsettings$builder);
biomegenerationsettings$builder.addStructureStart(StructureFeatures.MINESHAFT);
DefaultBiomeFeatures.addDefaultCarvers(biomegenerationsettings$builder);
DefaultBiomeFeatures.addDefaultUndergroundVariety(biomegenerationsettings$builder);
mobspawninfo$builder.addSpawn(EntityClassification.MONSTER, new MobSpawnInfo.Spawners(EntityType.BLAZE, 100, 10, 15));
return (new Biome.Builder()).precipitation(RainType.RAIN).biomeCategory(Category.EXTREME_HILLS).depth(depth).scale(scale).temperature(1.5F).downfall(0.9F).specialEffects((new BiomeAmbience.Builder()).waterColor(65518).waterFogColor(16763760).fogColor(16763760).skyColor(16763760).foliageColorOverride(9547008).grassColorOverride(9547008).ambientParticle(new ParticleEffectAmbience(ParticleTypes.LAVA, 0.003f)).skyColor(16763760).ambientLoopSound(SoundEvents.AMBIENT_CRIMSON_FOREST_LOOP).ambientMoodSound(new MoodSoundAmbience(SoundEvents.AMBIENT_WARPED_FOREST_MOOD, 6000, 8, 2.0D)).ambientAdditionsSound(new SoundAdditionsAmbience(SoundEvents.AMBIENT_NETHER_WASTES_MOOD, 0.0111D)).build()).mobSpawnSettings(mobspawninfo$builder.build()).generationSettings(biomegenerationsettings$builder.build()).build();
}
public static void register(IEventBus eventBus)
{
BIOMES.register(eventBus);
}
}

Answering my own question.
Instead of using event.getCategory().equals(SomeBiomeCategory) in the if statement in the OreGen class you should use event.getName().equals(YourModBiomeInit.BiomeName.getId(). Because event.getCategory().equals(SomeBiomeCategory) gets the category of the biome currently generating whilst event.getName().equals(YourModBiomeInit.BiomeName.getId() gets the registered name (or id).
So the if statement would look something like this :
if(event.getName().equals(YourModBiomeInit.SOME_BIOME.getId()))
{
// Generate ores ...
}

Related

How to get sum of of sums in laravel on to many to many relationship in laravel

I have a User table that have many TeamMember and each TeamMember have many Order. My query look like this at the moment:
$users = User::select('id', 'username')
->with(['userTeamMembers' => function ($query) {
$query->select('team_lead_id', 'team_member_id')
->withSum('completedOrders', 'amount')
->whereHas('completedOrders');
}])
->whereHas('userTeamMembers.completedOrders')
->get()
->toArray();
The output:
[
{
"id": 1,
"username": "user1",
"user_team_members": [
{
"team_lead_id": 1,
"team_member_id": 19,
"completed_orders_sum_amount": "100.00"
},
{
"team_lead_id": 1,
"team_member_id": 34,
"completed_orders_sum_amount": "200.00"
},
]
},
{
"id": 5,
"username": "user5",
"user_team_members": [
{
"team_lead_id": 5,
"team_member_id": 25,
"completed_orders_sum_amount": "50.00"
},
{
"team_lead_id": 5,
"team_member_id": 67,
"completed_orders_sum_amount": "50.00"
},
]
}
]
But what I'm trying to achieve is a result like below:
[
{
"id": 1,
"username": "user1",
"user_team_members_sum": "300.00"
},
{
"id": 5,
"username": "user5",
"user_team_members_sum": "100.00"
}
]
As you can see, all of the team members total are added together compared to the former output. Is the result like above achievable? My Models are like below:
User Model
class User extends Authenticatable
{
...
public function userTeamMembers()
{
return $this->hasMany(TeamMember::class, 'team_lead_id');
}
}
Team Member Model
class TeamMember extends Model
{
....
public function completedOrders()
{
return $this->hasMany(Order::class, 'user_id', 'team_member_id')->select('user_id', 'amount')->where('status', 1);
}
}
// Try this. It could serve your desire output
$users = User::select('id', 'username')
->withSum('userTeamMembers.completedOrders', 'amount')
->whereHas('userTeamMembers.completedOrders')
->get()
->toArray();

Nest JS - Serialization not work with nested object

I want to append a new field called logo_img_url after data manipulation. It works with the object but the nested array object seems not to work. Any recommendations or solution
import { Expose } from 'class-transformer';
import {} from 'class-validator';
import { Entity, Column } from 'typeorm';
import { BaseEntity } from '#common/base/entity.base';
import { getAdminImageUrl } from '#common/util/vault-file.util';
#Entity()
export class Agency extends BaseEntity {
#Expose()
#Column({
type: 'varchar',
length: '255',
nullable: true,
})
public logo_key!: string;
#Expose({ name: 'logoImgUrl' })
logo_img_url = this.logoImgUrl;
#Expose()
get logoImgUrl(): any {
return "http://localhost:30001/". this.logo_key;
}
}
Actaul response:
{
"data": [
{
"logo_img_url": "",
"id": 22,
"logo_url": "9597e74d-aaea-4502-b5cd-b2867504fd80",
},
{
"logo_img_url": "",
"id": 21,
"logo_url": "0a655497-1318-4276-a21f-cfdc259241a2",
},
],
"meta": {
"status_code": 200,
"pagination": {
"totalPages": 1,
"currentPage": 1,
"nextPage": null,
"paginationToken": null,
"previousPage": null,
"totalItems": 9,
"itemsPerPage": 10
}
}
}
Expected result:
{
"data": [
{
"logo_img_url": "http://localhost:3000/9597e74d-aaea-4502-b5cd-b2867504fd80",
"id": 22,
"logo_url": "9597e74d-aaea-4502-b5cd-b2867504fd80",
},
{
"logo_img_url": "http://localhost:3000/0a655497-1318-4276-a21f-cfdc259241a2",
"id": 21,
"logo_url": "0a655497-1318-4276-a21f-cfdc259241a2",
},
],
"meta": {
"status_code": 200,
"pagination": {
"totalPages": 1,
"currentPage": 1,
"nextPage": null,
"paginationToken": null,
"previousPage": null,
"totalItems": 9,
"itemsPerPage": 10
}
}
}
You can use #AfterLoad decorator from typeorm. Its calls the decorated method once the entity is loaded and then one can perform the required manipulations.
logo_img_url:string
#AfterLoad()
async transform(){
this.logo_img_url=`http://localhost:30001/${this.logo_key}`
}

I have a model class in which when price type is "fixed" it return object and when it is "percentage" it return string, I don't know how to it?

I have a model which receive a response in which when i have option and furthur values, In values i have a priceType which can be percentage or fixed.
When pricetype is percentage the response is Sting but when price type is fixed the response id object and i receive error..
Accept response
JSONObject jsonResponse = new JSONObject(response);
Gson gson = new GsonBuilder().create();
product = gson.fromJson(String.valueOf(jsonResponse), Product.class);
JSON REsponse for Percentage
{
"id": 73,
"option_id": 21,
"price": "7.0000",
"price_type": "percent",
"position": 0,
"created_at": "2019-10-22 04:23:16",
"updated_at": "2019-10-30 04:57:45",
"label": "Red",
"translations": [
{
"id": 73,
"option_value_id": 73,
"locale": "en",
"label": "Red"
}
]
}
Json Response for Fixed Price
{
"id": 74,
"option_id": 21,
"price": {
"amount": "5.0000",
"formatted": "$5.00",
"currency": "USD"
},
"price_type": "fixed",
"position": 1,
"created_at": "2019-10-22 04:23:16",
"updated_at": "2019-10-22 04:23:16",
"label": "White",
"translations": [
{
"id": 74,
"option_value_id": 74,
"locale": "en",
"label": "White"
}
]
}
Price can either be class or String but i don't know how to put in my model class..
You can declare your pojo class like below :--
public class Product<T> {
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getOption_id() {
return option_id;
}
public void setOption_id(int option_id) {
this.option_id = option_id;
}
private int id;
private int option_id;
public T getPrice() {
return price;
}
public void setPrice(T price) {
this.price = price;
}
T price;
.............
}
When response is parsed then you can check the type of the T then extract the data in that followed way.
Hope it solves your problem.Let me know if further code required.

How to customize czml datasource?

I have a CZML data that I extracted via python.
I have buildings, with their geometry, height, building ID, and intervals. each interval has a value.
After loading the czml data to Cesium, I'd like to access the attributes and then customize the color of the buildings according to the value given.
Here is a sample of my CZML:
[{
"id": "document",
"version": "1.0"
}, {
"id": 32,
"availability": "2014-01-01T00:00:00Z/2014-12-31T00:00:00Z",
"polygon": {
"positions": {
"cartographicDegrees": [54.7162360431897, 24.4519912715277, 0, 54.716219612921, 24.4519754832587, 0, 54.7162501395131, 24.4519488635358, 0, 54.7162465684811, 24.4519454316688, 0, 54.7162670831639, 24.4519275432238, 0, 54.7162707308589, 24.4519310439514, 0, 54.7163022563025, 24.4519035537608, 0, 54.7161962974502, 24.4518018819532, 0, 54.7161647729823, 24.4518293730395, 0, 54.7162035538772, 24.4520196028966, 0, 54.7162360431897, 24.4519912715277, 0]
},
"someProperty": [{
"interval": "2014-00-01T00:00:00Z/2014-01-01T00:00:00Z",
"En_C_need": 0.7
}, {
"interval": "2014-01-01T00:00:00Z/2014-02-01T00:00:00Z",
"En_C_need": 1.0
}, {
"interval": "2014-02-01T00:00:00Z/2014-03-01T00:00:00Z",
"En_C_need": 2.6
}, {
"interval": "2014-03-01T00:00:00Z/2014-04-01T00:00:00Z",
"En_C_need": 12.1
}, {
"interval": "2014-04-01T00:00:00Z/2014-05-01T00:00:00Z",
"En_C_need": 30.2
}, {
"interval": "2014-05-01T00:00:00Z/2014-06-01T00:00:00Z",
"En_C_need": 37.8
}],
"extrudedHeight": 6.0
}
}]
I have other GeoJSON data that I customized, I tried the same method but it didn't work.
Here is what I'm trying to do (this does not work):
var test2 = Cesium.CzmlDataSource.load ('Data/czml/TESTING/example_8.czml');
test2.then(function (dataSource) {
viewer.dataSources.add(test2);
viewer.zoomTo (test2);
var entities = dataSource.entities.values;
var colorHash = {};
var Energy = [];
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
Energy = entity.someProperty.En_C_need;
var color = colorHash [Energy];
if(!color ) {
if (Energy < 5 ) {
color = Cesium.Color.DARKSALMON.withAlpha (0.95);
} else if (Energy < 10) {
color = Cesium.Color.BURLYWOOD.withAlpha (0.95);
} else if (Energy < 20) {
color = Cesium.Color.RED.withAlpha (0.95);
} else {
color = Cesium.Color.PINK.withAlpha (0.95);
};
colorHash[Energy] = color;
};
entity.polygon.fill = true;
entity.polygon.material = color;
entity.polygon.outline = false;
};
});
To start with the solution - here's the working plnkr:
https://plnkr.co/edit/P1Cg4DNJYtK9r9XrLzxK?p=preview
I've changed several things in your code:
1) viewer.dataSources.add(test2); should be outside your promise (it doesn't really matter, but it's cleaner code - using the promise inside the promise feels strange).
2) According to the CZML properties spec, you need to place the properties in the right location in the CZML. It should not be inside the polygon, but in the "root":
var czml = [{"id": "document", "version": "1.0"},
{
"id": 32, "availability": "2014-01-01T00:00:00Z/2014-12-31T00:00:00Z", "properties": {
"someProperty": [
{"interval": "2014-00-01T00:00:00Z/2014-01-01T00:00:00Z", "En_C_need": 0.7},
{"interval": "2014-01-01T00:00:00Z/2014-02-01T00:00:00Z", "En_C_need": 1.0},
{"interval": "2014-02-01T00:00:00Z/2014-03-01T00:00:00Z", "En_C_need": 2.6},
{"interval": "2014-03-01T00:00:00Z/2014-04-01T00:00:00Z", "En_C_need": 12.1},
{"interval": "2014-04-01T00:00:00Z/2014-05-01T00:00:00Z", "En_C_need": 30.2},
{"interval": "2014-05-01T00:00:00Z/2014-06-01T00:00:00Z", "En_C_need": 37.8}
],
},
"polygon": {
"positions": {
"cartographicDegrees":
[54.7162360431897, 24.4519912715277, 0, 54.716219612921, 24.4519754832587, 0, 54.7162501395131, 24.4519488635358, 0, 54.7162465684811, 24.4519454316688, 0, 54.7162670831639, 24.4519275432238, 0, 54.7162707308589, 24.4519310439514, 0, 54.7163022563025, 24.4519035537608, 0, 54.7161962974502, 24.4518018819532, 0, 54.7161647729823, 24.4518293730395, 0, 54.7162035538772, 24.4520196028966, 0, 54.7162360431897, 24.4519912715277, 0]
},
"extrudedHeight": 6.0
}
}];
Then you can ask for the properties according to the interval (Energy = entity.properties.getValue(viewer.clock.currentTime).someProperty.En_C_need;) and get the Energy at viewer's current time.
Update after commentchatting:
Your code was not meant to change dynamically. You need to set the value either by callbackProperty as in this example: plnkr.co/edit/lm290uaQewEvfIOgXbDP?p=preview or by using timeIntervalCollection

JSON.Net references become null

I'm serializing my game state with JSON.Net, but weirdly some references are becoming null. They seem to serialize fine (the $id and $ref seem to be properly set when checking the output json), but the deserialized objectes contain null references where they shouldn't.
My state is as follows: I have a planet, which contains a list of tiles. Each tile knows it neighbours (again a list of tiles).
Here's a little piece of the json, the initial serialization: (most important part is the last line, where neighbours has uses a ref number)
"Tiles": {
"$id": "3",
"$values": [
{
"$id": "4",
"$type": "WarSystems.Tile, Assembly-CSharp",
"_type": 0,
"ID": "161d8ca1-f086-49eb-94ba-0b5b3bbb0921",
"Position": {
"x": 0.0,
"y": 0.0,
"z": -1.71737635
},
"Normal": {
"x": 0.0,
"y": 0.0,
"z": -1.0
},
"Neighbours": [
{
"$id": "5",
"$type": "WarSystems.Tile, Assembly-CSharp",
"_type": 2,
"ID": "f34a2bb1-4a10-49db-b2d5-7980ccc55760",
"Position": {
"x": 0.2789981,
"y": -0.8586796,
"z": -1.460893
},
"Normal": {
"x": 0.1624527,
"y": -0.4999933,
"z": -0.850656152
},
"Neighbours": [
{
"$ref": "4"
},
"Tiles" is the list of tiles in the planet. As you can see, the first tile has a neighbour, and their neighbour has the first tile as his neighbour. Serializing goes fine, all there neighbours are set properly.
However, when I deserialize this, and then reserialize that, I get the following: (now notice that neighbours has a null)
"Tiles": {
"$id": "3",
"$values": [
{
"$id": "4",
"$type": "WarSystems.Tile, Assembly-CSharp",
"_type": 0,
"ID": "161d8ca1-f086-49eb-94ba-0b5b3bbb0921",
"Position": {
"x": 0.0,
"y": 0.0,
"z": -1.71737635
},
"Normal": {
"x": 0.0,
"y": 0.0,
"z": -1.0
},
"Neighbours": [
{
"$id": "5",
"$type": "WarSystems.Tile, Assembly-CSharp",
"_type": 2,
"ID": "f34a2bb1-4a10-49db-b2d5-7980ccc55760",
"Position": {
"x": 0.2789981,
"y": -0.8586796,
"z": -1.460893
},
"Normal": {
"x": 0.1624527,
"y": -0.4999933,
"z": -0.850656152
},
"Neighbours": [
null,
As you can see, the first neighbour is now null. (I also checked the actual deserialized object, it also has the null reference, so it seems the deserializing goes wrong. Of course there is a lot more, but this part shows what's going wrong and the whole json would be a bit much to post.)
Lastly, this is how I (de)serialize:
private static string SerializeState(State state)
{
return JsonConvert.SerializeObject(state, SerializerSettings);
}
private static State DeserializeState(string serialized)
{
return JsonConvert.DeserializeObject<State>(serialized, SerializerSettings);
}
With the SerializerSettings shared between them:
private static JsonSerializerSettings SerializerSettings = new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Objects,
PreserveReferencesHandling = PreserveReferencesHandling.All,
ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
Converters = new List<JsonConverter>() { new Vector3Converter() },
Formatting = Formatting.Indented
};
(Vector3Converter is used to serialize Unity's Vector3. It simply serializes it as an object with 3 field: x, y, and z. As the Position property in the tiles.)
Does anyone know what's going wrong, and how to fix it?
Thanks!
Edit, the Planet and Tile class:
public class Planet
{
public Vector3 Position { get; set; }
public List<Tile> Tiles { get; set; }
public Planet(Vector3 pos, List<Tile> tiles)
{
Position = pos;
Tiles = tiles;
}
}
public class Tile
{
public Guid ID { get; set; }
[JsonRequired]
private TileType _type;
[JsonIgnore]
public TileType Type
{
get { return _type; }
set
{
if (_type != value)
{
_type = value;
if (TypeChanged != null) TypeChanged(_type);
}
}
}
public Vector3 Position { get; set; }
public Vector3 Normal { get; set; }
private List<Tile> _neighbours = new List<Tile>(6); //6 since we use a hex grid
public List<Tile> Neighbours { get { return _neighbours; } set { _neighbours = value; } }
// Events
public event System.Action<TileType> TypeChanged;
public Tile(TileType type, Vector3 pos, Vector3 normal)
{
ID = Guid.NewGuid();
Position = pos;
Normal = normal;
}
public void AddNeighbour(Tile neighbour)
{
_neighbours.Add(neighbour);
}
}
I've solved it. Once I added an empty constructor in my Tile class everything works as intended.
public Tile() { } //for deserialization