diff --git a/.gitignore b/.gitignore index 6bdd20d59..aee4667e5 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ !/minecraft # github +!/.gitattributes !/.gitignore !/README.md diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/asm/StaticForwarder.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/asm/StaticForwarder.java index 504b4261c..932c004db 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/asm/StaticForwarder.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/asm/StaticForwarder.java @@ -24,10 +24,15 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.chunk.Chunk; +import nova.core.component.misc.FactoryProvider; import nova.core.event.BlockEvent; import nova.core.wrapper.mc.forge.v17.launcher.NovaMinecraft; +import nova.core.wrapper.mc.forge.v17.wrapper.block.backward.BWBlock; +import nova.core.wrapper.mc.forge.v17.wrapper.block.forward.FWBlock; import nova.core.wrapper.mc.forge.v17.wrapper.block.forward.FWTile; import nova.core.wrapper.mc.forge.v17.wrapper.block.forward.FWTileLoader; +import nova.core.wrapper.mc.forge.v17.wrapper.block.forward.MCBlockTransform; +import nova.core.wrapper.mc.forge.v17.wrapper.block.world.WorldConverter; import nova.internal.core.Game; import nova.internal.core.launch.NovaLauncher; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; @@ -41,8 +46,31 @@ public class StaticForwarder { private StaticForwarder() {} public static void chunkSetBlockEvent(Chunk chunk, int x, int y, int z, Block oldBlock, int oldMeta, Block newBlock, int newMeta) { + nova.core.world.World world = WorldConverter.instance().toNova(chunk.worldObj); + Vector3D position = new Vector3D((chunk.xPosition << 4) + x, y, (chunk.zPosition << 4) + z); + nova.core.block.Block oldBlockInstance; + nova.core.block.Block newBlockInstance; + + if (oldBlock instanceof FWBlock) { + oldBlockInstance = ((FWBlock) oldBlock).getFactory().build(); + oldBlockInstance.components.add(new MCBlockTransform(oldBlockInstance, world, position)); + } else { + oldBlockInstance = new BWBlock(oldBlock, world, position); + Game.blocks().get(net.minecraft.block.Block.blockRegistry.getNameForObject(oldBlock)) + .ifPresent(blockFactory -> oldBlockInstance.components.getOrAdd(new FactoryProvider(blockFactory))); + } + + if (newBlock instanceof FWBlock) { + newBlockInstance = ((FWBlock) newBlock).getFactory().build(); + newBlockInstance.components.add(new MCBlockTransform(newBlockInstance, world, position)); + } else { + newBlockInstance = new BWBlock(newBlock, world, position); + Game.blocks().get(net.minecraft.block.Block.blockRegistry.getNameForObject(newBlock)) + .ifPresent(blockFactory -> newBlockInstance.components.getOrAdd(new FactoryProvider(blockFactory))); + } + // Publish the event - Game.events().publish(new BlockEvent.Change(Game.natives().toNova(chunk.worldObj), new Vector3D((chunk.xPosition << 4) + x, y, (chunk.zPosition << 4) + z), Game.natives().toNova(oldBlock), Game.natives().toNova(newBlock))); + Game.events().publish(new BlockEvent.Change(world, position, oldBlockInstance, newBlockInstance)); } /** diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/manager/MCRetentionManager.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/manager/MCRetentionManager.java index b1e5e92ed..4caca4e6e 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/manager/MCRetentionManager.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/manager/MCRetentionManager.java @@ -45,7 +45,7 @@ public class MCRetentionManager extends RetentionManager { /** * Last time that the queueSave manager tried to queueSave a file */ - private long lastSaveMills = 0; + private long lastSaveTime = 0; /** * Save all storable queued @@ -156,8 +156,8 @@ public File getBaseDirectory() { @SubscribeEvent public void worldSave(WorldEvent evt) { //Current time milli-seconds is used to prevent the files from saving 20 times when the world loads - if (System.currentTimeMillis() - lastSaveMills > 2000) { - lastSaveMills = System.currentTimeMillis(); + if (System.nanoTime() - lastSaveTime > 2_000_000_000) { + lastSaveTime = System.nanoTime(); saveAll(); } } diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/BlockConverter.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/BlockConverter.java index d6b6c5b55..d60806686 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/BlockConverter.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/BlockConverter.java @@ -20,6 +20,8 @@ package nova.core.wrapper.mc.forge.v17.wrapper.block; +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.registry.GameRegistry; @@ -35,29 +37,28 @@ import nova.core.wrapper.mc.forge.v17.launcher.NovaMinecraft; import nova.core.wrapper.mc.forge.v17.wrapper.CategoryConverter; import nova.core.wrapper.mc.forge.v17.wrapper.block.backward.BWBlock; +import nova.core.wrapper.mc.forge.v17.wrapper.block.backward.BWBlockFactory; import nova.core.wrapper.mc.forge.v17.wrapper.block.forward.FWBlock; import nova.core.wrapper.mc.forge.v17.wrapper.item.FWItemBlock; import nova.internal.core.Game; import nova.internal.core.launch.NovaLauncher; -import java.util.HashMap; - /** * @author Calclavia */ -public class BlockConverter implements NativeConverter, ForgeLoadable { +public class BlockConverter implements NativeConverter, ForgeLoadable { /** * A map of all blockFactory to MC blocks registered */ - public final HashMap blockFactoryMap = new HashMap<>(); + public final BiMap blockFactoryMap = HashBiMap.create(); public static BlockConverter instance() { - return Game.natives().getNative(Block.class, net.minecraft.block.Block.class); + return Game.natives().getNative(BlockFactory.class, net.minecraft.block.Block.class); } @Override - public Class getNovaSide() { - return Block.class; + public Class getNovaSide() { + return BlockFactory.class; } @Override @@ -66,20 +67,19 @@ public Class getNativeSide() { } @Override - public Block toNova(net.minecraft.block.Block nativeBlock) { + public BlockFactory toNova(net.minecraft.block.Block nativeBlock) { //Prevent recursive wrapping if (nativeBlock instanceof FWBlock) { - return ((FWBlock) nativeBlock).dummy; + return ((FWBlock) nativeBlock).getFactory(); } if (nativeBlock == Blocks.air) { - return Game.blocks().getAirBlock().build(); + return Game.blocks().getAirBlock(); } - return new BWBlock(nativeBlock); + return blockFactoryMap.inverse().get(nativeBlock); } - @Override public net.minecraft.block.Block toNative(Block novaBlock) { //Prevent recursive wrapping if (novaBlock instanceof BWBlock) { @@ -89,12 +89,15 @@ public net.minecraft.block.Block toNative(Block novaBlock) { return toNative(novaBlock.getFactory()); } + @Override public net.minecraft.block.Block toNative(BlockFactory blockFactory) { return blockFactoryMap.get(blockFactory); } /** * Register all Nova blocks + * + * @param evt The Minecraft Forge pre-initialization event */ @Override public void preInit(FMLPreInitializationEvent evt) { @@ -102,16 +105,11 @@ public void preInit(FMLPreInitializationEvent evt) { registerNOVAToMinecraft(); } + @SuppressWarnings("unchecked") private void registerMinecraftToNOVA() { //TODO: Will this register ALL Forge mod blocks as well? BlockManager blockManager = Game.blocks(); - net.minecraft.block.Block.blockRegistry.forEach(obj -> - blockManager.register( - new BlockFactory(net.minecraft.block.Block.blockRegistry.getNameForObject(obj).toString(), - () -> new BWBlock((net.minecraft.block.Block) obj), evt -> { - }) - ) - ); + net.minecraft.block.Block.blockRegistry.forEach(block -> blockManager.register(new BWBlockFactory((net.minecraft.block.Block) block))); } private void registerNOVAToMinecraft() { diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/backward/BWBlockFactory.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/backward/BWBlockFactory.java new file mode 100644 index 000000000..f12922ba5 --- /dev/null +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/backward/BWBlockFactory.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2017 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ +package nova.core.wrapper.mc.forge.v17.wrapper.block.backward; + +import net.minecraft.block.Block; +import nova.core.block.BlockFactory; + +/** + * @author ExE Boss + */ +public class BWBlockFactory extends BlockFactory { + + private final Block block; + + public BWBlockFactory(Block block) { + super(Block.blockRegistry.getNameForObject(block), () -> new BWBlock(block), factory -> {}); + this.block = block; + } + + public Block getBlock() { + return block; + } + + @Override + public String getLocalizedName() { + return getBlock().getLocalizedName(); + } + + @Override + public String getUnlocalizedName() { + return getBlock().getUnlocalizedName(); + } +} diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/recipes/MinecraftRecipeRegistry.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/recipes/MinecraftRecipeRegistry.java index 1840c1131..78049baef 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/recipes/MinecraftRecipeRegistry.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/recipes/MinecraftRecipeRegistry.java @@ -61,7 +61,7 @@ private MinecraftRecipeRegistry() { } public void registerRecipes() { - long startTime = System.currentTimeMillis(); + long startTime = System.nanoTime(); RecipeManager recipeManager = Game.recipes(); @@ -78,7 +78,7 @@ public void registerRecipes() { ReflectionUtil.setCraftingRecipeList(new RecipeListWrapper(recipes)); - Game.logger().info("Initialized recipes in {} ms", (System.currentTimeMillis() - startTime)); + Game.logger().info("Initialized recipes in {} ms", (System.nanoTime() - startTime) / 1_000_000); recipeManager.whenRecipeAdded(CraftingRecipe.class, this::onNOVARecipeAdded); recipeManager.whenRecipeRemoved(CraftingRecipe.class, this::onNOVARecipeRemoved); diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/asm/StaticForwarder.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/asm/StaticForwarder.java index 3dc9b0a76..8f814952b 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/asm/StaticForwarder.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/asm/StaticForwarder.java @@ -25,14 +25,22 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.world.chunk.Chunk; +import nova.core.block.Block; +import nova.core.component.misc.FactoryProvider; import nova.core.event.BlockEvent; import nova.core.wrapper.mc.forge.v18.launcher.NovaMinecraft; +import nova.core.wrapper.mc.forge.v18.wrapper.block.backward.BWBlock; +import nova.core.wrapper.mc.forge.v18.wrapper.block.forward.FWBlock; import nova.core.wrapper.mc.forge.v18.wrapper.block.forward.FWTile; import nova.core.wrapper.mc.forge.v18.wrapper.block.forward.FWTileLoader; +import nova.core.wrapper.mc.forge.v18.wrapper.block.forward.MCBlockTransform; +import nova.core.wrapper.mc.forge.v18.wrapper.block.world.WorldConverter; import nova.internal.core.Game; import nova.internal.core.launch.NovaLauncher; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; +import java.util.Objects; + /** * Static forwarder forwards injected methods. * @author Calclavia @@ -42,14 +50,31 @@ public class StaticForwarder { private StaticForwarder() {} public static void chunkSetBlockEvent(Chunk chunk, BlockPos pos, IBlockState oldBlockState, IBlockState newBlockState) { + nova.core.world.World world = WorldConverter.instance().toNova(chunk.getWorld()); + Vector3D position = new Vector3D((chunk.xPosition << 4) + pos.getX(), pos.getY(), (chunk.zPosition << 4) + pos.getZ()); + Block oldBlockInstance; + Block newBlockInstance; + + if (oldBlockState.getBlock() instanceof FWBlock) { + oldBlockInstance = ((FWBlock) oldBlockState.getBlock()).getFactory().build(); + oldBlockInstance.components.add(new MCBlockTransform(oldBlockInstance, world, position)); + } else { + oldBlockInstance = new BWBlock(oldBlockState.getBlock(), world, position); + Game.blocks().get(Objects.toString(net.minecraft.block.Block.blockRegistry.getNameForObject(oldBlockState.getBlock()))) + .ifPresent(blockFactory -> oldBlockInstance.components.getOrAdd(new FactoryProvider(blockFactory))); + } + + if (newBlockState.getBlock() instanceof FWBlock) { + newBlockInstance = ((FWBlock) newBlockState.getBlock()).getFactory().build(); + oldBlockInstance.components.add(new MCBlockTransform(oldBlockInstance, world, position)); + } else { + newBlockInstance = new BWBlock(newBlockState.getBlock()); + Game.blocks().get(Objects.toString(net.minecraft.block.Block.blockRegistry.getNameForObject(newBlockState.getBlock()))) + .ifPresent(blockFactory -> newBlockInstance.components.getOrAdd(new FactoryProvider(blockFactory))); + } + // Publish the event - Game.events().publish( - new BlockEvent.Change( - Game.natives().toNova(chunk.getWorld()), - new Vector3D((chunk.xPosition << 4) + pos.getX(), pos.getY(), (chunk.zPosition << 4) + pos.getZ()), - Game.natives().toNova(oldBlockState.getBlock()), Game.natives().toNova(newBlockState.getBlock()) - ) - ); + Game.events().publish(new BlockEvent.Change(world, position, oldBlockInstance, newBlockInstance)); } /** diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/manager/MCRetentionManager.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/manager/MCRetentionManager.java index e53989a76..1c4778066 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/manager/MCRetentionManager.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/manager/MCRetentionManager.java @@ -45,7 +45,7 @@ public class MCRetentionManager extends RetentionManager { /** * Last time that the queueSave manager tried to queueSave a file */ - private long lastSaveMills = 0; + private long lastSaveTime = 0; /** * Save all storable queued @@ -156,8 +156,8 @@ public File getBaseDirectory() { @SubscribeEvent public void worldSave(WorldEvent evt) { //Current time milli-seconds is used to prevent the files from saving 20 times when the world loads - if (System.currentTimeMillis() - lastSaveMills > 2000) { - lastSaveMills = System.currentTimeMillis(); + if (System.nanoTime() - lastSaveTime > 2_000_000_000) { + lastSaveTime = System.nanoTime(); saveAll(); } } diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/render/RenderUtility.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/render/RenderUtility.java index a878336c3..8a1467d5e 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/render/RenderUtility.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/render/RenderUtility.java @@ -23,9 +23,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.block.model.FaceBakery; -import net.minecraft.client.renderer.block.model.ItemModelGenerator; -import net.minecraft.client.renderer.block.model.ModelBlock; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.IResource; import net.minecraft.client.resources.model.ModelResourceLocation; @@ -38,12 +35,12 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import nova.core.component.renderer.Renderer; import nova.core.component.renderer.StaticRenderer; import nova.core.item.ItemFactory; import nova.core.render.texture.Texture; import nova.core.wrapper.mc.forge.v18.launcher.ForgeLoadable; import nova.core.wrapper.mc.forge.v18.wrapper.assets.AssetConverter; +import nova.core.wrapper.mc.forge.v18.wrapper.block.BlockConverter; import nova.core.wrapper.mc.forge.v18.wrapper.block.forward.FWBlock; import nova.core.wrapper.mc.forge.v18.wrapper.item.FWItem; import nova.core.wrapper.mc.forge.v18.wrapper.item.ItemConverter; @@ -188,7 +185,7 @@ private void updateTexureDimensions(Texture texture) { public void onModelBakeEvent(ModelBakeEvent event) { //Register all blocks Game.blocks().registry.forEach(blockFactory -> { - Object blockObj = Game.natives().toNative(blockFactory.build()); + net.minecraft.block.Block blockObj = BlockConverter.instance().toNative(blockFactory); if (blockObj instanceof FWBlock) { FWBlock block = (FWBlock) blockObj; ResourceLocation blockRL = (ResourceLocation) net.minecraft.block.Block.blockRegistry.getNameForObject(block); diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/BlockConverter.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/BlockConverter.java index e50506dec..0bb95ca85 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/BlockConverter.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/BlockConverter.java @@ -20,6 +20,8 @@ package nova.core.wrapper.mc.forge.v18.wrapper.block; +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; import net.minecraft.init.Blocks; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; @@ -36,29 +38,27 @@ import nova.core.wrapper.mc.forge.v18.wrapper.block.backward.BWBlock; import nova.core.wrapper.mc.forge.v18.wrapper.block.forward.FWBlock; import nova.core.wrapper.mc.forge.v18.wrapper.CategoryConverter; +import nova.core.wrapper.mc.forge.v18.wrapper.block.backward.BWBlockFactory; import nova.core.wrapper.mc.forge.v18.wrapper.item.FWItemBlock; import nova.internal.core.Game; import nova.internal.core.launch.NovaLauncher; -import java.util.HashMap; - /** * @author Calclavia */ -//TODO: Should be -public class BlockConverter implements NativeConverter, ForgeLoadable { +public class BlockConverter implements NativeConverter, ForgeLoadable { /** * A map of all blockFactory to MC blocks registered */ - public final HashMap blockFactoryMap = new HashMap<>(); + public final BiMap blockFactoryMap = HashBiMap.create(); public static BlockConverter instance() { - return Game.natives().getNative(Block.class, net.minecraft.block.Block.class); + return Game.natives().getNative(BlockFactory.class, net.minecraft.block.Block.class); } @Override - public Class getNovaSide() { - return Block.class; + public Class getNovaSide() { + return BlockFactory.class; } @Override @@ -67,20 +67,19 @@ public Class getNativeSide() { } @Override - public Block toNova(net.minecraft.block.Block nativeBlock) { + public BlockFactory toNova(net.minecraft.block.Block nativeBlock) { //Prevent recursive wrapping if (nativeBlock instanceof FWBlock) { - return ((FWBlock) nativeBlock).dummy; + return ((FWBlock) nativeBlock).getFactory(); } if (nativeBlock == Blocks.air) { - return Game.blocks().getAirBlock().build(); + return Game.blocks().getAirBlock(); } - return new BWBlock(nativeBlock); + return blockFactoryMap.inverse().get(nativeBlock); } - @Override public net.minecraft.block.Block toNative(Block novaBlock) { //Prevent recursive wrapping if (novaBlock instanceof BWBlock) { @@ -90,12 +89,15 @@ public net.minecraft.block.Block toNative(Block novaBlock) { return toNative(novaBlock.getFactory()); } + @Override public net.minecraft.block.Block toNative(BlockFactory blockFactory) { return blockFactoryMap.get(blockFactory); } /** * Register all Nova blocks + * + * @param evt The Minecraft Forge pre-initialization event */ @Override public void preInit(FMLPreInitializationEvent evt) { @@ -103,16 +105,11 @@ public void preInit(FMLPreInitializationEvent evt) { registerNOVAToMinecraft(); } + @SuppressWarnings("unchecked") private void registerMinecraftToNOVA() { //TODO: Will this register ALL Forge mod blocks as well? BlockManager blockManager = Game.blocks(); - net.minecraft.block.Block.blockRegistry.forEach(obj -> - blockManager.register( - new BlockFactory(net.minecraft.block.Block.blockRegistry.getNameForObject(obj).toString(), - () -> new BWBlock((net.minecraft.block.Block) obj), evt -> { - }) - ) - ); + net.minecraft.block.Block.blockRegistry.forEach(block -> blockManager.register(new BWBlockFactory((net.minecraft.block.Block) block))); } private void registerNOVAToMinecraft() { diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/backward/BWBlockFactory.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/backward/BWBlockFactory.java new file mode 100644 index 000000000..bda71dd7d --- /dev/null +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/backward/BWBlockFactory.java @@ -0,0 +1,51 @@ + +/* + * Copyright (c) 2017 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ +package nova.core.wrapper.mc.forge.v18.wrapper.block.backward; + +import net.minecraft.block.Block; +import nova.core.block.BlockFactory; + +/** + * @author ExE Boss + */ +public class BWBlockFactory extends BlockFactory { + + private final Block block; + + public BWBlockFactory(Block block) { + super(Block.blockRegistry.getNameForObject(block).toString(), () -> new BWBlock(block), factory -> {}); + this.block = block; + } + + public Block getBlock() { + return block; + } + + @Override + public String getLocalizedName() { + return getBlock().getLocalizedName(); + } + + @Override + public String getUnlocalizedName() { + return getBlock().getUnlocalizedName(); + } +} diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/FWBlock.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/FWBlock.java index 3f72220a9..4f49c0a89 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/FWBlock.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/FWBlock.java @@ -110,6 +110,10 @@ public FWBlock(BlockFactory factory) { this.translucent = !isOpaqueCube(); } + public BlockFactory getFactory() { + return this.factory; + } + public Block getBlockInstance(IBlockAccess access, Vector3D position) { /** * If this block has a TileEntity, forward the method into the Stateful diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/recipes/MinecraftRecipeRegistry.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/recipes/MinecraftRecipeRegistry.java index c8abb1433..5a5ae8598 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/recipes/MinecraftRecipeRegistry.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/recipes/MinecraftRecipeRegistry.java @@ -61,7 +61,7 @@ private MinecraftRecipeRegistry() { } public void registerRecipes() { - long startTime = System.currentTimeMillis(); + long startTime = System.nanoTime(); RecipeManager recipeManager = Game.recipes(); @@ -78,7 +78,7 @@ public void registerRecipes() { ReflectionUtil.setCraftingRecipeList(new RecipeListWrapper(recipes)); - Game.logger().info("Initialized recipes in {} ms", (System.currentTimeMillis() - startTime)); + Game.logger().info("Initialized recipes in {} ms", (System.nanoTime() - startTime) / 1_000_000); recipeManager.whenRecipeAdded(CraftingRecipe.class, this::onNOVARecipeAdded); recipeManager.whenRecipeRemoved(CraftingRecipe.class, this::onNOVARecipeRemoved); diff --git a/src/main/java/nova/internal/core/tick/UpdateTicker.java b/src/main/java/nova/internal/core/tick/UpdateTicker.java index dda11ac61..d4aa32691 100755 --- a/src/main/java/nova/internal/core/tick/UpdateTicker.java +++ b/src/main/java/nova/internal/core/tick/UpdateTicker.java @@ -50,7 +50,7 @@ public class UpdateTicker { private double deltaTime; public UpdateTicker() { - last = System.currentTimeMillis(); + last = System.nanoTime(); } public void add(Updater ticker) { @@ -82,9 +82,9 @@ public void update() { preEvents.clear(); } - long current = System.currentTimeMillis(); + long current = System.nanoTime(); //The time in milliseconds between the last update and this one. - deltaTime = (current - last) / 1000d; + deltaTime = (current - last) / 1_000_000_000d; synchronized (updaters) { //TODO: Check the threshold Stream stream = updaters.size() > 1000 ? updaters.parallelStream() : updaters.stream();