Merge branch '1.16-fabric' into fabric-creepy

This commit is contained in:
Waterpicker 2021-02-09 01:12:00 -06:00
commit 8b1d715e1e
77 changed files with 890 additions and 716 deletions

View file

@ -1,6 +1,6 @@
plugins {
id 'fabric-loom' version '0.5-SNAPSHOT'
id 'maven-publish'
id "fabric-loom" version "0.5-SNAPSHOT"
id "maven-publish"
}
apply plugin: "java"
@ -9,24 +9,66 @@ sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
maven { url = 'https://maven.fabricmc.net/' }
mavenCentral()
maven { url = 'https://www.cursemaven.com' }
maven { url = 'https://jitpack.io' }
maven { url = 'https://server.bbkr.space/artifactory/libs-release' }
maven {
name = "Fabric maven"
url = "https://maven.fabricmc.net/"
}
maven {
name = "Tehnut maven"
url "https://maven.tehnut.info"
content {
includeGroup "mcp.mobius.waila"
}
}
maven {
url = "https://www.cursemaven.com"
content {
includeGroup "curse.maven"
}
}
maven {
url = "https://jitpack.io"
content {
includeGroup "com.github.DimensionalDevelopment"
includeGroup "com.github.Waterpicker"
}
}
maven {
url = "https://server.bbkr.space/artifactory/libs-release"
content {
includeGroup "io.github.cottonmc"
}
}
maven {
name = "Ladysnake Libs"
url = "https://dl.bintray.com/ladysnake/libs"
}
maven {
name = "Tehnut maven"
url "https://maven.tehnut.info"
content {
includeGroup "mcp.mobius.waila"
}
}
}
def includeCompile(str) {
def dep
def includeCompile(group, artifact, version) {
project.dependencies {
dep = modImplementation(str) {
modCompileOnly("$group:$artifact:$version") {
exclude module: "fabric-api"
}
include(str)
modRuntime("$group:$artifact:$version") {
exclude module: "fabric-api"
}
include("$group:$artifact:$version")
}
project.publishing {
publications {
@ -34,9 +76,9 @@ def includeCompile(str) {
pom.withXml {
def depsNode = asNode().appendNode("dependencies")
def depNode = depsNode.appendNode("dependency")
depNode.appendNode("groupId", dep.group)
depNode.appendNode("artifactId", dep.name)
depNode.appendNode("version", dep.version)
depNode.appendNode("groupId", group)
depNode.appendNode("artifactId", artifact)
depNode.appendNode("version", version)
depNode.appendNode("scope", "compile")
}
}
@ -45,22 +87,25 @@ def includeCompile(str) {
}
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
includeCompile("com.flowpowered:flow-math:1.0.3")
includeCompile("org.jgrapht:jgrapht-core:1.1.0")
includeCompile("com.github.DimensionalDevelopment:poly2tri.java:0.1.1")
includeCompile("com.github.Waterpicker:OpenWorlds:c5a1ced")
includeCompile("io.github.boogiemonster1o1:libcbe:1.1.0")
includeCompile("io.github.cottonmc:LibGui:3.3.2+1.16.4")
includeCompile("me.shedaniel.cloth:config-2:4.8.3")
includeCompile("io.github.onyxstudios:Cardinal-Components-API:2.7.10")
minecraft "com.mojang:minecraft:1.16.5"
mappings "net.fabricmc:yarn:1.16.5+build.3:v2"
modImplementation "net.fabricmc:fabric-loader:0.11.0"
modImplementation "net.fabricmc.fabric-api:fabric-api:0.30.0+1.16"
includeCompile("com.flowpowered", "flow-math", "1.0.3")
includeCompile("org.jgrapht", "jgrapht-core", "1.1.0")
includeCompile("com.github.DimensionalDevelopment", "poly2tri.java", "0.1.1")
includeCompile("com.github.Waterpicker", "OpenWorlds", "c5a1ced")
includeCompile("io.github.boogiemonster1o1", "libcbe", "1.1.0")
includeCompile("io.github.cottonmc", "LibGui", "3.3.2+1.16.4")
includeCompile("me.shedaniel.cloth", "config-2", "4.8.3")
includeCompile("io.github.onyxstudios", "Cardinal-Components-API", "2.7.10")
includeCompile("me.sargunvohra.mcmods", "autoconfig1u", "3.3.1")
// TODO: Add project id
// modImplementation("curse.maven:worldedit:3039223") // For saving schematics
// modImplementation("curse.maven:wecui:2995033") // Cos why not
modRuntime "curse.maven:Worldedit-225608:3039223" // For saving schematics
modRuntime "curse.maven:wecui-402098:3169571" // Cos why not
modCompileOnly "curse.maven:Hwyla-253449:3033613"
modRuntime "curse.maven:Hwyla-253449:3033613"
modCompileOnly("io.github.prospector:modmenu:1.14.6+build.31") {
exclude module: "fabric-api"
}
@ -69,15 +114,15 @@ dependencies {
}
}
version "4.0.0+alpha.4"
archivesBaseName = "dimensional-doors"
version "4.0.0+alpha.5"
archivesBaseName = "DimensionalDoors"
sourceSets {
main {
java {
srcDir 'src/main/schematics'
srcDir 'src/main/registry'
srcDir 'src/main/config'
srcDir "src/main/schematics"
srcDir "src/main/registry"
srcDir "src/main/config"
}
}
}

View file

@ -2,6 +2,7 @@ package org.dimdev.dimdoors;
import java.io.IOException;
import me.sargunvohra.mcmods.autoconfig1u.ConfigHolder;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.block.entity.ModBlockEntityTypes;
import org.dimdev.dimdoors.command.ModCommands;
@ -36,6 +37,8 @@ import net.fabricmc.loader.api.FabricLoader;
public class DimensionalDoorsInitializer implements ModInitializer {
public static final Identifier MONOLITH_PARTICLE_PACKET = new Identifier("dimdoors", "monolith_particle_packet");
public static ConfigHolder<ModConfig> CONFIG_MANAGER;
public static ModConfig CONFIG;
private static MinecraftServer server;
@ -76,8 +79,7 @@ public class DimensionalDoorsInitializer implements ModInitializer {
ModFluids.init();
ModSoundEvents.init();
ModParticleTypes.init();
ModConfig.deserialize();
ModConfig.init();
Targets.registerDefaultTargets();
VirtualTarget.VirtualTargetType.register();

View file

@ -1,72 +1,40 @@
package org.dimdev.dimdoors;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.LinkedList;
import java.util.List;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParser;
import com.mojang.serialization.Codec;
import com.mojang.serialization.JsonOps;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.client.util.Category;
import org.dimdev.dimdoors.client.util.Expose;
import org.dimdev.dimdoors.client.util.Private;
import org.dimdev.dimdoors.client.util.IntSet;
import org.dimdev.dimdoors.client.util.RequiresRestart;
import org.dimdev.dimdoors.client.util.Title;
import org.dimdev.dimdoors.util.Codecs;
import org.dimdev.dimdoors.world.limbo.LimboDecay;
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
import me.sargunvohra.mcmods.autoconfig1u.ConfigData;
import me.sargunvohra.mcmods.autoconfig1u.annotation.Config;
import me.sargunvohra.mcmods.autoconfig1u.annotation.ConfigEntry.Category;
import me.sargunvohra.mcmods.autoconfig1u.annotation.ConfigEntry.Gui.RequiresRestart;
import me.sargunvohra.mcmods.autoconfig1u.annotation.ConfigEntry.Gui.TransitiveObject;
import me.sargunvohra.mcmods.autoconfig1u.serializer.JanksonConfigSerializer;
import net.fabricmc.loader.api.FabricLoader;
@Title("dimdoors.config.title")
public final class ModConfig {
public static ModConfig INSTANCE;
private static final Path CONFIG_PATH;
private static final Gson GSON;
private static final Codec<ModConfig> CODEC;
private static final String DEFAULT;
private static final ModConfig FALLBACK;
private static final Logger LOGGER;
@Category
@Private
private final General general;
@Category
@Private
private final Pockets pockets;
@Category
@Private
private final World world;
@Category
@Private
private final Dungeons dungeons;
@Category
@Private
private final Monoliths monoliths;
@Category
@Private
private final Limbo limbo;
@Category
@Private
private final Graphics graphics;
private ModConfig(General general, Pockets pockets, World world, Dungeons dungeons, Monoliths monoliths, Limbo limbo, Graphics graphics) {
this.general = general;
this.pockets = pockets;
this.world = world;
this.dungeons = dungeons;
this.monoliths = monoliths;
this.limbo = limbo;
this.graphics = graphics;
}
@SuppressWarnings("FieldMayBeFinal")
@Config(name = "dimdoors")
public final class ModConfig implements ConfigData {
@TransitiveObject
@Category("general")
private General general = new General();
@TransitiveObject
@Category("pockets")
private Pockets pockets = new Pockets();
@TransitiveObject
@Category("world")
private World world = new World();
@TransitiveObject
@Category("dungeons")
private Dungeons dungeons = new Dungeons();
@TransitiveObject
@Category("monoliths")
private Monoliths monoliths = new Monoliths();
@TransitiveObject
@Category("limbo")
private Limbo limbo = new Limbo();
@TransitiveObject
@Category("graphics")
private Graphics graphics = new Graphics();
public General getGeneralConfig() {
return this.general;
@ -97,257 +65,64 @@ public final class ModConfig {
}
public static class General {
public static final Codec<General> CODEC = RecordCodecBuilder.create((instance) -> instance.group(
Codec.BOOL.fieldOf("closeDoorBehind").forGetter((general) -> general.closeDoorBehind),
Codec.DOUBLE.fieldOf("teleportOffset").forGetter((general) -> general.teleportOffset),
Codec.BOOL.fieldOf("riftBoundingBoxInCreative").forGetter((general) -> general.riftBoundingBoxInCreative),
Codec.DOUBLE.fieldOf("riftCloseSpeed").forGetter((general) -> general.riftCloseSpeed),
Codec.DOUBLE.fieldOf("riftGrowthSpeed").forGetter((general) -> general.riftGrowthSpeed),
Codec.INT.fieldOf("depthSpreadFactor").forGetter((general) -> general.depthSpreadFactor),
Codec.BOOL.fieldOf("useEnderPearlsInCrafting").forGetter((general) -> general.useEnderPearlsInCrafting),
Codec.DOUBLE.fieldOf("endermanSpawnChance").forGetter((general) -> general.endermanSpawnChance),
Codec.DOUBLE.fieldOf("endermanAggressiveChance").forGetter((general) -> general.endermanAggressiveChance)
).apply(instance, General::create));
@Expose
public boolean closeDoorBehind = false;
@Expose
public double teleportOffset = 0.5;
@Expose
public boolean riftBoundingBoxInCreative;
@Expose
public double riftCloseSpeed = 0.005;
@Expose
public double riftGrowthSpeed = 1;
@Expose
public int depthSpreadFactor = 20;
@RequiresRestart
@Expose
public boolean useEnderPearlsInCrafting = false;
@Expose
public double endermanSpawnChance = 0.001;
@Expose
public double endermanAggressiveChance = 0.5;
public static General create(boolean closeDoorBehind, double teleportOffset, boolean riftBoundingBoxInCreative, double riftCloseSpeed, double riftGrowthSpeed, int depthSpreadFactor, boolean useEnderPearlsInCrafting, double endermanSpawnChance, double endermanAggressiveChance) {
General general = new General();
general.closeDoorBehind = closeDoorBehind;
general.teleportOffset = teleportOffset;
general.riftBoundingBoxInCreative = riftBoundingBoxInCreative;
general.riftCloseSpeed = riftCloseSpeed;
general.riftGrowthSpeed = riftGrowthSpeed;
general.depthSpreadFactor = depthSpreadFactor;
general.useEnderPearlsInCrafting = useEnderPearlsInCrafting;
general.endermanSpawnChance = endermanSpawnChance;
general.endermanAggressiveChance = endermanAggressiveChance;
return general;
}
}
public static class Pockets {
public static final Codec<Pockets> CODEC = RecordCodecBuilder.create((instance) -> instance.group(
Codec.INT.fieldOf("pocketGridSize").forGetter((pockets) -> pockets.pocketGridSize),
Codec.INT.fieldOf("maxPocketSize").forGetter((pockets) -> pockets.maxPocketSize),
Codec.INT.fieldOf("privatePocketSize").forGetter((pockets) -> pockets.privatePocketSize),
Codec.INT.fieldOf("publicPocketSize").forGetter((pockets) -> pockets.publicPocketSize),
Codec.BOOL.fieldOf("loadAllSchematics").forGetter((pockets) -> pockets.loadAllSchematics),
Codec.INT.fieldOf("cachedSchematics").forGetter((pockets) -> pockets.cachedSchematics)
).apply(instance, Pockets::create));
@Expose
public int pocketGridSize = 32;
@Expose
public int maxPocketSize = 15;
@Expose
public int privatePocketSize = 2;
@Expose
public int publicPocketSize = 1;
@RequiresRestart
@Expose
public boolean loadAllSchematics = false;
@RequiresRestart
@Expose
public int cachedSchematics = 10;
public static Pockets create(int pocketGridSize, int maxPocketSize, int privatePocketSize, int publicPocketSize, boolean loadAllSchematics, int cachedSchematics) {
Pockets pockets = new Pockets();
pockets.pocketGridSize = pocketGridSize;
pockets.maxPocketSize = maxPocketSize;
pockets.privatePocketSize = privatePocketSize;
pockets.publicPocketSize = publicPocketSize;
pockets.loadAllSchematics = loadAllSchematics;
pockets.cachedSchematics = cachedSchematics;
return pockets;
}
}
public static class World {
public static final Codec<World> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.DOUBLE.fieldOf("clusterGenChance").forGetter((world) -> world.clusterGenChance),
Codec.INT.fieldOf("gatewayGenChance").forGetter((world) -> world.gatewayGenChance),
Codecs.INT_SET.fieldOf("clusterDimBlacklist").forGetter((world) -> world.clusterDimBlacklist),
Codecs.INT_SET.fieldOf("gatewayDimBlacklist").forGetter((world) -> world.gatewayDimBlacklist)
).apply(instance, World::create));
@RequiresRestart
@Expose
public double clusterGenChance = 0.0002;
@RequiresRestart
@Expose
public int gatewayGenChance = 200;
@IntSet
@RequiresRestart
@Expose
public Set<Integer> clusterDimBlacklist = new LinkedHashSet<>();
@IntSet
public List<Integer> clusterDimBlacklist = new LinkedList<>();
@RequiresRestart
@Expose
public Set<Integer> gatewayDimBlacklist = new LinkedHashSet<>();
public static World create(double clusterGenChance, int gatewayGenChance, Set<Integer> clusterDimBlacklist, Set<Integer> gatewayDimBlacklist) {
World world = new World();
world.clusterGenChance = clusterGenChance;
world.gatewayGenChance = gatewayGenChance;
world.clusterDimBlacklist = clusterDimBlacklist;
world.gatewayDimBlacklist = gatewayDimBlacklist;
return world;
}
public List<Integer> gatewayDimBlacklist = new LinkedList<>();
}
public static class Dungeons {
public static final Codec<Dungeons> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.INT.fieldOf("maxDungeonDepth").forGetter((dungeons) -> dungeons.maxDungeonDepth)
).apply(instance, Dungeons::create));
@Expose
public int maxDungeonDepth = 50;
public static Dungeons create(int maxDungeonDepth) {
Dungeons dungeons = new Dungeons();
dungeons.maxDungeonDepth = maxDungeonDepth;
return dungeons;
}
}
public static class Monoliths {
public static final Codec<Monoliths> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.BOOL.fieldOf("dangerousLimboMonoliths").forGetter((monoliths) -> monoliths.dangerousLimboMonoliths),
Codec.BOOL.fieldOf("monolithTeleportation").forGetter((monoliths) -> monoliths.monolithTeleportation)
).apply(instance, Monoliths::create));
@Expose
public boolean dangerousLimboMonoliths = false;
@Expose
public boolean monolithTeleportation = true;
public static Monoliths create(boolean dangerousLimboMonoliths, boolean monolithTeleportation) {
Monoliths monoliths = new Monoliths();
monoliths.dangerousLimboMonoliths = dangerousLimboMonoliths;
monoliths.monolithTeleportation = monolithTeleportation;
return monoliths;
}
}
public static class Limbo {
public static final Codec<Limbo> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.BOOL.fieldOf("universalLimbo").forGetter((limbo) -> limbo.universalLimbo),
Codec.BOOL.fieldOf("hardcoreLimbo").forGetter((limbo) -> limbo.hardcoreLimbo),
Codec.DOUBLE.fieldOf("decaySpreadChance").forGetter((limbo) -> limbo.decaySpreadChance)
).apply(instance, Limbo::create));
@Expose
public boolean universalLimbo = false;
@Expose
public boolean hardcoreLimbo = false;
@Expose
public double decaySpreadChance = 0.5;
public static Limbo create(boolean universalLimbo, boolean hardcoreLimbo, double decaySpreadChance) {
Limbo limbo = new Limbo();
limbo.universalLimbo = universalLimbo;
limbo.hardcoreLimbo = hardcoreLimbo;
limbo.decaySpreadChance = decaySpreadChance;
return limbo;
}
}
public static class Graphics {
public static final Codec<Graphics> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.BOOL.fieldOf("showRiftCore").forGetter((graphics) -> graphics.showRiftCore),
Codec.INT.fieldOf("highlightRiftCoreFor").forGetter((graphics) -> graphics.highlightRiftCoreFor),
Codec.DOUBLE.fieldOf("riftSize").forGetter((graphics) -> graphics.riftSize),
Codec.DOUBLE.fieldOf("riftJitter").forGetter((graphics) -> graphics.riftJitter)
).apply(instance, Graphics::create));
@Expose
public boolean showRiftCore = false;
@Expose
public int highlightRiftCoreFor = 15000;
@Expose
public double riftSize = 1;
@Expose
public double riftJitter = 1;
public static Graphics create(boolean showRiftCore, int highlightRiftCoreFor, double riftSize, double riftJitter) {
Graphics graphics = new Graphics();
graphics.showRiftCore = showRiftCore;
graphics.highlightRiftCoreFor = highlightRiftCoreFor;
graphics.riftSize = riftSize;
graphics.riftJitter = riftJitter;
return graphics;
}
}
public static void serialize() {
try {
Files.write(CONFIG_PATH, GSON.toJson(CODEC.encodeStart(JsonOps.INSTANCE, INSTANCE).getOrThrow(false, System.err::println)).getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
LOGGER.error("An Unexpected error occured when serializing the Config", e);
}
}
public static int deserialize() {
LimboDecay.init();
try {
if (Files.isDirectory(CONFIG_PATH)) {
Files.delete(CONFIG_PATH);
}
if (!Files.exists(CONFIG_PATH)) {
Files.createFile(CONFIG_PATH);
Files.write(CONFIG_PATH, DEFAULT.getBytes(StandardCharsets.UTF_8));
}
INSTANCE = CODEC.decode(
JsonOps.INSTANCE, new JsonParser().parse(
new InputStreamReader(
Files.newInputStream(CONFIG_PATH)
)
).getAsJsonObject()
).getOrThrow(false, System.err::println).getFirst();
return 1;
} catch (IOException e) {
LOGGER.error("An Unexpected error occured when deserializing the Config. Using default values", e);
INSTANCE = FALLBACK;
return -1;
}
}
static {
CODEC = RecordCodecBuilder.create(instance -> instance.group(
General.CODEC.fieldOf("general").forGetter(ModConfig::getGeneralConfig),
Pockets.CODEC.fieldOf("pockets").forGetter(ModConfig::getPocketsConfig),
World.CODEC.fieldOf("world").forGetter(ModConfig::getWorldConfig),
Dungeons.CODEC.fieldOf("dungeons").forGetter(ModConfig::getDungeonsConfig),
Monoliths.CODEC.fieldOf("monoliths").forGetter(ModConfig::getMonolithsConfig),
Limbo.CODEC.fieldOf("limbo").forGetter(ModConfig::getLimboConfig),
Graphics.CODEC.fieldOf("graphics").forGetter(ModConfig::getGraphicsConfig)
).apply(instance, ModConfig::new));
CONFIG_PATH = FabricLoader.getInstance().getConfigDir().resolve("dimensional_doors.json");
GSON = new GsonBuilder().setLenient().setPrettyPrinting().create();
FALLBACK = new ModConfig(
new General(),
new Pockets(),
new World(),
new Dungeons(),
new Monoliths(),
new Limbo(),
new Graphics()
);
INSTANCE = FALLBACK;
DEFAULT = GSON.toJson(CODEC.encodeStart(JsonOps.INSTANCE, INSTANCE).getOrThrow(false, System.err::println));
LOGGER = LogManager.getLogger(ModConfig.class);
public static void init() {
DimensionalDoorsInitializer.CONFIG_MANAGER = AutoConfig.register(ModConfig.class, JanksonConfigSerializer::new);
DimensionalDoorsInitializer.CONFIG = DimensionalDoorsInitializer.CONFIG_MANAGER.getConfig();
}
}

View file

@ -3,23 +3,20 @@ package org.dimdev.dimdoors.block;
import java.util.Random;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.client.RiftParticle;
import org.dimdev.dimdoors.particle.client.RiftParticle;
import org.dimdev.dimdoors.particle.client.RiftParticleEffect;
import org.dimdev.dimdoors.world.ModDimensions;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.MaterialColor;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@ -41,17 +38,6 @@ public class DetachedRiftBlock extends Block implements RiftProvider<DetachedRif
return MaterialColor.BLACK;
}
@Override
public void onBroken(WorldAccess world, BlockPos pos, BlockState state) {
((DetachedRiftBlockEntity) world.getBlockEntity(pos)).unregister();
super.onBroken(world, pos, state);
}
@Override
public VoxelShape getOutlineShape(BlockState blockState, BlockView blockView, BlockPos blockPos, ShapeContext entityContext) {
return VoxelShapes.empty();
}
@Override
public DetachedRiftBlockEntity getRift(World world, BlockPos pos, BlockState state) {
return (DetachedRiftBlockEntity) world.getBlockEntity(pos);
@ -66,25 +52,27 @@ public class DetachedRiftBlock extends Block implements RiftProvider<DetachedRif
DetachedRiftBlockEntity rift = (DetachedRiftBlockEntity) blockEntity;
boolean outsidePocket = !ModDimensions.isPocketDimension(world);
double speed = 0.1D;
double speed = 0.1;
if (rift.closing) {
MinecraftClient.getInstance().particleManager.addParticle(
new RiftParticle(
(ClientWorld) world,
pos.getX() + .5, pos.getY() + 1.5, pos.getZ() + .5,
rand.nextGaussian() * speed, rand.nextGaussian() * speed, rand.nextGaussian() * speed,
outsidePocket ? 0.8f : 0.4f, 0.55f, 2000, 2000
)
world.addParticle(RiftParticleEffect.of(outsidePocket),
pos.getX() + .5,
pos.getY() + .5,
pos.getZ() + .5,
rand.nextGaussian() * speed,
rand.nextGaussian() * speed,
rand.nextGaussian() * speed
);
}
/*MinecraftClient.getInstance().particleManager.addParticle(new RiftParticle(
(ClientWorld) world,
pos.getX() + .5, pos.getY() + 1.5, pos.getZ() + .5,
rand.nextGaussian() * speed, rand.nextGaussian() * speed, rand.nextGaussian() * speed,
outsidePocket ? 0.0f : 0.7f, 0.55f, rift.stabilized ? 750 : 2000, rift.stabilized ? 750 : 2000)
);*/
world.addParticle(RiftParticleEffect.of(outsidePocket, rift.stabilized),
pos.getX() + .5,
pos.getY() + .5,
pos.getZ() + .5,
rand.nextGaussian() * speed,
rand.nextGaussian() * speed,
rand.nextGaussian() * speed
);
}
@Override

View file

@ -1,6 +1,7 @@
package org.dimdev.dimdoors.block;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.block.entity.EntranceRiftBlockEntity;
import org.dimdev.dimdoors.util.TeleportUtil;
import org.dimdev.dimdoors.world.ModDimensions;
@ -8,15 +9,25 @@ import org.dimdev.dimdoors.world.ModDimensions;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.DoorBlock;
import net.minecraft.block.HorizontalFacingBlock;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.enums.DoubleBlockHalf;
import net.minecraft.entity.Entity;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
public class DimensionalPortalBlock extends Block implements RiftProvider<EntranceRiftBlockEntity> {
public static DirectionProperty FACING = HorizontalFacingBlock.FACING;
public DimensionalPortalBlock(Settings settings) {
super(settings);
setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH));
}
@Override
@ -39,9 +50,24 @@ public class DimensionalPortalBlock extends Block implements RiftProvider<Entran
if (world.isClient) {
return;
}
if (ModDimensions.isLimboDimension(entity.getEntityWorld())) {
TeleportUtil.teleport(entity, DimensionalDoorsInitializer.getWorld(World.OVERWORLD), entity.getPos().subtract(0, entity.getPos().y, 0).add(0, 384, 0), 0);
this.getRift(world, pos, state).teleport(entity);
EntranceRiftBlockEntity rift = getRift(world, pos, state);
world.setBlockState(pos, ModBlocks.DETACHED_RIFT.getDefaultState());
((DetachedRiftBlockEntity) world.getBlockEntity(pos)).setData(rift.getData());
}
super.onEntityCollision(state, world, pos, entity);
public BlockState rotate(BlockState state, BlockRotation rotation) {
return (BlockState)state.with(FACING, rotation.rotate((Direction)state.get(FACING)));
}
public BlockState mirror(BlockState state, BlockMirror mirror) {
return state.rotate(mirror.getRotation((Direction)state.get(FACING)));
}
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACING);
}
}

View file

@ -31,7 +31,7 @@ public final class ModBlocks {
public static final Block OAK_DIMENSIONAL_TRAPDOOR = register("dimdoors:wood_dimensional_trapdoor", new DimensionalTrapdoorBlock(FabricBlockSettings.of(Material.WOOD, MaterialColor.WOOD).nonOpaque()));
public static final Block DIMENSIONAL_PORTAL = register("dimdoors:dimensional_portal", new DimensionalPortalBlock(FabricBlockSettings.of(Material.AIR).collidable(false).nonOpaque().dropsNothing().lightLevel(10)));
public static final Block DETACHED_RIFT = register("dimdoors:detached_rift", new DetachedRiftBlock(FabricBlockSettings.of(Material.AIR).nonOpaque()));
public static final Block DETACHED_RIFT = register("dimdoors:detached_rift", new DetachedRiftBlock(FabricBlockSettings.of(Material.AIR).noCollision().nonOpaque()));
public static final Block WHITE_FABRIC = registerFabric("dimdoors:white_fabric", DyeColor.WHITE);
public static final Block ORANGE_FABRIC = registerFabric("dimdoors:orange_fabric", DyeColor.ORANGE);

View file

@ -2,7 +2,7 @@ package org.dimdev.dimdoors.block.entity;
import java.util.Random;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.util.TeleportUtil;
@ -13,7 +13,6 @@ import net.minecraft.entity.mob.EndermanEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Tickable;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@ -47,10 +46,10 @@ public class DetachedRiftBlockEntity extends RiftBlockEntity implements Tickable
return;
}
if (!this.world.isClient() && random.nextDouble() < ModConfig.INSTANCE.getGeneralConfig().endermanSpawnChance) {
if (!this.world.isClient() && random.nextDouble() < DimensionalDoorsInitializer.CONFIG.getGeneralConfig().endermanSpawnChance) {
EndermanEntity enderman = EntityType.ENDERMAN.spawn((ServerWorld) this.world, null, null, null, this.pos, SpawnReason.STRUCTURE, false, false);
if (random.nextDouble() < ModConfig.INSTANCE.getGeneralConfig().endermanAggressiveChance) {
if (random.nextDouble() < DimensionalDoorsInitializer.CONFIG.getGeneralConfig().endermanAggressiveChance) {
if (enderman != null) {
enderman.setTarget(this.world.getClosestPlayer(enderman, 50));
}
@ -59,12 +58,12 @@ public class DetachedRiftBlockEntity extends RiftBlockEntity implements Tickable
if (this.closing) {
if (this.size > 0) {
this.size -= ModConfig.INSTANCE.getGeneralConfig().riftCloseSpeed;
this.size -= DimensionalDoorsInitializer.CONFIG.getGeneralConfig().riftCloseSpeed;
} else {
this.world.removeBlock(this.pos, false);
}
} else if (!this.stabilized) {
this.size += ModConfig.INSTANCE.getGeneralConfig().riftGrowthSpeed / (this.size + 1);
this.size += DimensionalDoorsInitializer.CONFIG.getGeneralConfig().riftGrowthSpeed / (this.size + 1);
}
}

View file

@ -2,7 +2,7 @@ package org.dimdev.dimdoors.block.entity;
import java.util.Optional;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.util.TeleportUtil;
import net.minecraft.block.BlockState;
@ -42,7 +42,7 @@ public class EntranceRiftBlockEntity extends RiftBlockEntity {
@Override
public boolean receiveEntity(Entity entity, float yawOffset) {
Vec3d targetPos = Vec3d.ofCenter(this.pos).add(Vec3d.of(this.getOrientation().getOpposite().getVector()).multiply(ModConfig.INSTANCE.getGeneralConfig().teleportOffset + 0.5));
Vec3d targetPos = Vec3d.ofCenter(this.pos).add(Vec3d.of(this.getOrientation().getOpposite().getVector()).multiply(DimensionalDoorsInitializer.CONFIG.getGeneralConfig().teleportOffset + 0.5));
TeleportUtil.teleport(entity, this.world, targetPos, yawOffset);
return true;
}

View file

@ -3,7 +3,7 @@ package org.dimdev.dimdoors.client;
import java.util.Objects;
import com.flowpowered.math.TrigMath;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.client.tesseract.Tesseract;
@ -15,7 +15,6 @@ import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Matrix4f;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@ -34,7 +33,7 @@ public class DetachedRiftBlockEntityRenderer extends BlockEntityRenderer<Detache
@Override
public void render(DetachedRiftBlockEntity rift, float tickDelta, MatrixStack matrices, VertexConsumerProvider vcs, int breakProgress, int alpha) {
if (ModConfig.INSTANCE.getGraphicsConfig().showRiftCore) {
if (DimensionalDoorsInitializer.CONFIG.getGraphicsConfig().showRiftCore) {
this.renderTesseract(vcs.getBuffer(MyRenderLayer.TESSERACT), rift, matrices, tickDelta);
} else {
long timeLeft = RiftBlockEntity.showRiftCoreUntil - System.currentTimeMillis();
@ -49,7 +48,7 @@ public class DetachedRiftBlockEntityRenderer extends BlockEntityRenderer<Detache
private void renderCrack(VertexConsumer vc, MatrixStack matrices, DetachedRiftBlockEntity rift) {
matrices.push();
matrices.translate(0.5, 0.5, 0.5);
RiftCrackRenderer.drawCrack(matrices.peek().getModel(), vc, 0, CURVE, ModConfig.INSTANCE.getGraphicsConfig().riftSize * rift.size, 0xF1234568L * rift.getPos().hashCode());
RiftCrackRenderer.drawCrack(matrices.peek().getModel(), vc, 0, CURVE, ModConfig.INSTANCE.getGraphicsConfig().riftSize * rift.size / 150, 0);//0xF1234568L * rift.hashCode());
matrices.pop();
}

View file

@ -15,12 +15,11 @@ public class MonolithModel extends EntityModel<MonolithEntity> {
private final ModelPart body;
public MonolithModel() {
this.textureWidth = 256;
this.textureHeight = 256;
this.body = new ModelPart(this);
this.body.setPivot(0.0F, 0.0F, 0.0F);
this.body.setTextureOffset(0, 0).addCuboid(-24.0F, -108.0F, -6.0F, 48.0F, 108.0F, 12.0F, 0.0F, false);
textureWidth = 102;
textureHeight = 51;
body = new ModelPart(this);
body.setPivot(0.0F, 24.0F, 0.0F);
body.setTextureOffset(1, 1).addCuboid(-23.5F, -23.5F, 0.0F, 49.0F, 49.0F, 1.0F, 0.0F, false);
}
@Override

View file

@ -1,19 +1,27 @@
package org.dimdev.dimdoors.client;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.dimdev.dimdoors.entity.MonolithEntity;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderPhase;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.LivingEntityRenderer;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.util.Identifier;
import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry;
import org.jetbrains.annotations.Nullable;
public class MonolithRenderer extends LivingEntityRenderer<MonolithEntity, MonolithModel> {
public static final List<Identifier> MONOLITH_TEXTURES = ImmutableList.of(
public static final List<RenderLayer> MONOLITH_TEXTURES = Stream.of(
new Identifier("dimdoors:textures/mob/monolith/monolith0.png"),
new Identifier("dimdoors:textures/mob/monolith/monolith1.png"),
new Identifier("dimdoors:textures/mob/monolith/monolith2.png"),
@ -32,19 +40,21 @@ public class MonolithRenderer extends LivingEntityRenderer<MonolithEntity, Monol
new Identifier("dimdoors:textures/mob/monolith/monolith15.png"),
new Identifier("dimdoors:textures/mob/monolith/monolith16.png"),
new Identifier("dimdoors:textures/mob/monolith/monolith17.png"),
new Identifier("dimdoors:textures/mob/monolith/monolith18.png"));
new Identifier("dimdoors:textures/mob/monolith/monolith18.png")
).map(MyRenderLayer::getMonolith).collect(Collectors.toList());
public MonolithRenderer(EntityRenderDispatcher dispatcher, EntityRendererRegistry.Context context) {
super(dispatcher, new MonolithModel(), 0);
}
@Nullable
@Override
protected boolean isShaking(MonolithEntity entity) {
return entity.getAggro() > 120;
protected RenderLayer getRenderLayer(MonolithEntity entity, boolean showBody, boolean translucent, boolean showOutline) {
return MonolithRenderer.MONOLITH_TEXTURES.get(entity.getTextureState());
}
@Override
public Identifier getTexture(MonolithEntity entity) {
return MONOLITH_TEXTURES.get(entity.getTextureState());
return null;
}
}

View file

@ -92,4 +92,9 @@ public class MyRenderLayer extends RenderLayer {
.build(false)
);
}
public static RenderLayer getMonolith(Identifier texture) {
RenderLayer.MultiPhaseParameters multiPhaseParameters = RenderLayer.MultiPhaseParameters.builder().texture(new RenderPhase.Texture(texture, false, false)).transparency(RenderPhase.TRANSLUCENT_TRANSPARENCY).diffuseLighting(RenderPhase.ENABLE_DIFFUSE_LIGHTING).alpha(RenderPhase.ONE_TENTH_ALPHA).cull(DISABLE_CULLING).lightmap(ENABLE_LIGHTMAP).depthTest(RenderPhase.ALWAYS_DEPTH_TEST).overlay(ENABLE_OVERLAY_COLOR).build(false);
return RenderLayer.of("monolith", VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL, 7, 256, true, true, multiPhaseParameters);
}
}

View file

@ -1,8 +1,10 @@
package org.dimdev.dimdoors.client;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.util.Util;
import net.minecraft.util.math.Matrix4f;
import net.fabricmc.api.EnvType;
@ -14,42 +16,44 @@ public final class RiftCrackRenderer {
// Calculate the proper size for the rift render
double scale = size / (poly.maxX - poly.minX);
// Calculate the midpoint of the fractal's bounding box
// Calculate the midpoint of the fractal bounding box
double offsetX = (poly.maxX + poly.minX) / 2d;
double offsetY = (poly.maxY + poly.minY) / 2d;
double offsetZ = 0;
// Jitters that make rifts shake
float jitterSpeed = 0.014f; // Changes how quickly the rift jitters
// Changes how far the triangles move
// TODO: Actually seems to control the glow around the rift
float motionMagnitude = 0.6F;
// Calculate jitter like for monoliths, depending x, y and z coordinates to avoid all rifts syncing
float time = (System.currentTimeMillis() + riftRandom) % 2000000;
// Changes how quickly the triangles move
float motionSpeed = 0.014f;
double jitterScale = ModConfig.INSTANCE.getGraphicsConfig().riftJitter * size * size * size / 2000f;
// Number of individual jitter waveforms to generate
// changes how "together" the overall motions are
int jCount = 10;
float time = ((Util.getEpochTimeMs() + riftRandom) % 2000000) * motionSpeed;
double[] jitters = new double[jCount];
double jitterScale = DimensionalDoorsInitializer.CONFIG.getGraphicsConfig().riftJitter * size * size * size / 2000f;
// We use random constants here on purpose just to get different wave forms
double xJitter = jitterScale * Math.sin(1.1f * time * size * jitterSpeed) * Math.sin(0.8f * time * jitterSpeed);
double yJitter = jitterScale * Math.sin(1.2f * time * size * jitterSpeed) * Math.sin(0.9f * time * jitterSpeed);
double zJitter = jitterScale * Math.sin(1.3f * time * size * jitterSpeed) * Math.sin(0.7f * time * jitterSpeed);
double xJitter = jitterScale * Math.sin(1.1f * time*size) * Math.sin(0.8f * time);
double yJitter = jitterScale * Math.sin(1.2f * time*size) * Math.sin(0.9f * time);
double zJitter = jitterScale * Math.sin(1.3f * time*size) * Math.sin(0.7f * time);
// Flutters in the rift's triangles (most noticed in the edges)
float flutterMagnitude = 0.6F; // Changes how far the triangles move
int flutterModulo = 10; // Changes how "together" the overall motions are
float flutterSpeed = 0.014f; // Changes the speed at which the rift flutters
double[] flutters = new double[flutterModulo];
for (int i = 0; i < flutterModulo; i += 1) {
flutters[i] = Math.sin((1F + i / 10F) * time * flutterSpeed) * Math.cos(1F - i / 10F * time * flutterSpeed) * flutterMagnitude;
// generate a series of waveforms
for (int i = 0; i < jCount; i += 1) {
jitters[i] = Math.sin((1F + i / 10F) * time) * Math.cos(1F - i / 10F * time) * motionMagnitude;
}
// Draw the rift
for (RiftCurves.Point p : poly.points) {
// Reduces most overlap between triangles inside the rift's center
int flutterIndex = Math.abs((p.x + p.y) * (p.x + p.y + 1) / 2 + p.y);
int jIndex = Math.abs((p.x + p.y) * (p.x + p.y + 1) / 2 + p.y);
// Apply flutter and jitter
double x = (p.x + flutters[(flutterIndex + 1) % flutterModulo] - offsetX) * Math.cos(Math.toRadians(riftRotation)) - flutters[(flutterIndex + 2) % flutterModulo] * Math.sin(Math.toRadians(riftRotation));
double y = p.y + flutters[flutterIndex % flutterModulo] - offsetY;
double z = (p.x + flutters[(flutterIndex + 2) % flutterModulo] - offsetZ) * Math.sin(Math.toRadians(riftRotation)) + flutters[(flutterIndex + 2) % flutterModulo] * Math.cos(Math.toRadians(riftRotation));
double x = (p.x + jitters[(jIndex + 1) % jCount] - offsetX) * Math.cos(Math.toRadians(riftRotation)) - jitters[(jIndex + 2) % jCount] * Math.sin(Math.toRadians(riftRotation));
double y = p.y + jitters[jIndex % jCount] - offsetY;
double z = (p.x + jitters[(jIndex + 2) % jCount] - offsetZ) * Math.sin(Math.toRadians(riftRotation)) + jitters[(jIndex + 2) % jCount] * Math.cos(Math.toRadians(riftRotation));
// Scale the rift
x *= scale;

View file

@ -1,37 +0,0 @@
package org.dimdev.dimdoors.client;
import java.util.Random;
import net.minecraft.client.particle.AnimatedParticle;
import net.minecraft.client.particle.SpriteProvider;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.world.ClientWorld;
public class RiftParticle extends AnimatedParticle {
public RiftParticle(ClientWorld world, double x, double y, double z, double velocityX, double velocityY, double velocityZ, float color, float scale, int averageAge, int ageSpread) {
super(world, x, y, z, new SpriteProvider() { // TODO: 160, 8
@Override
public Sprite getSprite(int i, int j) {
return null;
}
@Override
public Sprite getSprite(Random random) {
return null;
}
}, 0);
this.velocityX = velocityX;
this.velocityY = velocityY;
this.velocityZ = velocityZ;
scale *= scale;
this.maxAge = averageAge - ageSpread / 2 + this.random.nextInt(ageSpread);
this.setColor(color, color, color);
}
@Override
public void tick() {
this.setColorAlpha(1 - (float) this.age / this.maxAge);
}
}

View file

@ -1,45 +0,0 @@
package org.dimdev.dimdoors.client.config;
import org.dimdev.dimdoors.ModConfig;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.TranslatableText;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@Environment(EnvType.CLIENT)
public class LoadConfigScreen extends Screen {
private final Screen parent;
protected LoadConfigScreen(Screen parent) {
super(new TranslatableText("dimdoors.config.title"));
this.parent = parent;
}
@Override
public void onClose() {
MinecraftClient.getInstance().openScreen(this.getParent());
}
public Screen getParent() {
return this.parent;
}
@Override
protected void init() {
super.init();
this.addButton(new ButtonWidget(10, 10, 100, 20, new TranslatableText("dimdoors.config.screen.reload"), (button) -> {
ModConfig.deserialize();
}));
}
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
this.renderBackgroundTexture(0);
super.render(matrices, mouseX, mouseY, delta);
}
}

View file

@ -2,8 +2,8 @@ package org.dimdev.dimdoors.client.config;
import io.github.prospector.modmenu.api.ConfigScreenFactory;
import io.github.prospector.modmenu.api.ModMenuApi;
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.client.util.ScreenGenerator;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@ -12,6 +12,6 @@ import net.fabricmc.api.Environment;
public class ModMenuImpl implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return screen -> ScreenGenerator.create(screen, ModConfig.INSTANCE, ModConfig::serialize);
return screen -> AutoConfig.getConfigScreen(ModConfig.class, screen).get();
}
}

View file

@ -1,21 +0,0 @@
package org.dimdev.dimdoors.command;
import com.mojang.brigadier.CommandDispatcher;
import org.dimdev.dimdoors.ModConfig;
import net.minecraft.server.command.ServerCommandSource;
import static net.minecraft.server.command.CommandManager.literal;
public class DimdoorsConfigCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(
literal("dimdoorsconfig")
.requires(source -> source.hasPermissionLevel(2))
.then(
literal("load")
.executes(ctx -> ModConfig.deserialize())
)
);
}
}

View file

@ -9,7 +9,6 @@ public final class ModCommands {
PocketCommand.register(dispatcher);
SchematicV2Command.register(dispatcher);
SchematicCommand.register(dispatcher);
DimdoorsConfigCommand.register(dispatcher);
});
}
}

View file

@ -2,7 +2,7 @@ package org.dimdev.dimdoors.entity;
import java.util.Random;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.entity.ai.MonolithAggroGoal;
import org.dimdev.dimdoors.item.ModItems;
import org.dimdev.dimdoors.sound.ModSoundEvents;
@ -33,8 +33,6 @@ import net.minecraft.world.WorldAccess;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.network.PacketContext;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
public class MonolithEntity extends MobEntity {
public final EntityDimensions DIMENSIONS = EntityDimensions.fixed(3f, 6f);
@ -79,7 +77,7 @@ public class MonolithEntity extends MobEntity {
}
public boolean isDangerous() {
return ModConfig.INSTANCE.getMonolithsConfig().monolithTeleportation && (ModDimensions.isLimboDimension(this.world) || ModConfig.INSTANCE.getMonolithsConfig().dangerousLimboMonoliths);
return DimensionalDoorsInitializer.CONFIG.getMonolithsConfig().monolithTeleportation && (ModDimensions.isLimboDimension(this.world) || DimensionalDoorsInitializer.CONFIG.getMonolithsConfig().dangerousLimboMonoliths);
}
@Override

View file

@ -5,7 +5,6 @@ import java.util.Random;
import io.netty.buffer.Unpooled;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.entity.MonolithEntity;
import org.dimdev.dimdoors.item.ModItems;
import org.dimdev.dimdoors.sound.ModSoundEvents;
@ -96,7 +95,7 @@ public class MonolithAggroGoal extends Goal {
}
// Teleport the target player if various conditions are met
if (this.mob.getAggro() >= MAX_AGGRO && ModConfig.INSTANCE.getMonolithsConfig().monolithTeleportation && !this.target.isCreative() && this.mob.isDangerous()) {
if (this.mob.getAggro() >= MAX_AGGRO && DimensionalDoorsInitializer.CONFIG.getMonolithsConfig().monolithTeleportation && !this.target.isCreative() && this.mob.isDangerous()) {
this.mob.setAggro(0);
//Location destination = LimboDimension.getLimboSkySpawn(player);
//TeleportUtil.teleport(player, destination, 0, 0);

View file

@ -2,7 +2,7 @@ package org.dimdev.dimdoors.item;
import java.util.function.Consumer;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.block.RiftProvider;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
@ -44,7 +44,7 @@ public class DimensionalDoorItem extends TallBlockItem {
if (context.getWorld().isClient) {
context.getPlayer().sendMessage(new TranslatableText("rifts.entrances.rift_too_close"), true);
RiftBlockEntity.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.INSTANCE.getGraphicsConfig().highlightRiftCoreFor;
RiftBlockEntity.showRiftCoreUntil = System.currentTimeMillis() + DimensionalDoorsInitializer.CONFIG.getGraphicsConfig().highlightRiftCoreFor;
}
return ActionResult.FAIL;

View file

@ -0,0 +1,40 @@
package org.dimdev.dimdoors.item;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.sound.ModSoundEvents;
public class DimensionalEraser extends Item {
public DimensionalEraser(Settings settings) {
super(settings);
}
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
ItemStack stack = player.getStackInHand(hand);
HitResult hit = RaycastHelper.raycast(player, RaycastHelper.REACH_DISTANCE, 1.0F, a -> !(a instanceof PlayerEntity));
if (hit != null && hit.getType() == HitResult.Type.ENTITY) {
((EntityHitResult) hit).getEntity().remove();
player.playSound(ModSoundEvents.BLOOP, 1.0f, 1.0f);
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
}
return new TypedActionResult<>(ActionResult.FAIL, stack);
}
}

View file

@ -5,6 +5,7 @@ import java.util.Collections;
import java.util.HashSet;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.entity.ModEntityTypes;
import org.dimdev.dimdoors.fluid.ModFluids;
import org.dimdev.dimdoors.rift.registry.LinkProperties;
import org.dimdev.dimdoors.rift.targets.EscapeTarget;
@ -18,6 +19,7 @@ import org.dimdev.dimdoors.util.registry.RegistryObject;
import org.dimdev.dimdoors.world.ModDimensions;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.BlockItem;
@ -26,6 +28,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
@ -145,6 +148,11 @@ public final class ModItems {
@RegistryObject("rift_stabilizer")
public static final Item RIFT_STABILIZER = create(new RiftStabilizerItem(new Item.Settings().maxCount(1).maxDamage(6).group(DIMENSIONAL_DOORS)));
@RegistryObject("dimensional_eraser")
public static final Item DIMENSIONAL_ERASER = create(new DimensionalEraser(new Item.Settings().maxDamage(100).group(DIMENSIONAL_DOORS)));
@RegistryObject("monolith_spawner")
public static final Item MONOLITH_SPAWNER = new SpawnEggItem(ModEntityTypes.MONOLITH, 0xffffff, 0xffffff, new Item.Settings().group(ItemGroup.MISC));
@RegistryObject("world_thread_helmet")
public static final Item WORLD_THREAD_HELMET = create(new ArmorItem(ModArmorMaterials.WORLD_THREAD, EquipmentSlot.HEAD, new Item.Settings().group(DIMENSIONAL_DOORS)));
@ -266,7 +274,7 @@ public final class ModItems {
public static final Item CREEPY_RECORD = create(new MusicDiscItem(10, ModSoundEvents.CREEPY, new Item.Settings().group(DIMENSIONAL_DOORS)));
@RegistryObject("white_void_record")
public static final Item WHITE_VOID_RECORD = create(new MusicDiscItem(10, ModSoundEvents.CREEPY, new Item.Settings().group(DIMENSIONAL_DOORS)));
public static final Item WHITE_VOID_RECORD = create(new MusicDiscItem(10, ModSoundEvents.WHITE_VOID, new Item.Settings().group(DIMENSIONAL_DOORS)));
@RegistryObject("marking_plate")
public static final Item MARKING_PLATE = create(ModBlocks.MARKING_PLATE);

View file

@ -1,13 +1,21 @@
package org.dimdev.dimdoors.item;
import java.util.function.Predicate;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.ProjectileUtil;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.BlockView;
import net.minecraft.world.RaycastContext;
public final class RaycastHelper {
public static final int REACH_DISTANCE = 5;
@ -23,4 +31,12 @@ public final class RaycastHelper {
public static boolean hitsLivingEntity(HitResult hit) {
return hit != null && hit.getType() == HitResult.Type.ENTITY && ((EntityHitResult) hit).getEntity() instanceof LivingEntity;
}
public static HitResult raycast(Entity entity, double maxDistance, float tickDelta, Predicate<Entity> predicate) {
Vec3d vec3d = entity.getCameraPosVec(tickDelta);
Vec3d vec3d2 = entity.getRotationVec(tickDelta);
Vec3d vec3d3 = vec3d.add(vec3d2.x * maxDistance, vec3d2.y * maxDistance, vec3d2.z * maxDistance);
Box box = entity.getBoundingBox().stretch(vec3d2.multiply(maxDistance)).expand(1.0D, 1.0D, 1.0D);
return ProjectileUtil.raycast(entity, vec3d, vec3d3, box, predicate, maxDistance);
}
}

View file

@ -2,9 +2,10 @@ package org.dimdev.dimdoors.item;
import java.util.Objects;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SwordItem;
@ -13,9 +14,11 @@ import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.RaycastContext;
import net.minecraft.world.World;
public class RiftBladeItem extends SwordItem {
@ -39,9 +42,18 @@ public class RiftBladeItem extends SwordItem {
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
ItemStack stack = player.getStackInHand(hand);
HitResult hit = player.raycast(16, 1.0F, false); //TODO: make the range of the Rift Blade configurable
HitResult hit = RaycastHelper.raycast(player,16,0.0F, LivingEntity.class::isInstance);
if(hit == null) {
hit = RaycastHelper.raycast(player, 16, 1.0F, LivingEntity.class::isInstance);
}
if(hit == null) {
hit = player.raycast(16, 1.0F, false); //TODO: make the range of the Rift Blade configurable
}
if (hit == null) {
hit = player.raycast(RaycastHelper.REACH_DISTANCE, 0, false);
hit = player.raycast(16, 0, false);
}
if (world.isClient) {
@ -49,7 +61,7 @@ public class RiftBladeItem extends SwordItem {
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
} else {
player.sendMessage(new TranslatableText(this.getTranslationKey() + ".rift_miss"), true);
RiftBlockEntity.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.INSTANCE.getGraphicsConfig().highlightRiftCoreFor;
RiftBlockEntity.showRiftCoreUntil = System.currentTimeMillis() + DimensionalDoorsInitializer.CONFIG.getGraphicsConfig().highlightRiftCoreFor;
return new TypedActionResult<>(ActionResult.FAIL, stack);
}
}
@ -74,9 +86,13 @@ public class RiftBladeItem extends SwordItem {
stack.damage(1, player, a -> {
});
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
} else if (RaycastHelper.hitsRift(hit, world)) {
RiftBlockEntity rift = (RiftBlockEntity) world.getBlockEntity(new BlockPos(hit.getPos()));
rift.teleport(player);
} else if (RaycastHelper.hitsDetachedRift(hit, world)) {
BlockHitResult blockHitResult = (BlockHitResult) hit;
BlockPos pos = blockHitResult.getBlockPos();
RiftBlockEntity rift = (RiftBlockEntity) world.getBlockEntity(blockHitResult.getBlockPos());
world.setBlockState(pos, ModBlocks.DIMENSIONAL_PORTAL.getDefaultState().with(DimensionalPortalBlock.FACING, blockHitResult.getSide()));
((EntranceRiftBlockEntity) world.getBlockEntity(pos)).setData(rift.getData());
stack.damage(1, player, a -> a.sendToolBreakStatus(hand));
return new TypedActionResult<>(ActionResult.SUCCESS, stack);

View file

@ -2,7 +2,7 @@ package org.dimdev.dimdoors.item;
import java.util.List;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import net.minecraft.client.item.TooltipContext;
@ -39,7 +39,7 @@ public class RiftConfigurationToolItem extends Item {
if (world.isClient) {
if (!RaycastHelper.hitsRift(hit, world)) {
player.sendMessage(new TranslatableText("tools.rift_miss"), true);
RiftBlockEntity.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.INSTANCE.getGraphicsConfig().highlightRiftCoreFor;
RiftBlockEntity.showRiftCoreUntil = System.currentTimeMillis() + DimensionalDoorsInitializer.CONFIG.getGraphicsConfig().highlightRiftCoreFor;
}
return new TypedActionResult<>(ActionResult.FAIL, stack);
}

View file

@ -3,7 +3,7 @@ package org.dimdev.dimdoors.item;
import java.util.List;
import java.util.Objects;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.sound.ModSoundEvents;
@ -47,7 +47,7 @@ public class RiftRemoverItem extends Item {
if (world.isClient) {
if (!RaycastHelper.hitsDetachedRift(hit, world)) {
player.sendMessage(new TranslatableText("tools.rift_miss"), true);
RiftBlockEntity.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.INSTANCE.getGraphicsConfig().highlightRiftCoreFor;
RiftBlockEntity.showRiftCoreUntil = System.currentTimeMillis() + DimensionalDoorsInitializer.CONFIG.getGraphicsConfig().highlightRiftCoreFor;
}
return new TypedActionResult<>(ActionResult.FAIL, stack);
}

View file

@ -2,7 +2,7 @@ package org.dimdev.dimdoors.item;
import java.util.List;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
import org.dimdev.dimdoors.sound.ModSoundEvents;
@ -40,7 +40,7 @@ public class RiftStabilizerItem extends Item {
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
} else {
player.sendMessage(new TranslatableText("tools.rift_miss"), true);
RiftBlockEntity.showRiftCoreUntil = System.currentTimeMillis() + ModConfig.INSTANCE.getGraphicsConfig().highlightRiftCoreFor;
RiftBlockEntity.showRiftCoreUntil = System.currentTimeMillis() + DimensionalDoorsInitializer.CONFIG.getGraphicsConfig().highlightRiftCoreFor;
return new TypedActionResult<>(ActionResult.FAIL, stack);
}
}

View file

@ -1,25 +1,32 @@
package org.dimdev.dimdoors.particle;
import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes;
import org.dimdev.dimdoors.particle.client.RiftParticle;
import org.dimdev.dimdoors.mixin.accessor.DefaultParticleTypeAccessor;
import org.dimdev.dimdoors.particle.client.MonolithParticle;
import net.minecraft.particle.DefaultParticleType;
import net.minecraft.particle.ParticleType;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import org.dimdev.dimdoors.particle.client.RiftParticleEffect;
public class ModParticleTypes {
public static final DefaultParticleType MONOLITH = DefaultParticleTypeAccessor.createDefaultParticleType(true);
public static final DefaultParticleType MONOLITH = FabricParticleTypes.simple(true);
public static final ParticleType<RiftParticleEffect> RIFT = new RiftParticleType();
public static void init() {
Registry.register(Registry.PARTICLE_TYPE, new Identifier("dimdoors", "monolith"), MONOLITH);
Registry.register(Registry.PARTICLE_TYPE, new Identifier("dimdoors", "rift"), RIFT);
}
@Environment(EnvType.CLIENT)
public static void initClient() {
ParticleFactoryRegistry.getInstance().register(MONOLITH, new MonolithParticle.Factory());
ParticleFactoryRegistry.getInstance().register(RIFT, RiftParticle.Factory::new);
}
}

View file

@ -0,0 +1,18 @@
package org.dimdev.dimdoors.particle;
import net.minecraft.particle.ParticleType;
import com.mojang.serialization.Codec;
import org.dimdev.dimdoors.particle.client.RiftParticleEffect;
public class RiftParticleType extends ParticleType<RiftParticleEffect> {
protected RiftParticleType() {
super(true, RiftParticleEffect.PARAMETERS_FACTORY);
}
@Override
public Codec<RiftParticleEffect> getCodec() {
return RiftParticleEffect.CODEC;
}
}

View file

@ -31,7 +31,7 @@ public class MonolithParticle extends Particle {
super(world, x, y, z);
this.maxAge = 30;
this.model = new MonolithModel();
this.layer = RenderLayer.getEntitySolid(MonolithRenderer.MONOLITH_TEXTURES.get(14));
this.layer = MonolithRenderer.MONOLITH_TEXTURES.get(14);
}
@Override

View file

@ -0,0 +1,43 @@
package org.dimdev.dimdoors.particle.client;
import net.minecraft.client.particle.AnimatedParticle;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.ParticleFactory;
import net.minecraft.client.particle.ParticleTextureSheet;
import net.minecraft.client.particle.SpriteProvider;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.particle.DefaultParticleType;
import org.dimdev.dimdoors.particle.RiftParticleType;
public class RiftParticle extends AnimatedParticle {
public RiftParticle(ClientWorld world, double x, double y, double z, double velocityX, double velocityY, double velocityZ, float color, int ageSpread, SpriteProvider spriteProvider) {
super(world, x, y, z, spriteProvider, 0);
this.velocityX = velocityX;
this.velocityY = velocityY;
this.velocityZ = velocityZ;
this.scale *= 0.55f;
this.maxAge = ageSpread - ageSpread / 2 + this.random.nextInt(2000);
this.setColor(color, color, color);
this.setSpriteForAge(spriteProvider);
}
@Override
public ParticleTextureSheet getType() {
return super.getType();
}
public static class Factory implements ParticleFactory<RiftParticleEffect> {
private final SpriteProvider spriteProvider;
public Factory(SpriteProvider spriteProvider) {
this.spriteProvider = spriteProvider;
}
public Particle createParticle(RiftParticleEffect riftParticleEffect, ClientWorld clientWorld, double x, double y, double z, double velocityX, double velocityY, double velocityZ) {
return new RiftParticle(clientWorld, x, y, z, velocityX, velocityY, velocityZ, riftParticleEffect.getColor(), riftParticleEffect.getAverageAge(), this.spriteProvider);
}
}
}

View file

@ -0,0 +1,95 @@
package org.dimdev.dimdoors.particle.client;
import java.util.Locale;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.particle.DustParticleEffect;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleType;
import net.minecraft.util.registry.Registry;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.dimdev.dimdoors.particle.ModParticleTypes;
public class RiftParticleEffect implements ParticleEffect {
public static RiftParticleEffect of(boolean isOutsidePocket) {
return isOutsidePocket ? OUTSIDE : INSIDE;
}
public static RiftParticleEffect of(boolean isOutsidePocket, boolean stablized) {
if (isOutsidePocket) {
if (stablized) {
return OUTSIDE_STABLE;
} else {
return OUTSIDE_UNSTABLE;
}
} else {
if (stablized) {
return INSIDE_STABLE;
} else {
return INSIDE_UNSTABLE;
}
}
}
private static final RiftParticleEffect OUTSIDE = new RiftParticleEffect(0.4f, 2000);
private static final RiftParticleEffect INSIDE = new RiftParticleEffect(0.8f, 2000);
private static final RiftParticleEffect OUTSIDE_UNSTABLE = new RiftParticleEffect(0.0f, 2000);
private static final RiftParticleEffect INSIDE_UNSTABLE = new RiftParticleEffect( 0.7f, 2000);
private static final RiftParticleEffect OUTSIDE_STABLE = new RiftParticleEffect(0.0f, 750);
private static final RiftParticleEffect INSIDE_STABLE = new RiftParticleEffect( 0.7f, 750);
public static final Codec<RiftParticleEffect> CODEC = RecordCodecBuilder.create((instance) -> instance.group(
Codec.FLOAT.fieldOf("color").forGetter(riftParticleEffect -> riftParticleEffect.color),
Codec.INT.fieldOf("averageAge").forGetter((riftParticleEffect) -> riftParticleEffect.averageAge))
.apply(instance, RiftParticleEffect::new));
public static final ParticleEffect.Factory<RiftParticleEffect> PARAMETERS_FACTORY = new ParticleEffect.Factory<RiftParticleEffect>() {
public RiftParticleEffect read(ParticleType<RiftParticleEffect> particleType, StringReader stringReader) throws CommandSyntaxException {
stringReader.expect(' ');
float f = stringReader.readFloat();
stringReader.expect(' ');
int g = stringReader.readInt();
return new RiftParticleEffect(f, g);
}
public RiftParticleEffect read(ParticleType<RiftParticleEffect> particleType, PacketByteBuf packetByteBuf) {
return new RiftParticleEffect(packetByteBuf.readFloat(), packetByteBuf.readInt());
}
};
private final float color;
private final int averageAge;
public RiftParticleEffect(float color, int averageAge) {
this.color = color;
this.averageAge = averageAge;
}
public void write(PacketByteBuf buf) {
buf.writeFloat(this.color);
buf.writeInt(this.averageAge);
}
public String asString() {
return String.format(Locale.ROOT, "%s %.2f %s", Registry.PARTICLE_TYPE.getId(this.getType()), this.color, this.averageAge);
}
public ParticleType<RiftParticleEffect> getType() {
return ModParticleTypes.RIFT;
}
@Environment(EnvType.CLIENT)
public float getColor() {
return color;
}
@Environment(EnvType.CLIENT)
public int getAverageAge() {
return averageAge;
}
}

View file

@ -80,7 +80,7 @@ public final class PocketGenerator {
float netherProbability = DimensionalDoorsInitializer.getWorld(virtualLocation.getWorld()).getDimension().isUltrawarm() ? 1 : (float) depth / 200; // TODO: improve nether probability
Random random = new Random();
String group = random.nextFloat() < netherProbability ? "nether" : "ruins";
PocketTemplate pocketTemplate = SchematicHandler.INSTANCE.getRandomTemplate(group, depth, ModConfig.INSTANCE.getPocketsConfig().maxPocketSize, false);
PocketTemplate pocketTemplate = SchematicHandler.INSTANCE.getRandomTemplate(group, depth, DimensionalDoorsInitializer.CONFIG.getPocketsConfig().maxPocketSize, false);
return generatePocketFromTemplate(DimensionalDoorsInitializer.getWorld(ModDimensions.DUNGEON), pocketTemplate, virtualLocation, linkTo, linkProperties);
}

View file

@ -31,7 +31,6 @@ import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.util.math.MathUtil;
import org.dimdev.dimdoors.util.schematic.Schematic;
@ -221,7 +220,7 @@ public class SchematicHandler { // TODO: parts of this should be moved to the or
for (JsonElement pocketElement : pockets) {
JsonObject pocket = pocketElement.getAsJsonObject();
int size = pocket.get("size").getAsInt();
if (!ModConfig.INSTANCE.getPocketsConfig().loadAllSchematics && size > ModConfig.INSTANCE.getPocketsConfig().maxPocketSize)
if (!DimensionalDoorsInitializer.CONFIG.getPocketsConfig().loadAllSchematics && size > DimensionalDoorsInitializer.CONFIG.getPocketsConfig().maxPocketSize)
continue;
String id = pocket.get("id").getAsString();
String type = pocket.has("type") ? pocket.get("type").getAsString() : null;
@ -320,11 +319,11 @@ public class SchematicHandler { // TODO: parts of this should be moved to the or
}
public PocketTemplate getPersonalPocketTemplate() {
return this.getRandomTemplate("private", -1, ModConfig.INSTANCE.getPocketsConfig().privatePocketSize, true);
return this.getRandomTemplate("private", -1, DimensionalDoorsInitializer.CONFIG.getPocketsConfig().privatePocketSize, true);
}
public PocketTemplate getPublicPocketTemplate() {
return this.getRandomTemplate("public", -1, ModConfig.INSTANCE.getPocketsConfig().publicPocketSize, true);
return this.getRandomTemplate("public", -1, DimensionalDoorsInitializer.CONFIG.getPocketsConfig().publicPocketSize, true);
}
public static void saveSchematic(Schematic schematic, String id) {
@ -392,7 +391,7 @@ public class SchematicHandler { // TODO: parts of this should be moved to the or
}
public boolean isUsedOftenEnough(PocketTemplate template) {
int maxNrOfCachedSchematics = ModConfig.INSTANCE.getPocketsConfig().cachedSchematics;
int maxNrOfCachedSchematics = DimensionalDoorsInitializer.CONFIG.getPocketsConfig().cachedSchematics;
int usageRank = this.usageMap.get(template);
return usageRank < maxNrOfCachedSchematics;
}
@ -421,9 +420,9 @@ public class SchematicHandler { // TODO: parts of this should be moved to the or
this.usageList.set(insertionIndex, new SimpleEntry(template, newUsage));
this.usageMap.put(template, insertionIndex);
if (insertionIndex < ModConfig.INSTANCE.getPocketsConfig().cachedSchematics) { //if the schematic of this template is supposed to get cached
if (this.usageList.size() > ModConfig.INSTANCE.getPocketsConfig().cachedSchematics) { //if there are more used templates than there are schematics allowed to be cached
this.usageList.get(ModConfig.INSTANCE.getPocketsConfig().cachedSchematics).getKey().setSchematic(null); //make sure that the number of cached schematics is limited
if (insertionIndex < DimensionalDoorsInitializer.CONFIG.getPocketsConfig().cachedSchematics) { //if the schematic of this template is supposed to get cached
if (this.usageList.size() > DimensionalDoorsInitializer.CONFIG.getPocketsConfig().cachedSchematics) { //if there are more used templates than there are schematics allowed to be cached
this.usageList.get(DimensionalDoorsInitializer.CONFIG.getPocketsConfig().cachedSchematics).getKey().setSchematic(null); //make sure that the number of cached schematics is limited
}
}
}

View file

@ -19,6 +19,7 @@ public final class ModSoundEvents {
public static final SoundEvent RIFT_START = register("dimdoors:rift_start");
public static final SoundEvent TEARING = register("dimdoors:tearing");
public static final SoundEvent WHITE_VOID = register("dimdoors:white_void");
public static final SoundEvent BLOOP = register("dimdoors:bloop");
private static SoundEvent register(String id) {
return Registry.register(Registry.SOUND_EVENT, id, new SoundEvent(new Identifier(id)));

View file

@ -4,7 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.mixin.accessor.GenerationSettingsAccessor;
import org.dimdev.dimdoors.world.feature.decorator.EternalFluidLakeDecorator;
@ -70,7 +70,7 @@ public final class ModFeatures {
}
static {
int gatewayChance = FabricLoader.getInstance().isDevelopmentEnvironment() ? 20 : ModConfig.INSTANCE.getWorldConfig().gatewayGenChance;
int gatewayChance = FabricLoader.getInstance().isDevelopmentEnvironment() ? 20 : DimensionalDoorsInitializer.CONFIG.getWorldConfig().gatewayGenChance;
SANDSTONE_PILLARS_FEATURE = SCHEMATIC_GATEWAY_FEATURE.configure(new SchematicV2GatewayFeatureConfig(SchematicV2Gateway.ID_SCHEMATIC_MAP.inverse().get(SANDSTONE_PILLARS_GATEWAY))).decorate(ConfiguredFeatures.Decorators.SQUARE_TOP_SOLID_HEIGHTMAP.applyChance(gatewayChance));
TWO_PILLARS_FEATURE = SCHEMATIC_GATEWAY_FEATURE.configure(new SchematicV2GatewayFeatureConfig(SchematicV2Gateway.ID_SCHEMATIC_MAP.inverse().get(TWO_PILLARS_GATEWAY))).decorate(ConfiguredFeatures.Decorators.SQUARE_TOP_SOLID_HEIGHTMAP.applyChance(gatewayChance));
LIMBO_GATEWAY_CONFIGURED_FEATURE = LIMBO_GATEWAY_FEATURE.configure(DefaultFeatureConfig.INSTANCE).decorate(ConfiguredFeatures.Decorators.SQUARE_TOP_SOLID_HEIGHTMAP.applyChance(gatewayChance));

View file

@ -19,7 +19,7 @@ import com.mojang.serialization.JsonOps;
import com.mojang.serialization.codecs.UnboundedMapCodec;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
@ -168,7 +168,7 @@ public final class LimboDecay {
public static void applySpreadDecay(World world, BlockPos pos) {
//Check if we randomly apply decay spread or not. This can be used to moderate the frequency of
//full spread decay checks, which can also shift its performance impact on the game.
if (random.nextDouble() < ModConfig.INSTANCE.getLimboConfig().decaySpreadChance) {
if (random.nextDouble() < DimensionalDoorsInitializer.CONFIG.getLimboConfig().decaySpreadChance) {
//Apply decay to the blocks above, below, and on all four sides.
//World.getBlockId() implements bounds checking, so we don't have to worry about reaching out of the world
boolean flag = decayBlock(world, pos.up());

View file

@ -4,7 +4,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.util.math.GridUtil;
import net.minecraft.nbt.CompoundTag;
@ -23,7 +23,7 @@ public class PocketDirectory {
RegistryKey<World> worldKey;
public PocketDirectory(RegistryKey<World> worldKey) {
this.gridSize = ModConfig.INSTANCE.getPocketsConfig().pocketGridSize;
this.gridSize = DimensionalDoorsInitializer.CONFIG.getPocketsConfig().pocketGridSize;
this.worldKey = worldKey;
this.nextID = 0;
this.pockets = new HashMap<>();

View file

@ -4,7 +4,6 @@ import com.google.common.base.MoreObjects;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.world.level.DimensionalRegistry;
import org.dimdev.dimdoors.util.Location;
import org.dimdev.dimdoors.world.ModDimensions;
@ -71,7 +70,7 @@ public class VirtualLocation {
virtualLocation = null; // TODO: door was placed in a pockets dim but outside of a pockets...
}
} else if (ModDimensions.isLimboDimension(location.getWorld())) { // TODO: convert to interface on worldprovider
virtualLocation = new VirtualLocation(location.world, location.getX(), location.getZ(), ModConfig.INSTANCE.getDungeonsConfig().maxDungeonDepth);
virtualLocation = new VirtualLocation(location.world, location.getX(), location.getZ(), DimensionalDoorsInitializer.CONFIG.getDungeonsConfig().maxDungeonDepth);
} // TODO: nether coordinate transform
if (virtualLocation == null) {
@ -87,7 +86,7 @@ public class VirtualLocation {
world = world.getServer().getWorld(OVERWORLD);
}
float spread = ModConfig.INSTANCE.getGeneralConfig().depthSpreadFactor * this.depth;
float spread = DimensionalDoorsInitializer.CONFIG.getGeneralConfig().depthSpreadFactor * this.depth;
int newX = (int) (this.x + spread * 2 * (Math.random() - 0.5));
int newZ = (int) (this.z + spread * 2 * (Math.random() - 0.5));
BlockPos pos = world.getTopPosition(Heightmap.Type.WORLD_SURFACE, new BlockPos(newX, 0, newZ));

View file

@ -93,6 +93,9 @@
"item.dimdoors.eternal_fluid_bucket": "Eternal Fluid Bucket",
"item.dimdoors.white_void_record": "Music Disc",
"item.dimdoors.white_void_record.desc": "White Void - The sound of Pocket",
"item.dimdoors.dimensional_eraser": "Dimensional Eraser",
"item.dimdoors.dimensional_eraser.desc": "Erases entities",
"item.dimdoors.monolith_spawner": "Monolith Spawner",
"fluid.dimdoors.eternal_fabric": "Eternal Fabric",
"entity.dimdoors.monolith": "",
"commands.dimteleport.usage": "/dimteleport <dimension> <x> <y> <z> [yaw] [pitch]",

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "dimdoors:item/dimensional_eraser"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "dimdoors:item/monolith_spawner"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "dimdoors:item/record_creepy"
}
}

View file

@ -0,0 +1,12 @@
{
"textures": [
"minecraft:glitter_7",
"minecraft:glitter_6",
"minecraft:glitter_5",
"minecraft:glitter_4",
"minecraft:glitter_3",
"minecraft:glitter_2",
"minecraft:glitter_1",
"minecraft:glitter_0"
]
}

View file

@ -12,5 +12,6 @@
"rift_end": { "sounds" : [ "dimdoors:rift_end" ] },
"rift_start": { "sounds" : [ "dimdoors:rift_start" ] },
"tearing": { "sounds" : [ "dimdoors:tearing"] },
"white_void": { "sounds" : [ "dimdoors:white_void"] }
"white_void": { "sounds" : [ "dimdoors:white_void"] },
"bloop": { "sounds" : [ "dimdoors:bloop"]}
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 565 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 457 B

View file

@ -0,0 +1,26 @@
{
"animation": {
"frames": [
{
"index": 0,
"time": 100
},
{
"index": 1,
"time": 2
},
{
"index": 2,
"time": 2
},
{
"index": 3,
"time": 2
},
{
"index": 4,
"time": 2
}
]
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 158 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 914 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 934 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 984 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 379 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 431 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 661 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 721 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 717 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4 KiB

After

Width:  |  Height:  |  Size: 815 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4 KiB

After

Width:  |  Height:  |  Size: 815 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4 KiB

After

Width:  |  Height:  |  Size: 843 B

View file

@ -2,17 +2,14 @@ package org.dimdev.dimdoors.util.schematic.v2;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import io.github.boogiemonster1o1.libcbe.api.ConditionalBlockEntityProvider;
import org.jetbrains.annotations.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
@ -21,7 +18,6 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.fluid.FluidState;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntArrayTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.util.math.BlockPos;
@ -29,23 +25,29 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.BlockView;
import net.minecraft.world.ModifiableWorld;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.biome.Biome;
import net.fabricmc.fabric.api.util.NbtType;
public class RelativeBlockSample implements BlockView, ModifiableWorld {
public final Schematic schematic;
private final int[][][] blockData;
private final int[][] biomeData;
private final BiMap<BlockState, Integer> blockPalette;
private final BiMap<Biome, Integer> biomePalette;
private final Map<BlockPos, BlockState> blockContainer;
private final Map<BlockPos, Biome> biomeContainer;
private final Map<BlockPos, CompoundTag> blockEntityContainer;
private final BiMap<CompoundTag, Vec3d> entityContainer;
private StructureWorldAccess world;
public RelativeBlockSample(Schematic schematic) {
this.schematic = schematic;
this.blockData = SchematicPlacer.getBlockData(schematic);
this.biomeData = SchematicPlacer.getBiomeData(schematic);
this.blockPalette = ImmutableBiMap.copyOf(schematic.getBlockPalette());
this.biomePalette = ImmutableBiMap.copyOf(schematic.getBiomePalette());
this.blockContainer = Maps.newHashMap();
this.biomeContainer = Maps.newHashMap();
this.blockEntityContainer = Maps.newHashMap();
int width = schematic.getWidth();
int height = schematic.getHeight();
@ -54,10 +56,14 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
for (int y = 0; y < height; y++) {
for (int z = 0; z < length; z++) {
this.setBlockState(new BlockPos(x, y, z), this.blockPalette.inverse().get(this.blockData[x][y][z]), 2);
this.blockContainer.put(new BlockPos(x, y, z), this.blockPalette.inverse().get(this.blockData[x][y][z]));
}
}
}
for (int x = 0; x < width; x++) {
for (int z = 0; z < length; z++) {
this.biomeContainer.put(new BlockPos(x, 0, z), this.biomePalette.inverse().get(this.biomeData[x][z]));
}
}
for (CompoundTag blockEntityTag : schematic.getBlockEntities()) {
int[] arr = blockEntityTag.getIntArray("Pos");
BlockPos position = new BlockPos(arr[0], arr[1], arr[2]);
@ -73,15 +79,12 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
@Override
public @Nullable BlockEntity getBlockEntity(BlockPos pos) {
Block block = this.getBlockState(pos).getBlock();
if (block.hasBlockEntity()) {
if (block instanceof ConditionalBlockEntityProvider && ((ConditionalBlockEntityProvider) block).hasBlockEntity(this.getBlockState(pos)) && ((ConditionalBlockEntityProvider) block).hasBlockEntity(pos, this)) {
return ((ConditionalBlockEntityProvider) block).createBlockEntity(this.world);
} else {
return ((BlockEntityProvider) block).createBlockEntity(this.world);
}
}
return null;
return Optional.of(this.getBlockState(pos))
.map(BlockState::getBlock)
.filter(BlockEntityProvider.class::isInstance)
.map(BlockEntityProvider.class::cast)
.map(bep -> bep.createBlockEntity(this))
.orElse(null);
}
@Override
@ -94,18 +97,15 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
return this.blockContainer.get(pos).getFluidState();
}
public void place(BlockPos origin) {
if (this.world == null) {
throw new UnsupportedOperationException("Can not place in a null world!");
}
this.blockContainer.forEach((pos, state) -> this.world.setBlockState(origin.add(pos), state, 0b0000011));
public void place(BlockPos origin, StructureWorldAccess world, boolean biomes) {
this.blockContainer.forEach((pos, state) -> world.setBlockState(origin.add(pos), state, 0b0000011));
for (Map.Entry<BlockPos, CompoundTag> entry : this.blockEntityContainer.entrySet()) {
BlockPos pos = entry.getKey();
BlockPos actualPos = origin.add(entry.getKey());
BlockEntity blockEntity = BlockEntity.createFromTag(this.getBlockState(pos), entry.getValue());
if (blockEntity != null) {
this.world.toServerWorld().setBlockEntity(actualPos, blockEntity);
world.toServerWorld().setBlockEntity(actualPos, blockEntity);
}
}
for (Map.Entry<CompoundTag, Vec3d> entry : this.entityContainer.entrySet()) {
@ -116,8 +116,8 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
doubles.set(1, NbtOps.INSTANCE.createDouble(vec.y));
doubles.set(2, NbtOps.INSTANCE.createDouble(vec.z));
tag.put("Pos", doubles);
Entity entity = EntityType.getEntityFromTag(tag, this.world.toServerWorld()).orElseThrow(NoSuchElementException::new);
this.world.spawnEntity(entity);
Entity entity = EntityType.getEntityFromTag(tag, world.toServerWorld()).orElseThrow(NoSuchElementException::new);
world.spawnEntity(entity);
}
}
@ -137,15 +137,6 @@ public class RelativeBlockSample implements BlockView, ModifiableWorld {
return this.blockEntityContainer;
}
public StructureWorldAccess getWorld() {
return this.world;
}
public RelativeBlockSample setWorld(StructureWorldAccess world) {
this.world = world;
return this;
}
@Override
public boolean setBlockState(BlockPos pos, BlockState state, int flags, int maxUpdateDepth) {
this.blockContainer.put(pos, state);

View file

@ -2,16 +2,21 @@ package org.dimdev.dimdoors.util.schematic.v2;
import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import com.google.common.base.MoreObjects;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableList;
import com.google.gson.JsonObject;
import com.mojang.serialization.Codec;
import com.mojang.serialization.Dynamic;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.JsonOps;
import com.mojang.serialization.codecs.RecordCodecBuilder;
@ -21,12 +26,11 @@ import net.minecraft.entity.Entity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.biome.Biome;
public class Schematic {
private static final Consumer<String> PRINT_TO_STDERR = System.err::println;
public static final Codec<Schematic> CODEC = RecordCodecBuilder.create((instance) -> {
return instance.group(
public static final Codec<Schematic> CODEC = RecordCodecBuilder.create((instance) -> instance.group(
Codec.INT.fieldOf("Version").forGetter(Schematic::getVersion),
Codec.INT.optionalFieldOf("Data Version", SharedConstants.getGameVersion().getWorldVersion()).forGetter(Schematic::getDataVersion),
SchematicMetadata.CODEC.optionalFieldOf("Metadata", SchematicMetadata.EMPTY).forGetter(Schematic::getMetadata),
@ -38,9 +42,10 @@ public class Schematic {
SchematicBlockPalette.CODEC.fieldOf("Palette").forGetter(Schematic::getBlockPalette),
Codec.BYTE_BUFFER.fieldOf("BlockData").forGetter(Schematic::getBlockData),
Codec.list(CompoundTag.CODEC).optionalFieldOf("BlockEntities", ImmutableList.of()).forGetter(Schematic::getBlockEntities),
Codec.list(CompoundTag.CODEC).optionalFieldOf("Entities", ImmutableList.of()).forGetter(Schematic::getEntities)
).apply(instance, Schematic::new);
});
Codec.list(CompoundTag.CODEC).optionalFieldOf("Entities", ImmutableList.of()).forGetter(Schematic::getEntities),
SchematicBiomePalette.CODEC.optionalFieldOf("BiomePalette", Collections.emptyMap()).forGetter(Schematic::getBiomePalette),
Codec.BYTE_BUFFER.optionalFieldOf("BiomeData", ByteBuffer.wrap(new byte[0])).forGetter(Schematic::getBlockData)
).apply(instance, Schematic::new));
private final int version;
private final int dataVersion;
@ -54,8 +59,11 @@ public class Schematic {
private final ByteBuffer blockData;
private List<CompoundTag> blockEntities;
private List<CompoundTag> entities;
private final BiMap<Biome, Integer> biomePalette;
private final ByteBuffer biomeData;
private RelativeBlockSample cachedBlockSample = null;
public Schematic(int version, int dataVersion, SchematicMetadata metadata, short width, short height, short length, Vec3i offset, int paletteMax, Map<BlockState, Integer> blockPalette, ByteBuffer blockData, List<CompoundTag> blockEntities, List<CompoundTag> entities) {
public Schematic(int version, int dataVersion, SchematicMetadata metadata, short width, short height, short length, Vec3i offset, int paletteMax, Map<BlockState, Integer> blockPalette, ByteBuffer blockData, List<CompoundTag> blockEntities, List<CompoundTag> entities, Map<Biome, Integer> biomePalette, ByteBuffer biomeData) {
this.version = version;
this.dataVersion = dataVersion;
this.metadata = metadata;
@ -68,6 +76,8 @@ public class Schematic {
this.blockData = blockData;
this.blockEntities = blockEntities;
this.entities = entities;
this.biomePalette = HashBiMap.create(biomePalette);
this.biomeData = biomeData;
}
public int getVersion() {
@ -114,6 +124,14 @@ public class Schematic {
return this.blockEntities;
}
public BiMap<Biome, Integer> getBiomePalette() {
return this.biomePalette;
}
public ByteBuffer getBiomeData() {
return this.biomeData;
}
public void setBlockEntities(List<CompoundTag> blockEntities) {
this.blockEntities = blockEntities.stream().map(SchematicPlacer::fixEntityId).collect(Collectors.toList());
}
@ -135,11 +153,10 @@ public class Schematic {
}
public static RelativeBlockSample getBlockSample(Schematic schem) {
return new RelativeBlockSample(schem);
if (schem.cachedBlockSample == null) {
return (schem.cachedBlockSample = new RelativeBlockSample(schem));
}
public static RelativeBlockSample getBlockSample(Schematic schem, StructureWorldAccess world) {
return getBlockSample(schem).setWorld(world);
return schem.cachedBlockSample;
}
public static Schematic fromTag(CompoundTag tag) {
@ -157,4 +174,76 @@ public class Schematic {
public static JsonObject toJson(Schematic schem) {
return (JsonObject) CODEC.encodeStart(JsonOps.INSTANCE, schem).getOrThrow(false, PRINT_TO_STDERR);
}
public static <T> Schematic fromDynamic(Dynamic<T> dynamic) {
return CODEC.parse(dynamic).getOrThrow(false, PRINT_TO_STDERR);
}
public static <T> Dynamic<T> toDynamic(Schematic schem, DynamicOps<T> ops) {
return new Dynamic<>(ops,CODEC.encodeStart(ops, schem).getOrThrow(false, PRINT_TO_STDERR));
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("version", this.version)
.add("dataVersion", this.dataVersion)
.add("metadata", this.metadata)
.add("width", this.width)
.add("height", this.height)
.add("length", this.length)
.add("offset", this.offset)
.add("paletteMax", this.paletteMax)
.add("blockPalette", this.blockPalette)
.add("blockData", this.blockData)
.add("blockEntities", this.blockEntities)
.add("entities", this.entities)
.add("biomePalette", this.biomePalette)
.add("biomeData", this.biomeData)
.add("cachedBlockSample", this.cachedBlockSample)
.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
Schematic schematic = (Schematic) o;
return this.version == schematic.version &&
this.dataVersion == schematic.dataVersion &&
this.width == schematic.width &&
this.height == schematic.height &&
this.length == schematic.length &&
this.paletteMax == schematic.paletteMax &&
Objects.equals(this.metadata, schematic.metadata)
&& Objects.equals(this.offset, schematic.offset)
&& Objects.equals(this.blockPalette, schematic.blockPalette)
&& Objects.equals(this.blockData, schematic.blockData)
&& Objects.equals(this.blockEntities, schematic.blockEntities)
&& Objects.equals(this.entities, schematic.entities)
&& Objects.equals(this.biomePalette, schematic.biomePalette)
&& Objects.equals(this.biomeData, schematic.biomeData)
&& Objects.equals(this.cachedBlockSample, schematic.cachedBlockSample);
}
@Override
public int hashCode() {
return Objects.hash(
this.version,
this.dataVersion,
this.metadata,
this.width,
this.height,
this.length,
this.offset,
this.paletteMax,
this.blockPalette,
this.blockData,
this.blockEntities,
this.entities,
this.biomePalette,
this.biomeData,
this.cachedBlockSample
);
}
}

View file

@ -0,0 +1,11 @@
package org.dimdev.dimdoors.util.schematic.v2;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.UnboundedMapCodec;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.world.biome.Biome;
public class SchematicBiomePalette {
public static final UnboundedMapCodec<Biome, Integer> CODEC = Codec.unboundedMap(BuiltinRegistries.BIOME, Codec.INT);
}

View file

@ -31,8 +31,8 @@ public final class SchematicPlacer {
LOGGER.warn("Schematic \"" + schematic.getMetadata().getName() + "\" depends on mod \"" + id + "\", which is missing!");
}
}
RelativeBlockSample blockSample = Schematic.getBlockSample(schematic, world);
blockSample.place(origin);
RelativeBlockSample blockSample = Schematic.getBlockSample(schematic);
blockSample.place(origin, world, false);
}
public static int[][][] getBlockData(Schematic schematic) {
@ -51,6 +51,19 @@ public final class SchematicPlacer {
return blockData;
}
public static int[][] getBiomeData(Schematic schematic) {
int width = schematic.getWidth();
int length = schematic.getLength();
byte[] biomeDataArray = schematic.getBiomeData().array();
int[][] biomeData = new int[width][length];
for (int x = 0; x < width; x++) {
for (int z = 0; z < length; z++) {
biomeData[x][z] = biomeDataArray[x + z * width];
}
}
return biomeData;
}
private static void placeEntities(int originX, int originY, int originZ, Schematic schematic, StructureWorldAccess world) {
List<CompoundTag> entityTags = schematic.getEntities();
for (CompoundTag tag : entityTags) {

View file

@ -1,47 +0,0 @@
package org.dimdev.dimdoors.util.schematic.v2;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList;
import com.mojang.serialization.DataResult;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlastFurnaceBlockEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.projectile.FireballEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.Tag;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import net.fabricmc.loader.api.FabricLoader;
public class SchematicTest {
public static void test() throws IOException {
SchematicMetadata meta = new SchematicMetadata("Dimdoors Test Schematic", "Dimensional Development", System.currentTimeMillis(), ImmutableList.of("dimdoors"));
BlockEntity be = new BlastFurnaceBlockEntity();
be.setPos(new BlockPos(0, 0, 0));
CompoundTag beTag = new CompoundTag();
be.toTag(beTag);
Entity e = new FireballEntity(EntityType.FIREBALL, DimensionalDoorsInitializer.getServer().getOverworld());
e.setPos(1, 1, 1);
CompoundTag eTag = new CompoundTag();
e.saveSelfToTag(eTag);
Schematic schematic = new Schematic(2, 2543, meta, (short) 5, (short) 5, (short) 5, Vec3i.ZERO, -1, ImmutableBiMap.of(Blocks.AIR.getDefaultState(), 0, Blocks.NETHERRACK.getDefaultState(), 1), ByteBuffer.wrap(new byte[]{1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0}), ImmutableList.of(beTag), ImmutableList.of(eTag));
DataResult<Tag> result = Schematic.CODEC.encodeStart(NbtOps.INSTANCE, schematic);
Path path = FabricLoader.getInstance().getConfigDir().resolve("schematic.schem");
if (!Files.exists(path)) {
Files.createFile(path);
}
NbtIo.writeCompressed((CompoundTag) result.getOrThrow(false, System.err::println), path.toFile());
}
}

View file

@ -0,0 +1,70 @@
package org.dimdev.dimdoors.util.schematic.v2;
import java.util.function.Predicate;
import org.jetbrains.annotations.Nullable;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.fluid.FluidState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.Heightmap;
import net.minecraft.world.ModifiableTestableWorld;
import net.minecraft.world.StructureWorldAccess;
public class WorldlyBlockSample implements BlockView, ModifiableTestableWorld {
private final RelativeBlockSample relativeBlockSample;
private final StructureWorldAccess world;
public WorldlyBlockSample(RelativeBlockSample relativeBlockSample, StructureWorldAccess world) {
this.relativeBlockSample = relativeBlockSample;
this.world = world;
}
public void place(BlockPos origin, boolean biomes) {
this.relativeBlockSample.place(origin, this.world, biomes);
}
@Nullable
@Override
public BlockEntity getBlockEntity(BlockPos pos) {
return this.relativeBlockSample.getBlockEntity(pos);
}
@Override
public BlockState getBlockState(BlockPos pos) {
return this.relativeBlockSample.getBlockState(pos);
}
@Override
public FluidState getFluidState(BlockPos pos) {
return this.relativeBlockSample.getFluidState(pos);
}
@Override
public boolean setBlockState(BlockPos pos, BlockState state, int flags, int maxUpdateDepth) {
return this.relativeBlockSample.setBlockState(pos, state, flags, maxUpdateDepth);
}
@Override
public boolean removeBlock(BlockPos pos, boolean move) {
return this.relativeBlockSample.removeBlock(pos, move);
}
@Override
public boolean breakBlock(BlockPos pos, boolean drop, @Nullable Entity breakingEntity, int maxUpdateDepth) {
return this.relativeBlockSample.breakBlock(pos, drop, breakingEntity, maxUpdateDepth);
}
@Override
public boolean testBlockState(BlockPos pos, Predicate<BlockState> state) {
return state.test(this.getBlockState(pos));
}
@Override
public BlockPos getTopPosition(Heightmap.Type type, BlockPos pos) {
return this.world.getTopPosition(type, pos);
}
}