diff options
author | Roman / Nea <roman.graef@gmail.com> | 2022-01-16 01:03:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-15 19:03:04 -0500 |
commit | c81b6a34ae7bbb70a11f23f49422f2fceffa689c (patch) | |
tree | 44d2f2ba99a7e1746293489ee9b00dc9c307735b /src/main/java/io | |
parent | 2aa911fa84399a5a8cc9f36715246c7f3eee7133 (diff) | |
download | NotEnoughUpdates-c81b6a34ae7bbb70a11f23f49422f2fceffa689c.tar.gz NotEnoughUpdates-c81b6a34ae7bbb70a11f23f49422f2fceffa689c.tar.bz2 NotEnoughUpdates-c81b6a34ae7bbb70a11f23f49422f2fceffa689c.zip |
Add sounds and rework the existing textures to custom Dwarven Mines /… (#51)
* Pre Work of custom biomes
* Work on auto chunk update, Add Debug command
* Added 6 new biomes that are used in crystal hollows
* Made it so the biomes are registered in the main class so it loads properly
* Add sounds and rework the existing textures to custom Dwarven Mines / CH blocks
* Config fixups
* make titanium sounds work
* Added sounds per gemstone type
* fix dwarven mines sounds
* stop spamming sound effects with config
* Changelog for CH custom blocks
* add all the files
* Update src/main/resources/assets/notenoughupdates/sounds/titaniumbreak.json
* Update src/main/resources/assets/notenoughupdates/sounds/mithrilbreak.json
* Update src/main/resources/assets/notenoughupdates/sounds/gemstonetopazbreak.json
* Update src/main/resources/assets/notenoughupdates/sounds/gemstonerubybreak.json
* Update src/main/resources/assets/notenoughupdates/sounds/gemstonesapphirebreak.json
* Update src/main/resources/assets/notenoughupdates/sounds/gemstonejasperbreak.json
* Update src/main/resources/assets/notenoughupdates/sounds/gemstoneamethystbreak.json
* Update src/main/resources/assets/notenoughupdates/sounds/gemstonejadebreak.json
* Update src/main/resources/assets/notenoughupdates/sounds/gemstoneamberbreak.json
* Update src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
* Update src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
* Update src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
* Update src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
* Update src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
* Update src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
Co-authored-by: DoKM <mcazzyman@gmail.com>
Co-authored-by: nopothegamer <40329022+nopothegamer@users.noreply.github.com>
Co-authored-by: IRONM00N <64110067+IRONM00N@users.noreply.github.com>
Diffstat (limited to 'src/main/java/io')
17 files changed, 721 insertions, 428 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java index 4b6cd511..d7061c22 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java @@ -305,7 +305,6 @@ public class NEUEventListener { if (longUpdate) { CrystalOverlay.tick(); - DwarvenMinesTextures.tick(); FairySouls.tick(); XPInformation.getInstance().tick(); ProfileApiSyncer.getInstance().tick(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 3a6afef8..0cff5de1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -9,6 +9,9 @@ import io.github.moulberry.notenoughupdates.core.BackgroundBlur; import io.github.moulberry.notenoughupdates.cosmetics.CapeManager; import io.github.moulberry.notenoughupdates.dungeons.DungeonMap; import io.github.moulberry.notenoughupdates.miscfeatures.*; +import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBiomes; +import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBlockSounds; +import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.DwarvenMinesTextures; import io.github.moulberry.notenoughupdates.miscgui.CalendarOverlay; import io.github.moulberry.notenoughupdates.miscgui.InventoryStorageSelector; import io.github.moulberry.notenoughupdates.options.NEUConfig; @@ -28,6 +31,7 @@ import net.minecraft.scoreboard.ScoreObjective; import net.minecraft.scoreboard.Scoreboard; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.biome.*; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.common.Mod; @@ -35,6 +39,7 @@ import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; +import scala.collection.parallel.ParIterableLike; import java.awt.*; import java.io.*; @@ -101,6 +106,17 @@ public class NotEnoughUpdates { public Color[][] colourMap = null; /** + * Registers the biomes for the crystal hollows here so optifine knows they exists + */ + public static final BiomeGenBase crystalHollowsJungle = (new BiomeGenJungle(101, true)).setColor(5470985).setBiomeName("NeuCrystalHollowsJungle").setFillerBlockMetadata(5470985).setTemperatureRainfall(0.95F, 0.9F); + public static final BiomeGenBase crystalHollowsMagmaFields = (new BiomeGenHell(102)).setColor(16711680).setBiomeName("NeuCrystalHollowsMagmaFields").setDisableRain().setTemperatureRainfall(2.0F, 0.0F); + public static final BiomeGenBase crystalHollowsGoblinHoldout = (new BiomeGenMesa(103, false, false)).setColor(13274213).setBiomeName("NeuCrystalHollowsGoblinHoldout"); + public static final BiomeGenBase crystalHollowsPrecursorRemnants = (new BiomeGenMesa(104, false, true)).setColor(11573093).setBiomeName("NeuCrystalHollowsPrecursorRemnants"); + public static final BiomeGenBase crystalHollowsMithrilDeposit = (new BiomeGenSnow(105, false)).setColor(16777215).setBiomeName("NeuCrystalHollowsMithrilDeposits"); + public static final BiomeGenBase crystalHollowsCrystalNucleus = (new BiomeGenJungle(106, true)).setColor(5470985).setBiomeName("NeuCrystalHollowsCrystalNucleus").setFillerBlockMetadata(5470985).setTemperatureRainfall(0.95F, 0.9F); + + + /** * Instantiates NEUIo, NEUManager and NEUOverlay instances. Registers keybinds and adds a shutdown hook to clear tmp folder. */ @EventHandler @@ -145,7 +161,7 @@ public class NotEnoughUpdates { MinecraftForge.EVENT_BUS.register(new FairySouls()); MinecraftForge.EVENT_BUS.register(new CrystalOverlay()); MinecraftForge.EVENT_BUS.register(new ItemCooldowns()); - MinecraftForge.EVENT_BUS.register(new DwarvenMinesTextures()); + MinecraftForge.EVENT_BUS.register(new DwarvenMinesWaypoints()); MinecraftForge.EVENT_BUS.register(new FuelBar()); //MinecraftForge.EVENT_BUS.register(new FancyPortals()); @@ -157,10 +173,15 @@ public class NotEnoughUpdates { MinecraftForge.EVENT_BUS.register(SlotLocking.getInstance()); MinecraftForge.EVENT_BUS.register(FishingHelper.getInstance()); + MinecraftForge.EVENT_BUS.register(new DwarvenMinesTextures()); + MinecraftForge.EVENT_BUS.register(CustomBiomes.INSTANCE); + if (Minecraft.getMinecraft().getResourceManager() instanceof IReloadableResourceManager) { - ((IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager()).registerReloadListener(CustomSkulls.getInstance()); - ((IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager()).registerReloadListener(NPCRetexturing.getInstance()); - ((IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager()).registerReloadListener(new ItemCustomizeManager.ReloadListener()); + IReloadableResourceManager manager = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager(); + manager.registerReloadListener(CustomSkulls.getInstance()); + manager.registerReloadListener(NPCRetexturing.getInstance()); + manager.registerReloadListener(new ItemCustomizeManager.ReloadListener()); + manager.registerReloadListener(new CustomBlockSounds.ReloaderListener()); } this.commands = new Commands(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java index 0e58a6bc..37fe5f63 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java @@ -14,6 +14,9 @@ import io.github.moulberry.notenoughupdates.cosmetics.GuiCosmetics; import io.github.moulberry.notenoughupdates.dungeons.DungeonWin; import io.github.moulberry.notenoughupdates.dungeons.GuiDungeonMapEditor; import io.github.moulberry.notenoughupdates.gamemodes.GuiGamemodes; +import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBiomes; +import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.LocationChangeEvent; +import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.SpecialBlockZone; import io.github.moulberry.notenoughupdates.miscfeatures.FairySouls; import io.github.moulberry.notenoughupdates.miscfeatures.FancyPortals; import io.github.moulberry.notenoughupdates.miscfeatures.FishingHelper; @@ -25,6 +28,7 @@ import io.github.moulberry.notenoughupdates.options.NEUConfigEditor; import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; import io.github.moulberry.notenoughupdates.profileviewer.PlayerStats; import io.github.moulberry.notenoughupdates.util.Constants; +import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.block.material.MapColor; import net.minecraft.client.Minecraft; @@ -39,16 +43,17 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.*; import net.minecraft.world.storage.MapData; import net.minecraftforge.client.ClientCommandHandler; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Loader; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.text.WordUtils; -import java.awt.*; +import java.awt.Color; +import java.awt.Desktop; import java.io.*; import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; -import java.util.List; import java.util.*; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -97,6 +102,7 @@ public class Commands { ClientCommandHandler.instance.registerCommand(neuRepoMode); } + SimpleCommand.ProcessCommandRunnable collectionLogRun = new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { NotEnoughUpdates.INSTANCE.openGui = new GuiCollectionLog(); @@ -755,7 +761,18 @@ public class Commands { NotEnoughUpdates.INSTANCE.openGui = new GuiPriceGraph(args[1]); } } - + if (args.length == 1 && args[0].equalsIgnoreCase("zone")) { + BlockPos target = Minecraft.getMinecraft().objectMouseOver.getBlockPos(); + if (target == null) target = Minecraft.getMinecraft().thePlayer.getPosition(); + SpecialBlockZone zone = CustomBiomes.INSTANCE.getSpecialZone(target); + Arrays.asList( + new ChatComponentText("Showing Zone Info for: " + target), + new ChatComponentText("Zone: " + (zone != null ? zone.name() : "null")), + new ChatComponentText("Location: " + SBInfo.getInstance().getLocation()), + new ChatComponentText("Biome: " + CustomBiomes.INSTANCE.getCustomBiome(target)) + ).forEach(Minecraft.getMinecraft().thePlayer::addChatMessage); + MinecraftForge.EVENT_BUS.post(new LocationChangeEvent(SBInfo.getInstance().getLocation(), SBInfo.getInstance().getLocation())); + } if (args.length == 1 && args[0].equalsIgnoreCase("positiontest")) { NotEnoughUpdates.INSTANCE.openGui = new GuiPositionEditor(); return; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/events/NEUEvent.java b/src/main/java/io/github/moulberry/notenoughupdates/events/NEUEvent.java new file mode 100644 index 00000000..edcfe072 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/events/NEUEvent.java @@ -0,0 +1,11 @@ +package io.github.moulberry.notenoughupdates.events; + +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.eventhandler.Event; + +public class NEUEvent extends Event { + public boolean post() { + MinecraftForge.EVENT_BUS.post(this); + return isCancelable() && isCanceled(); + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/events/OnBlockBreakSoundEffect.java b/src/main/java/io/github/moulberry/notenoughupdates/events/OnBlockBreakSoundEffect.java new file mode 100644 index 00000000..b11cbd13 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/events/OnBlockBreakSoundEffect.java @@ -0,0 +1,40 @@ +package io.github.moulberry.notenoughupdates.events; + +import net.minecraft.block.state.BlockState; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.audio.ISound; +import net.minecraft.util.BlockPos; + +public class OnBlockBreakSoundEffect extends NEUEvent { + + private ISound sound; + private final BlockPos position; + private final IBlockState block; + + public OnBlockBreakSoundEffect(ISound sound, BlockPos position, IBlockState block) { + this.sound = sound; + this.position = position; + this.block = block; + } + + @Override + public boolean isCancelable() { + return true; + } + + public BlockPos getPosition() { + return position; + } + + public IBlockState getBlock() { + return block; + } + + public ISound getSound() { + return sound; + } + + public void setSound(ISound sound) { + this.sound = sound; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DwarvenMinesTextures.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DwarvenMinesTextures.java deleted file mode 100644 index 58ea414f..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DwarvenMinesTextures.java +++ /dev/null @@ -1,400 +0,0 @@ -package io.github.moulberry.notenoughupdates.miscfeatures; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.util.SBInfo; -import net.minecraft.block.BlockColored; -import net.minecraft.block.BlockStone; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; -import net.minecraft.init.Blocks; -import net.minecraft.item.EnumDyeColor; -import net.minecraft.util.BlockPos; -import net.minecraft.util.MathHelper; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.ChunkCoordIntPair; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -public class DwarvenMinesTextures { - private static class IgnoreColumn { - boolean always; - int minY; - int maxY; - - public IgnoreColumn(boolean always, int minY, int maxY) { - this.always = always; - this.minY = minY; - this.maxY = maxY; - } - } - - private static HashSet<ChunkCoordIntPair> ignoredChunks = null; - private static final HashMap<ChunkCoordIntPair, HashMap<ChunkCoordIntPair, IgnoreColumn>> loadedChunkData = new HashMap<>(); - private static final HashMap<ChunkCoordIntPair, Long> lastRetextureCheck = new HashMap<>(); - private static long time; - private static boolean error = false; - - public static int retexture(BlockPos pos) { - if (!NotEnoughUpdates.INSTANCE.config.mining.dwarvenTextures) return 0; - if (error) return 0; - if (Minecraft.getMinecraft().theWorld == null) return 0; - - String location = SBInfo.getInstance().getLocation(); - - if (location == null) return 0; - if (location.equals("crystal_hollows")) return 3; - if (!location.equals("mining_3")) return 0; - - IBlockState state = Minecraft.getMinecraft().theWorld.getBlockState(pos); - boolean titanium = state.getBlock() == Blocks.stone && state.getValue(BlockStone.VARIANT) == BlockStone.EnumType.DIORITE_SMOOTH; - if (titanium) { - IBlockState plus = Minecraft.getMinecraft().theWorld.getBlockState(pos.add(1, 0, 0)); - if (plus.getBlock() == Blocks.double_stone_slab) { - return 1; - } - IBlockState minus = Minecraft.getMinecraft().theWorld.getBlockState(pos.add(-1, 0, 0)); - if (minus.getBlock() == Blocks.double_stone_slab) { - return 1; - } - IBlockState above = Minecraft.getMinecraft().theWorld.getBlockState(pos.add(0, 1, 0)); - if (above.getBlock() == Blocks.stone_slab) { - return 1; - } - } - - if (titanium || (state.getBlock() == Blocks.stained_hardened_clay && state.getValue(BlockColored.COLOR) == EnumDyeColor.CYAN) || - (state.getBlock() == Blocks.wool && state.getValue(BlockColored.COLOR) == EnumDyeColor.GRAY)) { - - if (ignoredChunks == null) { - try { - ignoredChunks = new HashSet<>(); - ResourceLocation loc = new ResourceLocation("notenoughupdates:dwarven_data/all.json"); - InputStream is = Minecraft.getMinecraft().getResourceManager().getResource(loc).getInputStream(); - - try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { - JsonObject json = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(reader, JsonObject.class); - for (Map.Entry<String, JsonElement> entry : json.entrySet()) { - String coord = entry.getKey(); - String[] split = coord.split("_"); - int left = Integer.parseInt(split[0]); - int right = Integer.parseInt(split[1]); - ignoredChunks.add(new ChunkCoordIntPair(left, right)); - } - } - } catch (Exception e) { - error = true; - return 1; - } - } - if (ignoredChunks != null) { - ChunkCoordIntPair pair = new ChunkCoordIntPair(MathHelper.floor_float(pos.getX() / 16f), - MathHelper.floor_float(pos.getZ() / 16f)); - - lastRetextureCheck.put(pair, time); - - if (ignoredChunks.contains(pair)) { - return 1; - } - if (titanium) { - return 2; - } - - if (!loadedChunkData.containsKey(pair)) { - try { - HashMap<ChunkCoordIntPair, IgnoreColumn> map = new HashMap<>(); - loadedChunkData.put(pair, map); - - ResourceLocation loc = new ResourceLocation("notenoughupdates:dwarven_data/" + - pair.chunkXPos + "_" + pair.chunkZPos + ".json"); - InputStream is = Minecraft.getMinecraft().getResourceManager().getResource(loc).getInputStream(); - - try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { - JsonObject json = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(reader, JsonObject.class); - for (Map.Entry<String, JsonElement> entry : json.entrySet()) { - String coord = entry.getKey(); - String[] split = coord.split(":"); - int left = Integer.parseInt(split[0]); - int right = Integer.parseInt(split[1]); - - IgnoreColumn ignore = null; - if (entry.getValue().isJsonPrimitive()) { - JsonPrimitive prim = entry.getValue().getAsJsonPrimitive(); - if (prim.isBoolean()) { - ignore = new IgnoreColumn(true, 0, 0); - } else if (prim.isNumber()) { - int y = prim.getAsInt(); - ignore = new IgnoreColumn(false, y, y); - } - } else if (entry.getValue().isJsonArray()) { - JsonArray arr = entry.getValue().getAsJsonArray(); - if (arr.size() == 2) { - int min = arr.get(0).getAsInt(); - int max = arr.get(1).getAsInt(); - ignore = new IgnoreColumn(false, min, max); - } - } - if (ignore != null) { - ChunkCoordIntPair offset = new ChunkCoordIntPair(left, right); - map.put(offset, ignore); - } - } - } - } catch (Exception e) { - loadedChunkData.put(pair, null); - } - } - if (loadedChunkData.get(pair) != null) { - HashMap<ChunkCoordIntPair, IgnoreColumn> map = loadedChunkData.get(pair); - if (map == null) { - return 0; - } - - int modX = pos.getX() % 16; - int modZ = pos.getZ() % 16; - if (modX < 0) modX += 16; - if (modZ < 0) modZ += 16; - ChunkCoordIntPair offset = new ChunkCoordIntPair(modX, modZ); - - IgnoreColumn ignore = map.get(offset); - if (ignore != null) { - if (ignore.always) { - return 1; - } else { - int y = pos.getY(); - if (y >= ignore.minY && y <= ignore.maxY) { - return 1; - } - } - } - } - } - } - - return 2; - } - - /*@SubscribeEvent - public void onRender(RenderWorldLastEvent event) { - Entity viewer = Minecraft.getMinecraft().getRenderViewEntity(); - double viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * event.partialTicks; - double viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * event.partialTicks; - double viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * event.partialTicks; - - int x = MathHelper.floor_double(viewer.posX / 16f); - int z = MathHelper.floor_double(viewer.posZ / 16f); - File file = new File("C:/Users/James/Desktop/testfolder/" + x + "_" + z + ".json"); - - int col = 0xff0000; - if (file.exists()) { - col = 0x00ff00; - if (Keyboard.isKeyDown(Keyboard.KEY_K)) { - file.delete(); - } - - } - - AxisAlignedBB bb = new AxisAlignedBB( - MathHelper.floor_double(viewerX / 16) * 16 - viewerX, - 0 - viewerY, - MathHelper.floor_double(viewerZ / 16) * 16 - viewerZ, - MathHelper.floor_double(viewerX / 16) * 16 + 16 - viewerX, - 255 - viewerY, - MathHelper.floor_double(viewerZ / 16) * 16 + 16 - viewerZ).expand(0.01f, 0.01f, 0.01f); - - GlStateManager.disableCull(); - CustomItemEffects.drawFilledBoundingBox(bb, 1f, SpecialColour.special(0, 100, col)); - GlStateManager.enableCull(); - GlStateManager.enableTexture2D(); - }*/ - - //Render all blocks - extremeHillsEdge - //Don't render smooth diorite - extremeHillsPlus - //Don't render clay - mesaPlateau_F - - public static void tick() { - if (!NotEnoughUpdates.INSTANCE.config.mining.dwarvenTextures) return; - - time = System.currentTimeMillis(); - Set<ChunkCoordIntPair> remove = new HashSet<>(); - for (Map.Entry<ChunkCoordIntPair, Long> entry : lastRetextureCheck.entrySet()) { - if (time - entry.getValue() > 30 * 1000) { - remove.add(entry.getKey()); - } - } - lastRetextureCheck.keySet().removeAll(remove); - loadedChunkData.keySet().removeAll(remove); - - /*if (Minecraft.getMinecraft().theWorld == null) return; - - if (SBInfo.getInstance().getLocation() == null) return; - if (!SBInfo.getInstance().getLocation().equals("mining_3")) return; - - int playerX = (int) Minecraft.getMinecraft().thePlayer.posX; - int playerZ = (int) Minecraft.getMinecraft().thePlayer.posZ; - - if (Keyboard.isKeyDown(Keyboard.KEY_C)) { - ignoredBlocks.clear(); - whitelistBlocks.clear(); - } - if (Keyboard.isKeyDown(Keyboard.KEY_R)) { - ignoredChunks.clear(); - } - if (Keyboard.isKeyDown(Keyboard.KEY_P)) { - Gson gson = new GsonBuilder().create(); - JsonObject obj = new JsonObject(); - - for (Map.Entry<ChunkCoordIntPair, HashMap<ChunkCoordIntPair, Set<BlockPos>>> entry : ignoredBlocks.entrySet()) { - String chunkId = entry.getKey().chunkXPos + "_" + entry.getKey().chunkZPos; - if (!whitelistBlocks.containsKey(entry.getKey()) || whitelistBlocks.get(entry.getKey()).isEmpty()) { - obj.addProperty(chunkId, true); - } else { - HashMap<ChunkCoordIntPair, Set<BlockPos>> whitelistMap = whitelistBlocks.get(entry.getKey()); - JsonObject subChunkObj = new JsonObject(); - - for (Map.Entry<ChunkCoordIntPair, Set<BlockPos>> columnEntry : entry.getValue().entrySet()) { - String columnId = columnEntry.getKey().chunkXPos + ":" + columnEntry.getKey().chunkZPos; - - if (!whitelistMap.containsKey(columnEntry.getKey()) || whitelistMap.get(columnEntry.getKey()).isEmpty()) { - subChunkObj.addProperty(columnId, true); - } else if (!columnEntry.getValue().isEmpty()) { - JsonArray whitelistedBlocksInColumn = new JsonArray(); - - int min = 300; - int max = 0; - for (BlockPos pos : columnEntry.getValue()) { - int y = pos.getY(); - if (y < min) { - min = y; - } - if (y > max) { - max = y; - } - } - whitelistedBlocksInColumn.add(new JsonPrimitive(min)); - whitelistedBlocksInColumn.add(new JsonPrimitive(max)); - if (min < max) { - subChunkObj.add(columnId, whitelistedBlocksInColumn); - } else { - subChunkObj.addProperty(columnId, min); - } - } - } - try { - File file = new File("C:/Users/James/Desktop/testfolder/" + chunkId + ".json"); - file.createNewFile(); - - try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8))) { - writer.write(gson.toJson(subChunkObj)); - } - } catch (IOException ignored) { - ignored.printStackTrace(); - } - } - } - - try { - File file = new File("C:/Users/James/Desktop/testfolder/all.json"); - file.createNewFile(); - - try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8))) { - writer.write(gson.toJson(obj)); - } - } catch (IOException ignored) { - ignored.printStackTrace(); - } - - } - - for (int xC = -10; xC <= 10; xC++) { - out: - for (int zC = -10; zC <= 10; zC++) { - ChunkCoordIntPair pair = new ChunkCoordIntPair(playerX / 16 + xC, playerZ / 16 + zC); - - if (!ignoredChunks.contains(pair)) { - ignoredChunks.add(pair); - - boolean add = false; - for (int x = 0; x < 16; x++) { - for (int y = 0; y < 255; y++) { - for (int z = 0; z < 16; z++) { - BlockPos pos = new BlockPos(pair.chunkXPos * 16 + x, y, pair.chunkZPos * 16 + z); - IBlockState state = Minecraft.getMinecraft().theWorld.getBlockState(pos); - - ChunkCoordIntPair column = new ChunkCoordIntPair(x, z); - - if (state != null && state.getBlock() != Blocks.air) add = true; - - if (state != null && ((state.getBlock() == Blocks.stained_hardened_clay && - state.getValue(BlockColored.COLOR) == EnumDyeColor.CYAN) || - (state.getBlock() == Blocks.wool) && state.getValue(BlockColored.COLOR) == EnumDyeColor.GRAY || - (state.getBlock() == Blocks.stone && state.getValue(BlockStone.VARIANT) == BlockStone.EnumType.DIORITE_SMOOTH))) { - - boolean hasAir = false; - for (int xO = -1; xO <= 1; xO++) { - for (int yO = -1; yO <= 1; yO++) { - for (int zO = -1; zO <= 1; zO++) { - int tot = Math.abs(xO) + Math.abs(yO) + Math.abs(zO); - if (tot == 1) { - BlockPos pos2 = pos.add(xO, yO, zO); - IBlockState state2 = Minecraft.getMinecraft().theWorld.getBlockState(pos2); - - if (state2 == null) { - continue out; - } else if (state2.getBlock() == Blocks.air) { - hasAir = true; - } - } - } - } - } - if (!hasAir) continue; - - boolean found = false; - out2: - for (int xO = -4; xO <= 4; xO++) { - for (int yO = -4; yO <= 4; yO++) { - for (int zO = -4; zO <= 4; zO++) { - int distSq = xO * xO + yO * yO + zO * zO; - if (distSq < 4 * 4) { - BlockPos pos2 = pos.add(xO, yO, zO); - IBlockState state2 = Minecraft.getMinecraft().theWorld.getBlockState(pos2); - - if (state2 == null) { - continue out; - } else if (state2.getBlock() == Blocks.prismarine) { - ignoredBlocks.computeIfAbsent(pair, k -> new HashMap<>()) - .computeIfAbsent(column, k -> new HashSet<>()).remove(pos); - whitelistBlocks.computeIfAbsent(pair, k -> new HashMap<>()) - .computeIfAbsent(column, k -> new HashSet<>()).add(pos); - found = true; - break out2; - } - } - } - } - } - if (!found) { - ignoredBlocks.computeIfAbsent(pair, k -> new HashMap<>()) - .computeIfAbsent(column, k -> new HashSet<>()).add(pos); - } - - } - } - } - } - } - } - }*/ - } -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/CrystalHollowsTextures.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/CrystalHollowsTextures.java new file mode 100644 index 00000000..ab6aaf90 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/CrystalHollowsTextures.java @@ -0,0 +1,22 @@ +package io.github.moulberry.notenoughupdates.miscfeatures.customblockzones; + +import net.minecraft.util.BlockPos; + +public class CrystalHollowsTextures implements IslandZoneSubdivider { + public SpecialBlockZone getSpecialZoneForBlock(String location, BlockPos pos) { + if (pos.getY() < 65) { + return SpecialBlockZone.CRYSTAL_HOLLOWS_MAGMA_FIELDS; + } else if (pos.getX() < 565 && pos.getX() > 461 && pos.getZ() < 566 && pos.getZ() > 460 && pos.getY() > 64) { + return SpecialBlockZone.CRYSTAL_HOLLOWS_NUCLEUS; + } else if (pos.getX() < 513 && pos.getZ() < 513 && pos.getY() > 64) { + return SpecialBlockZone.CRYSTAL_HOLLOWS_JUNGLE; + } else if (pos.getX() < 513 && pos.getZ() > 512 && pos.getY() > 64) { + return SpecialBlockZone.CRYSTAL_HOLLOWS_GOBLIN_HIDEOUT; + } else if (pos.getX() > 512 && pos.getZ() < 513 && pos.getY() > 64) { + return SpecialBlockZone.CRYSTAL_HOLLOWS_MITHRIL_DEPOSIT; + } else if (pos.getX() > 512 && pos.getZ() > 512 && pos.getY() > 64) { + return SpecialBlockZone.CRYSTAL_HOLLOWS_PRECURSOR_REMNANTS; + } + return null; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/CustomBiomes.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/CustomBiomes.java new file mode 100644 index 00000000..2b1f5a1b --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/CustomBiomes.java @@ -0,0 +1,151 @@ +package io.github.moulberry.notenoughupdates.miscfeatures.customblockzones; + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.events.OnBlockBreakSoundEffect; +import io.github.moulberry.notenoughupdates.util.SBInfo; +import net.minecraft.block.BlockColored; +import net.minecraft.block.BlockStone; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.init.Blocks; +import net.minecraft.item.EnumDyeColor; +import net.minecraft.util.BlockPos; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import java.util.HashMap; +import java.util.Map; + +public class CustomBiomes { + + public static final CustomBiomes INSTANCE = new CustomBiomes(); + + private Map<String, IslandZoneSubdivider> subdividers = new HashMap<>(); + + private CustomBiomes() { + subdividers.put("crystal_hollows", new CrystalHollowsTextures()); + subdividers.put("mining_3", new DwarvenMinesTextures()); + } + + //Biome Prefix: NeuAreaBiomeName + //Example: NeuCHJungle + + public BiomeGenBase getCustomBiome(BlockPos pos) { + SpecialBlockZone specialZone = getSpecialZone(pos); + if (specialZone != null) { + if ((specialZone.isDwarvenMines() && NotEnoughUpdates.INSTANCE.config.mining.dwarvenTextures) + || (specialZone.isCrystalHollows() && NotEnoughUpdates.INSTANCE.config.mining.crystalHollowTextures)) + return specialZone.getCustomBiome(); + } + return null; + } + + /** + * Finds the special zone for the give block position + * <p> + * Returns null on error + */ + public SpecialBlockZone getSpecialZone(BlockPos pos) { + if (Minecraft.getMinecraft().theWorld == null) return null; + String location = SBInfo.getInstance().getLocation(); + IslandZoneSubdivider subdivider = subdividers.get(location); + if (subdivider == null) return SpecialBlockZone.NON_SPECIAL_ZONE; + return subdivider.getSpecialZoneForBlock(location, pos); + } + + + @SubscribeEvent + public void onBreakSound(OnBlockBreakSoundEffect event) { + SpecialBlockZone specialZone = getSpecialZone(event.getPosition()); + boolean hasMithrilSounds = NotEnoughUpdates.INSTANCE.config.mining.mithrilSounds; + boolean hasCrystalSounds = NotEnoughUpdates.INSTANCE.config.mining.gemstoneSounds; + if (specialZone != null) { + CustomBlockSounds.CustomSoundEvent customSound = null; + if (specialZone.hasMithril() && isBreakableMithril(event.getBlock()) && hasMithrilSounds && SBInfo.getInstance().getLocation().equals("mining_3")) { + customSound = CustomBlockSounds.mithrilBreak; + } + if (specialZone.hasMithril() && isMithrilHollows(event.getBlock()) && hasMithrilSounds && SBInfo.getInstance().getLocation().equals("crystal_hollows")) { + customSound = CustomBlockSounds.mithrilBreak; + } + if (specialZone.hasTitanium() && isTitanium(event.getBlock()) && hasMithrilSounds) { + customSound = CustomBlockSounds.titaniumBreak; + } + + if (specialZone.hasGemstones() && isGemstone(event.getBlock(), EnumDyeColor.RED) && hasCrystalSounds) { + customSound = CustomBlockSounds.gemstoneBreakRuby; + } + if (specialZone.hasGemstones() && isGemstone(event.getBlock(), EnumDyeColor.YELLOW) && hasCrystalSounds) { + customSound = CustomBlockSounds.gemstoneBreakTopaz; + } + if (specialZone.hasGemstones() && isGemstone(event.getBlock(), EnumDyeColor.PINK) && hasCrystalSounds) { + customSound = CustomBlockSounds.gemstoneBreakJasper; + } + if (specialZone.hasGemstones() && isGemstone(event.getBlock(), EnumDyeColor.LIGHT_BLUE) && hasCrystalSounds) { + customSound = CustomBlockSounds.gemstoneBreakSapphire; + } + if (specialZone.hasGemstones() && isGemstone(event.getBlock(), EnumDyeColor.ORANGE) && hasCrystalSounds) { + customSound = CustomBlockSounds.gemstoneBreakAmber; + } + if (specialZone.hasGemstones() && isGemstone(event.getBlock(), EnumDyeColor.PURPLE) && hasCrystalSounds) { + customSound = CustomBlockSounds.gemstoneBreakAmethyst; + } + if (specialZone.hasGemstones() && isGemstone(event.getBlock(), EnumDyeColor.LIME) && hasCrystalSounds) { + customSound = CustomBlockSounds.gemstoneBreakJade; + } + + if (customSound != null) { + if (customSound.shouldReplace()) { + event.setSound(customSound.replaceSoundEvent(event.getSound())); + } else { + event.setCanceled(true); + } + } + } + } + + public static boolean isTitanium(IBlockState state) { + return state.getBlock() == Blocks.stone && state.getValue(BlockStone.VARIANT) == BlockStone.EnumType.DIORITE_SMOOTH; + } + + public static boolean isMithril(IBlockState state) { + return isBreakableMithril(state) + || state.getBlock() == Blocks.bedrock; + } + + public static boolean isBreakableMithril(IBlockState state) { + return (state.getBlock() == Blocks.stained_hardened_clay && state.getValue(BlockColored.COLOR) == EnumDyeColor.CYAN) + || (state.getBlock() == Blocks.wool && state.getValue(BlockColored.COLOR) == EnumDyeColor.GRAY) + || (state.getBlock() == Blocks.wool && state.getValue(BlockColored.COLOR) == EnumDyeColor.LIGHT_BLUE) + || state.getBlock() == Blocks.prismarine; + } + + public static boolean isMithrilHollows(IBlockState state) { + return state.getBlock() == Blocks.prismarine + || (state.getBlock() == Blocks.wool && state.getValue(BlockColored.COLOR) == EnumDyeColor.LIGHT_BLUE); + } + + public static boolean isGemstone(IBlockState state, EnumDyeColor color) { + return ((state.getBlock() == Blocks.stained_glass || state.getBlock() == Blocks.stained_glass_pane) && state.getValue(BlockColored.COLOR) == color); + } + + @SubscribeEvent + public void onLocationChange(LocationChangeEvent event) { + WorldClient world = Minecraft.getMinecraft().theWorld; + String location = event.newLocation; + if (world == null) return; + if (location == null) return; + switch (location.intern()) { + case "crystal_hollows": + case "mining_3": + //if has custom biome, do chunk update or something + EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; + if (player == null) return; + + world.markBlocksDirtyVertical((int) player.posX, (int) player.posX, (int) player.posZ, (int) player.posZ); + } + } + + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/CustomBlockSounds.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/CustomBlockSounds.java new file mode 100644 index 00000000..45f22163 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/CustomBlockSounds.java @@ -0,0 +1,102 @@ +package io.github.moulberry.notenoughupdates.miscfeatures.customblockzones; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.ISound; +import net.minecraft.client.audio.PositionedSoundRecord; +import net.minecraft.client.resources.IResource; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.client.resources.IResourceManagerReloadListener; +import net.minecraft.util.ResourceLocation; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +public class CustomBlockSounds { + + static Gson gson = new Gson(); + + static List<CustomSoundEvent> allCustomSoundEvents = new ArrayList<>(); + + public static final CustomSoundEvent mithrilBreak = newCustomSoundEvent("mithril"); + public static final CustomSoundEvent gemstoneBreakRuby = newCustomSoundEvent("gemstoneRuby"); + public static final CustomSoundEvent gemstoneBreakAmber = newCustomSoundEvent("gemstoneAmber"); + public static final CustomSoundEvent gemstoneBreakAmethyst = newCustomSoundEvent("gemstoneAmethyst"); + public static final CustomSoundEvent gemstoneBreakSapphire = newCustomSoundEvent("gemstoneSapphire"); + public static final CustomSoundEvent gemstoneBreakJade = newCustomSoundEvent("gemstoneJade"); + public static final CustomSoundEvent gemstoneBreakTopaz = newCustomSoundEvent("gemstoneTopaz"); + public static final CustomSoundEvent gemstoneBreakJasper = newCustomSoundEvent("gemstoneJasper"); + public static final CustomSoundEvent titaniumBreak = newCustomSoundEvent("titanium"); + + + public static class ReloaderListener implements IResourceManagerReloadListener { + @Override + public void onResourceManagerReload(IResourceManager iResourceManager) { + allCustomSoundEvents.forEach(CustomSoundEvent::reload); + } + } + + public static class CustomSoundEvent { + public ResourceLocation soundEvent; + public ResourceLocation configFile; + private boolean loaded = false; + private int timer = 0; + private long lastReplaced = 0L; + + public CustomSoundEvent() { + allCustomSoundEvents.add(this); + } + + public boolean shouldReplace() { + if (!loaded) reload(); + if (timer < 0) return true; + long now = System.currentTimeMillis(); + if (now - lastReplaced >= timer) { + lastReplaced = now; + return true; + } + return false; + } + + public ISound replaceSoundEvent(ISound sound) { + return new PositionedSoundRecord( + this.soundEvent, + sound.getPitch(), sound.getVolume(), + sound.getXPosF(), sound.getYPosF(), sound.getZPosF() + ); + } + + public void reload() { + loaded = true; + IResource resource; + try { + resource = Minecraft.getMinecraft().getResourceManager().getResource(configFile); + } catch (IOException e) { + timer = -1; + return; + } + try (Reader r = new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8)) { + JsonObject jsonObject = gson.fromJson(r, JsonObject.class); + timer = jsonObject.getAsJsonPrimitive("debouncer").getAsInt() * 1000 / 20; + } catch (IOException e) { + e.printStackTrace(); + } + } + + } + + private static CustomSoundEvent newCustomSoundEvent(String soundEvent) { + CustomSoundEvent event = new CustomSoundEvent(); + event.soundEvent = new ResourceLocation("notenoughupdates", soundEvent + ".break"); + event.configFile = new ResourceLocation("notenoughupdates", "sounds/" + soundEvent.toLowerCase(Locale.ROOT) + "break.json"); + return event; + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/DwarvenMinesTextures.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/DwarvenMinesTextures.java new file mode 100644 index 00000000..4a25c4af --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/DwarvenMinesTextures.java @@ -0,0 +1,191 @@ +package io.github.moulberry.notenoughupdates.miscfeatures.customblockzones; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.init.Blocks; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.ChunkCoordIntPair; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import static io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBiomes.isMithril; +import static io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBiomes.isTitanium; + +public class DwarvenMinesTextures implements IslandZoneSubdivider { + + private static class IgnoreColumn { + boolean always; + int minY; + int maxY; + + public IgnoreColumn(boolean always, int minY, int maxY) { + this.always = always; + this.minY = minY; + this.maxY = maxY; + } + } + + private Set<ChunkCoordIntPair> ignoredChunks = null; + private final Map<ChunkCoordIntPair, Map<ChunkCoordIntPair, IgnoreColumn>> loadedChunkData = new HashMap<>(); + private boolean error = false; + + private IBlockState getBlock(BlockPos pos) { + return Minecraft.getMinecraft().theWorld.getBlockState(pos); + } + + + private boolean isDoubleSlab(IBlockState state) { + return state.getBlock() == Blocks.double_stone_slab; + } + + + private Reader getUTF8Resource(ResourceLocation location) throws IOException { + return new BufferedReader(new InputStreamReader(Minecraft.getMinecraft().getResourceManager().getResource(location).getInputStream(), StandardCharsets.UTF_8)); + } + + private void loadIgnoredChunks() { + ignoredChunks = new HashSet<>(); + try (Reader reader = getUTF8Resource(new ResourceLocation("notenoughupdates:dwarven_data/all.json"))) { + JsonObject json = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(reader, JsonObject.class); + for (Map.Entry<String, JsonElement> entry : json.entrySet()) { + String coord = entry.getKey(); + String[] split = coord.split("_"); + int left = Integer.parseInt(split[0]); + int right = Integer.parseInt(split[1]); + ignoredChunks.add(new ChunkCoordIntPair(left, right)); + } + } catch (IOException e) { + ignoredChunks = null; + error = true; + System.out.println("NEU failed to load dwarven mines ignore chunks: "); + e.printStackTrace(); + } + } + + private Set<ChunkCoordIntPair> getIgnoredChunks() { + if (ignoredChunks == null) + synchronized (this) { + if (ignoredChunks != null) return ignoredChunks; + loadIgnoredChunks(); + } + return ignoredChunks; + } + + private IgnoreColumn parseIgnoreColumn(JsonElement element) { + if (element.isJsonPrimitive()) { + JsonPrimitive prim = element.getAsJsonPrimitive(); + if (prim.isBoolean()) { + return new IgnoreColumn(true, 0, 0); + } else if (prim.isNumber()) { + int y = prim.getAsInt(); + return new IgnoreColumn(false, y, y); + } + } + if (element.isJsonArray()) { + JsonArray arr = element.getAsJsonArray(); + if (arr.size() == 2) { + int min = arr.get(0).getAsInt(); + int max = arr.get(1).getAsInt(); + return new IgnoreColumn(false, min, max); + } + } + return null; + } + + private Map<ChunkCoordIntPair, IgnoreColumn> loadChunkData(ChunkCoordIntPair pair) { + Map<ChunkCoordIntPair, IgnoreColumn> map = new HashMap<>(); + try { + ResourceLocation loc = new ResourceLocation("notenoughupdates:dwarven_data/" + + pair.chunkXPos + "_" + pair.chunkZPos + ".json"); + + try (Reader reader = getUTF8Resource(loc)) { + JsonObject json = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(reader, JsonObject.class); + for (Map.Entry<String, JsonElement> entry : json.entrySet()) { + String coord = entry.getKey(); + String[] split = coord.split(":"); + int left = Integer.parseInt(split[0]); + int right = Integer.parseInt(split[1]); + + IgnoreColumn ignore = parseIgnoreColumn(entry.getValue()); + if (ignore != null) { + ChunkCoordIntPair offset = new ChunkCoordIntPair(left, right); + map.put(offset, ignore); + } + } + } + } catch (Exception e) { + } + return map; + } + + private Map<ChunkCoordIntPair, IgnoreColumn> getChunkData(ChunkCoordIntPair chunkCoordinates) { + synchronized (this) { + return loadedChunkData.computeIfAbsent(chunkCoordinates, this::loadChunkData); + } + } + + @Override + public SpecialBlockZone getSpecialZoneForBlock(String location, BlockPos pos) { + if (error) return null; + IBlockState block = getBlock(pos); + boolean isTitanium = isTitanium(block); + boolean isMithril = isMithril(block); + if (isTitanium) { + for (EnumFacing direction : EnumFacing.values()) + if (isDoubleSlab(getBlock(pos.offset(direction)))) + return SpecialBlockZone.DWARVEN_MINES_NON_MITHRIL; + } + if (!isMithril && !isTitanium) return SpecialBlockZone.DWARVEN_MINES_NON_MITHRIL; + + Set<ChunkCoordIntPair> ignoredChunks = getIgnoredChunks(); + if (ignoredChunks == null) + return null; + ChunkCoordIntPair pair = new ChunkCoordIntPair( + MathHelper.floor_float(pos.getX() / 16f), + MathHelper.floor_float(pos.getZ() / 16f)); + + if (ignoredChunks.contains(pair)) { + return SpecialBlockZone.DWARVEN_MINES_NON_MITHRIL; + } + if (isTitanium) { + return SpecialBlockZone.DWARVEN_MINES_MITHRIL; + } + + Map<ChunkCoordIntPair, IgnoreColumn> chunkData = getChunkData(pair); + if (chunkData == null || error) return null; + + int modX = pos.getX() % 16; + int modZ = pos.getZ() % 16; + if (modX < 0) modX += 16; + if (modZ < 0) modZ += 16; + ChunkCoordIntPair subChunkCoordinates = new ChunkCoordIntPair(modX, modZ); + + IgnoreColumn ignore = chunkData.get(subChunkCoordinates); + if (ignore != null) { + if (ignore.always) { + return SpecialBlockZone.DWARVEN_MINES_NON_MITHRIL; + } + int y = pos.getY(); + if (ignore.minY <= y && y <= ignore.maxY) { + return SpecialBlockZone.DWARVEN_MINES_NON_MITHRIL; + } + } + return SpecialBlockZone.DWARVEN_MINES_MITHRIL; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/IslandZoneSubdivider.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/IslandZoneSubdivider.java new file mode 100644 index 00000000..72278894 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/IslandZoneSubdivider.java @@ -0,0 +1,7 @@ +package io.github.moulberry.notenoughupdates.miscfeatures.customblockzones; + +import net.minecraft.util.BlockPos; + +public interface IslandZoneSubdivider { + SpecialBlockZone getSpecialZoneForBlock(String location, BlockPos position); +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/LocationChangeEvent.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/LocationChangeEvent.java new file mode 100644 index 00000000..b4217b27 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/LocationChangeEvent.java @@ -0,0 +1,13 @@ +package io.github.moulberry.notenoughupdates.miscfeatures.customblockzones; + +import net.minecraftforge.fml.common.eventhandler.Event; + +public class LocationChangeEvent extends Event { + public final String newLocation; + public final String oldLocation; + public LocationChangeEvent(String newLocation, String oldLocation) + { + this.newLocation = newLocation; + this.oldLocation = oldLocation; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/SpecialBlockZone.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/SpecialBlockZone.java new file mode 100644 index 00000000..403e5b9b --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/SpecialBlockZone.java @@ -0,0 +1,60 @@ +package io.github.moulberry.notenoughupdates.miscfeatures.customblockzones; + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import net.minecraft.world.biome.BiomeGenBase; + +public enum SpecialBlockZone { + DWARVEN_MINES_NON_MITHRIL(BiomeGenBase.extremeHillsPlus, false, false, false, true, false), + DWARVEN_MINES_MITHRIL(BiomeGenBase.extremeHillsEdge, true, true, false, true, false), + CRYSTAL_HOLLOWS_MAGMA_FIELDS(NotEnoughUpdates.crystalHollowsMagmaFields, true, false, true, false, true), + CRYSTAL_HOLLOWS_NUCLEUS(NotEnoughUpdates.crystalHollowsCrystalNucleus, true, false, true, false, true), + CRYSTAL_HOLLOWS_JUNGLE(NotEnoughUpdates.crystalHollowsJungle, true, false, true, false, true), + CRYSTAL_HOLLOWS_GOBLIN_HIDEOUT(NotEnoughUpdates.crystalHollowsGoblinHoldout, true, false, true, false, true), + CRYSTAL_HOLLOWS_MITHRIL_DEPOSIT(NotEnoughUpdates.crystalHollowsMithrilDeposit, true, false, true, false, true), + CRYSTAL_HOLLOWS_PRECURSOR_REMNANTS(NotEnoughUpdates.crystalHollowsPrecursorRemnants, true, false, true, false, true), + NON_SPECIAL_ZONE(null, false, false, false, false, false); + + private final BiomeGenBase customBiome; + private final boolean hasMithril; + private final boolean hasTitanium; + private final boolean hasGemstones; + private final boolean isDwarvenMines; + private final boolean isCrystalHollows; + + SpecialBlockZone(BiomeGenBase customBiome, boolean hasMithril, boolean hasTitanium, boolean hasGemstones, boolean isDwarvenMines, boolean isCrystalHollows) { + this.customBiome = customBiome; + this.hasMithril = hasMithril; + this.hasTitanium = hasTitanium; + this.hasGemstones = hasGemstones; + this.isDwarvenMines = isDwarvenMines; + this.isCrystalHollows = isCrystalHollows; + } + + public BiomeGenBase getCustomBiome() { + return customBiome; + } + + public boolean hasMithril() { + return hasMithril; + } + + public boolean hasTitanium() { + return hasTitanium; + } + + public boolean hasGemstones() { + return hasGemstones; + } + + public boolean isDwarvenMines() { + return isDwarvenMines; + } + + public boolean isCrystalHollows() { + return isCrystalHollows; + } + + public boolean isMiningZone() { + return isCrystalHollows || isDwarvenMines; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinPlayerControllerMP.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinPlayerControllerMP.java index 78130cb4..969b5b88 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinPlayerControllerMP.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinPlayerControllerMP.java @@ -1,12 +1,17 @@ package io.github.moulberry.notenoughupdates.mixins; +import io.github.moulberry.notenoughupdates.events.OnBlockBreakSoundEffect; import io.github.moulberry.notenoughupdates.miscfeatures.ItemCooldowns; +import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.ISound; +import net.minecraft.client.audio.SoundHandler; import net.minecraft.client.multiplayer.PlayerControllerMP; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(PlayerControllerMP.class) @@ -19,4 +24,13 @@ public class MixinPlayerControllerMP { ((PlayerControllerMP)(Object)this).resetBlockRemoving(); }*/ } + + @Redirect(method = "onPlayerDamageBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/audio/SoundHandler;playSound(Lnet/minecraft/client/audio/ISound;)V")) + public void onPlayerDamageBlock(SoundHandler instance, ISound p_playSound_1_, BlockPos p_onPlayerDamageBlock_1_, EnumFacing p_onPlayerDamageBlock_2_) { + OnBlockBreakSoundEffect onBlockBreakSoundEffect = new OnBlockBreakSoundEffect(p_playSound_1_, p_onPlayerDamageBlock_1_, Minecraft.getMinecraft().theWorld.getBlockState(p_onPlayerDamageBlock_1_)); + if (!onBlockBreakSoundEffect.post()) { + instance.playSound(onBlockBreakSoundEffect.getSound()); + } + } + } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinWorld.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinWorld.java index 30b217db..3cee3564 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinWorld.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinWorld.java @@ -1,8 +1,8 @@ package io.github.moulberry.notenoughupdates.mixins; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBiomes; import io.github.moulberry.notenoughupdates.miscfeatures.CustomItemEffects; -import io.github.moulberry.notenoughupdates.miscfeatures.DwarvenMinesTextures; import net.minecraft.util.BlockPos; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; @@ -27,13 +27,10 @@ public class MixinWorld { @Inject(method = "getBiomeGenForCoords", at = @At("HEAD"), cancellable = true) public void getBiomeGenForCoords(BlockPos pos, CallbackInfoReturnable<BiomeGenBase> cir) { - int retexture = DwarvenMinesTextures.retexture(pos); - if (retexture == 1) { - cir.setReturnValue(BiomeGenBase.extremeHillsPlus); - } else if (retexture == 2) { - cir.setReturnValue(BiomeGenBase.extremeHillsEdge); - } else if (retexture == 3) { - cir.setReturnValue(BiomeGenBase.coldBeach); + BiomeGenBase customBiome = CustomBiomes.INSTANCE.getCustomBiome(pos); + if(customBiome != null){ + cir.setReturnValue(customBiome); } + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java index 2b0c42f7..c5580011 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java @@ -492,11 +492,46 @@ public class Mining { @ConfigEditorBoolean
public boolean titaniumAlertMustBeVisible = false;
+ @ConfigOption(
+ name = "Custom Textures",
+ desc = ""
+ )
+ @ConfigEditorAccordion(id = 7)
+ public boolean texturesAccordion = false;
+
@Expose
@ConfigOption(
name = "Dwarven Mines Textures",
- desc = "Allows texture packs to retexture blocks in the Dwarven Mines. If you don't have a texturepack that does this, you should leave this off"
+ desc = "Allows texture packs to retexture blocks in the Dwarven Mines. If you don't have a texture pack that does this, you should leave this off"
)
+ @ConfigAccordionId(id = 7)
@ConfigEditorBoolean
public boolean dwarvenTextures = false;
+ @Expose
+ @ConfigOption(
+ name = "Crystal Hollows Textures",
+ desc = "Allows texture packs to retexture blocks in the Crystal Hollows. If you don't have a texture pack that does this, you should leave this off"
+ )
+ @ConfigAccordionId(id = 7)
+ @ConfigEditorBoolean
+ public boolean crystalHollowTextures = false;
+
+ @Expose
+ @ConfigOption(
+ name = "Replace Gemstone sounds",
+ desc = "Replace the break sounds of crystals in the Crystal Hollows. Requires a texture pack with this feature"
+ )
+ @ConfigAccordionId(id = 7)
+ @ConfigEditorBoolean
+ public boolean gemstoneSounds = false;
+
+ @Expose
+ @ConfigOption(
+ name = "Replace Mithril sounds",
+ desc = "Replace the break sounds of mithril and titanium in the Dwarven mines. Requires a texture pack with this feature"
+ )
+ @ConfigAccordionId(id = 7)
+ @ConfigEditorBoolean
+ public boolean mithrilSounds = false;
+
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java b/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java index 008738fd..6dcd284e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java @@ -2,6 +2,7 @@ package io.github.moulberry.notenoughupdates.util; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.LocationChangeEvent; import io.github.moulberry.notenoughupdates.overlays.SlayerOverlay; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiChest; @@ -14,6 +15,7 @@ import net.minecraft.scoreboard.Scoreboard; import net.minecraft.util.IChatComponent; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.client.event.GuiOpenEvent; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -23,6 +25,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -77,7 +80,7 @@ public class SBInfo { public void onWorldLoad(WorldEvent.Load event) { lastLocRaw = -1; locraw = null; - mode = null; + this.setLocation(null); joinedWorld = System.currentTimeMillis(); lastOpenContainerName = ""; hasNewTab = false; @@ -106,7 +109,7 @@ public class SBInfo { if (System.currentTimeMillis() - lastManualLocRaw > 5000) event.setCanceled(true); if (obj.has("gametype") && obj.has("mode") && obj.has("map")) { locraw = obj; - mode = locraw.get("mode").getAsString(); + setLocation(locraw.get("mode").getAsString()); } } } catch (Exception e) { @@ -116,12 +119,16 @@ public class SBInfo { } public String getLocation() { - if (mode == null) { - return null; - } return mode; } + public void setLocation(String location) { + if (!Objects.equals(this.mode, location)) { + MinecraftForge.EVENT_BUS.post(new LocationChangeEvent(location, this.mode)); + } + this.mode = location; + } + private static final String profilePrefix = "\u00a7r\u00a7e\u00a7lProfile: \u00a7r\u00a7a"; private static final String skillsPrefix = "\u00a7r\u00a7e\u00a7lSkills: \u00a7r\u00a7a"; @@ -154,7 +161,8 @@ public class SBInfo { try { int level = Integer.parseInt(matcher.group(2).trim()); XPInformation.getInstance().updateLevel(matcher.group(1).toLowerCase().trim(), level); - } catch (Exception ignored) {} + } catch (Exception ignored) { + } } } } @@ -204,13 +212,17 @@ public class SBInfo { if (SlayerOverlay.slayerQuest) { if (line.contains(" I")) { SlayerOverlay.slayerTier = 1; - } if (line.contains(" II")) { + } + if (line.contains(" II")) { SlayerOverlay.slayerTier = 2; - } if (line.contains(" III")) { + } + if (line.contains(" III")) { SlayerOverlay.slayerTier = 3; - } if (line.contains(" IV")) { + } + if (line.contains(" IV")) { SlayerOverlay.slayerTier = 4; - } if (line.contains(" V")) { + } + if (line.contains(" V")) { SlayerOverlay.slayerTier = 5; } } @@ -226,7 +238,8 @@ public class SBInfo { String timeSpace = time.replace("am", " am").replace("pm", " pm"); SimpleDateFormat parseFormat = new SimpleDateFormat("hh:mm a"); currentTimeDate = parseFormat.parse(timeSpace); - } catch (ParseException ignored) {} + } catch (ParseException ignored) { + } } //Replaced with for loop because in crystal hollows with events the line it's on can shift. for (String line : lines) { |