Skip to content

Commit

Permalink
Merge branch 'master' into mc1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss committed Oct 19, 2017
2 parents 413f364 + 16e8f78 commit 606b3b3
Show file tree
Hide file tree
Showing 14 changed files with 216 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
!/minecraft

# github
!/.gitattributes
!/.gitignore
!/README.md

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Block, net.minecraft.block.Block>, ForgeLoadable {
public class BlockConverter implements NativeConverter<BlockFactory, net.minecraft.block.Block>, ForgeLoadable {
/**
* A map of all blockFactory to MC blocks registered
*/
public final HashMap<BlockFactory, net.minecraft.block.Block> blockFactoryMap = new HashMap<>();
public final BiMap<BlockFactory, net.minecraft.block.Block> 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<Block> getNovaSide() {
return Block.class;
public Class<BlockFactory> getNovaSide() {
return BlockFactory.class;
}

@Override
Expand All @@ -66,20 +67,19 @@ public Class<net.minecraft.block.Block> 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) {
Expand All @@ -89,29 +89,27 @@ 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) {
registerMinecraftToNOVA();
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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private MinecraftRecipeRegistry() {
}

public void registerRecipes() {
long startTime = System.currentTimeMillis();
long startTime = System.nanoTime();

RecipeManager recipeManager = Game.recipes();

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 606b3b3

Please sign in to comment.