-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
234 additions
and
23 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/client/java/fr/firstmegagame4/env/driven/assets/EDAEnvJsonVisitors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package fr.firstmegagame4.env.driven.assets; | ||
|
||
import fr.firstmegagame4.env.driven.assets.impl.env.json.BlockEnvJsonVisitor; | ||
import fr.firstmegagame4.env.driven.assets.impl.env.json.ClientEnvJsonVisitor; | ||
import fr.firstmegagame4.env.driven.assets.impl.env.json.EntityEnvJsonVisitor; | ||
import fr.firstmegagame4.env.json.api.EnvJsonVisitor; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
|
||
public class EDAEnvJsonVisitors { | ||
|
||
public static EnvJsonVisitor blockVisitor(World world, BlockPos pos) { | ||
return new BlockEnvJsonVisitor(world, pos); | ||
} | ||
|
||
public static EnvJsonVisitor clientVisitor(MinecraftClient client) { | ||
return new ClientEnvJsonVisitor(client); | ||
} | ||
|
||
public static EnvJsonVisitor entityVisitor(Entity entity) { | ||
return new EntityEnvJsonVisitor(entity); | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
src/client/java/fr/firstmegagame4/env/driven/assets/impl/env/json/BlockEnvJsonVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package fr.firstmegagame4.env.driven.assets.impl.env.json; | ||
|
||
import fr.firstmegagame4.env.json.api.EnvJsonVisitor; | ||
import fr.firstmegagame4.env.json.api.rule.SkyEnvJsonRule; | ||
import fr.firstmegagame4.env.json.api.rule.VoidEnvJsonRule; | ||
import fr.firstmegagame4.env.json.api.rule.WaterEnvJsonRule; | ||
import it.unimi.dsi.fastutil.ints.Int2BooleanFunction; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.registry.tag.FluidTags; | ||
import net.minecraft.registry.tag.TagKey; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.biome.Biome; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
@ApiStatus.Internal | ||
public class BlockEnvJsonVisitor implements EnvJsonVisitor { | ||
|
||
private final World world; | ||
private final BlockPos pos; | ||
|
||
public BlockEnvJsonVisitor(World world, BlockPos pos) { | ||
this.world = world; | ||
this.pos = pos; | ||
} | ||
|
||
@Override | ||
public boolean applyDimensionKey(RegistryKey<World> dimensionKey) { | ||
return this.world.getRegistryKey() == dimensionKey; | ||
} | ||
|
||
@Override | ||
public boolean applyDimensionTag(TagKey<World> dimensionTag) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean applyBiomeKey(RegistryKey<Biome> biomeKey) { | ||
return this.world.getBiome(this.pos).matchesKey(biomeKey); | ||
} | ||
|
||
@Override | ||
public boolean applyBiomeTag(TagKey<Biome> biomeTag) { | ||
return this.world.getBiome(this.pos).isIn(biomeTag); | ||
} | ||
|
||
@Override | ||
public boolean applyXCoord(Int2BooleanFunction operation) { | ||
return operation.get(this.pos.getX()); | ||
} | ||
|
||
@Override | ||
public boolean applyYCoord(Int2BooleanFunction operation) { | ||
return operation.get(this.pos.getY()); | ||
} | ||
|
||
@Override | ||
public boolean applyZCoord(Int2BooleanFunction operation) { | ||
return operation.get(this.pos.getZ()); | ||
} | ||
|
||
@Override | ||
public boolean applySubmerged(boolean submerged) { | ||
return submerged && this.world.getBlockState(this.pos.up()).getFluidState().isIn(FluidTags.WATER); | ||
} | ||
|
||
@Override | ||
public boolean applySky(SkyEnvJsonRule.Localization localization) { | ||
return switch (localization) { | ||
case BELOW -> this.pos.getY() <= this.world.getTopY(); | ||
case ABOVE -> this.pos.getY() > this.world.getTopY(); | ||
}; | ||
} | ||
|
||
@Override | ||
public boolean applyWater(WaterEnvJsonRule.Localization localization) { | ||
return switch (localization) { | ||
case BELOW -> this.pos.getY() <= this.world.getSeaLevel(); | ||
case ABOVE -> this.pos.getY() > this.world.getSeaLevel(); | ||
}; | ||
} | ||
|
||
@Override | ||
public boolean applyVoid(VoidEnvJsonRule.Localization localization) { | ||
return switch (localization) { | ||
case BELOW -> this.pos.getY() <= this.world.getBottomY(); | ||
case ABOVE -> this.pos.getY() > this.world.getBottomY(); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/client/java/fr/firstmegagame4/env/driven/assets/impl/env/json/EntityEnvJsonVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package fr.firstmegagame4.env.driven.assets.impl.env.json; | ||
|
||
import fr.firstmegagame4.env.json.api.EnvJsonVisitor; | ||
import fr.firstmegagame4.env.json.api.rule.SkyEnvJsonRule; | ||
import fr.firstmegagame4.env.json.api.rule.VoidEnvJsonRule; | ||
import fr.firstmegagame4.env.json.api.rule.WaterEnvJsonRule; | ||
import it.unimi.dsi.fastutil.ints.Int2BooleanFunction; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.registry.tag.TagKey; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.biome.Biome; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
@ApiStatus.Internal | ||
public class EntityEnvJsonVisitor implements EnvJsonVisitor { | ||
|
||
private final Entity entity; | ||
|
||
public EntityEnvJsonVisitor(Entity entity) { | ||
this.entity = entity; | ||
} | ||
|
||
@Override | ||
public boolean applyDimensionKey(RegistryKey<World> dimensionKey) { | ||
return this.entity.getWorld().getRegistryKey() == dimensionKey; | ||
} | ||
|
||
@Override | ||
public boolean applyDimensionTag(TagKey<World> dimensionTag) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean applyBiomeKey(RegistryKey<Biome> biomeKey) { | ||
return this.entity.getWorld().getBiome(this.entity.getBlockPos()).matchesKey(biomeKey); | ||
} | ||
|
||
@Override | ||
public boolean applyBiomeTag(TagKey<Biome> biomeTag) { | ||
return this.entity.getWorld().getBiome(this.entity.getBlockPos()).isIn(biomeTag); | ||
} | ||
|
||
@Override | ||
public boolean applyXCoord(Int2BooleanFunction operation) { | ||
return operation.get(this.entity.getBlockX()); | ||
} | ||
|
||
@Override | ||
public boolean applyYCoord(Int2BooleanFunction operation) { | ||
return operation.get(this.entity.getBlockY()); | ||
} | ||
|
||
@Override | ||
public boolean applyZCoord(Int2BooleanFunction operation) { | ||
return operation.get(this.entity.getBlockZ()); | ||
} | ||
|
||
@Override | ||
public boolean applySubmerged(boolean submerged) { | ||
return submerged; | ||
} | ||
|
||
@Override | ||
public boolean applySky(SkyEnvJsonRule.Localization localization) { | ||
return switch (localization) { | ||
case BELOW -> this.entity.getBlockY() <= this.entity.getWorld().getTopY(); | ||
case ABOVE -> this.entity.getBlockY() > this.entity.getWorld().getTopY(); | ||
}; | ||
} | ||
|
||
@Override | ||
public boolean applyWater(WaterEnvJsonRule.Localization localization) { | ||
return switch (localization) { | ||
case BELOW -> this.entity.getBlockY() <= this.entity.getWorld().getSeaLevel(); | ||
case ABOVE -> this.entity.getBlockY() > this.entity.getWorld().getSeaLevel(); | ||
}; | ||
} | ||
|
||
@Override | ||
public boolean applyVoid(VoidEnvJsonRule.Localization localization) { | ||
return switch (localization) { | ||
case BELOW -> this.entity.getBlockY() <= this.entity.getWorld().getBottomY(); | ||
case ABOVE -> this.entity.getBlockY() > this.entity.getWorld().getBottomY(); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters