This repository has been archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
357 additions
and
22 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/debug/java/org/dimdev/testmod/ChangeDimensionCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.dimdev.testmod; | ||
|
||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.arguments.ArgumentType; | ||
import com.mojang.brigadier.arguments.IntegerArgumentType; | ||
import com.mojang.brigadier.builder.LiteralArgumentBuilder; | ||
import com.mojang.brigadier.builder.RequiredArgumentBuilder; | ||
import net.minecraft.command.CommandSource; | ||
import net.minecraft.entity.Entity; | ||
|
||
public class ChangeDimensionCommand { | ||
public static void register(CommandDispatcher<CommandSource> dispatcher) { | ||
LiteralArgumentBuilder<CommandSource> builder = literalArgument("changedimension") | ||
.then(requiredArgument("dimension", IntegerArgumentType.integer(0)) | ||
.executes(context -> { | ||
Entity entity = context.getSource().getEntity(); | ||
entity.changeDimension(context.getArgument("dimension", Integer.class)); | ||
return 0; | ||
})); | ||
dispatcher.register(builder); | ||
} | ||
|
||
private static LiteralArgumentBuilder<CommandSource> literalArgument(String name) { | ||
return LiteralArgumentBuilder.literal(name); | ||
} | ||
|
||
private static <T> RequiredArgumentBuilder<CommandSource, T> requiredArgument(String name, ArgumentType<T> type) { | ||
return RequiredArgumentBuilder.argument(name, type); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/org/dimdev/rift/listener/DimensionTypeAdder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.dimdev.rift.listener; | ||
|
||
import net.minecraft.world.dimension.Dimension; | ||
import net.minecraft.world.dimension.DimensionType; | ||
import org.dimdev.utils.ReflectionUtils; | ||
|
||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
|
||
public interface DimensionTypeAdder { | ||
static DimensionType newDimensionType(int id, String name, String suffix, Supplier<? extends Dimension> dimensionSupplier) { | ||
return ReflectionUtils.makeEnumInstance(DimensionType.class, new Object[]{name.toUpperCase(), -1, id, name, suffix, dimensionSupplier}); | ||
} | ||
|
||
Set<? extends DimensionType> getDimensionTypes(); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/org/dimdev/rift/listener/client/AmbientMusicTypeProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.dimdev.rift.listener.client; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.util.SoundEvent; | ||
import org.dimdev.utils.ReflectionUtils; | ||
|
||
import static net.minecraft.client.audio.MusicTicker.MusicType; | ||
|
||
public interface AmbientMusicTypeProvider { | ||
static MusicType newMusicType(String name, SoundEvent sound, int minDelay, int maxDelay) { | ||
return ReflectionUtils.makeEnumInstance(MusicType.class, new Object[] {name, -1, sound, minDelay, maxDelay }); | ||
} | ||
|
||
MusicType getAmbientMusicType(Minecraft client); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/dimdev/rift/mixin/core/MixinMinecraftServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.dimdev.rift.mixin.core; | ||
|
||
import net.minecraft.server.MinecraftServer; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
|
||
@Mixin(MinecraftServer.class) | ||
public class MixinMinecraftServer { | ||
@Overwrite | ||
public String getServerModName() { | ||
return "rift"; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/org/dimdev/rift/mixin/hook/MixinAnvilSaveHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.dimdev.rift.mixin.hook; | ||
|
||
import com.mojang.datafixers.DataFixer; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.world.chunk.storage.AnvilChunkLoader; | ||
import net.minecraft.world.chunk.storage.AnvilSaveHandler; | ||
import net.minecraft.world.chunk.storage.IChunkLoader; | ||
import net.minecraft.world.dimension.Dimension; | ||
import net.minecraft.world.storage.SaveHandler; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
|
||
import javax.annotation.Nullable; | ||
import java.io.File; | ||
|
||
@Mixin(AnvilSaveHandler.class) | ||
public class MixinAnvilSaveHandler extends SaveHandler { | ||
public MixinAnvilSaveHandler(File p_i49566_1_, String p_i49566_2_, @Nullable MinecraftServer p_i49566_3_, DataFixer p_i49566_4_) { | ||
super(p_i49566_1_, p_i49566_2_, p_i49566_3_, p_i49566_4_); | ||
} | ||
|
||
@Overwrite | ||
@Override | ||
public IChunkLoader getChunkLoader(Dimension provider) { | ||
File worldDirectory = getWorldDirectory(); | ||
int dimensionId = provider.getDimensionType().getId(); | ||
if (dimensionId == 0) { | ||
return new AnvilChunkLoader(worldDirectory, dataFixer); | ||
} else { | ||
File dimensionFolder = new File(worldDirectory, "DIM" + dimensionId); | ||
dimensionFolder.mkdirs(); | ||
return new AnvilChunkLoader(dimensionFolder, dataFixer); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/org/dimdev/rift/mixin/hook/MixinDimensionType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.dimdev.rift.mixin.hook; | ||
|
||
import net.minecraft.world.dimension.DimensionType; | ||
import org.dimdev.rift.listener.DimensionTypeAdder; | ||
import org.dimdev.riftloader.RiftLoader; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
|
||
import java.util.HashMap; | ||
|
||
@Mixin(DimensionType.class) | ||
public class MixinDimensionType { | ||
@SuppressWarnings("PublicStaticMixinMember") // accessed using reflection | ||
private static HashMap<Integer, DimensionType> dimensionTypes = new HashMap<>(); | ||
|
||
static { | ||
for (DimensionType dimensionType : DimensionType.values()) { | ||
dimensionTypes.put(dimensionType.getId(), dimensionType); | ||
} | ||
|
||
for (DimensionTypeAdder dimensionTypeAdder : RiftLoader.instance.getListeners(DimensionTypeAdder.class)) { | ||
for (DimensionType dimensionType : dimensionTypeAdder.getDimensionTypes()) { | ||
dimensionTypes.put(dimensionType.getId(), dimensionType); | ||
} | ||
} | ||
} | ||
|
||
@Overwrite | ||
public static DimensionType getById(int id) { | ||
DimensionType dimensionType = dimensionTypes.get(id); | ||
if (dimensionType == null) { | ||
throw new IllegalArgumentException("Invalid dimension id " + id); | ||
} | ||
|
||
return dimensionType; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.