Skip to content

Commit

Permalink
Update to master
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss committed Oct 24, 2017
1 parent 7e23a15 commit d4b8cc5
Show file tree
Hide file tree
Showing 20 changed files with 165 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import nova.core.event.PlayerEvent;
import nova.core.wrapper.mc.forge.v1_11_2.wrapper.entity.EntityConverter;
import nova.internal.core.Game;

/**
Expand All @@ -32,12 +33,12 @@
public class FMLEventHandler {
@SubscribeEvent
public void playerJoin(net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent evt) {
Game.events().publish(new PlayerEvent.Join(Game.natives().toNova(evt.player)));
Game.events().publish(new PlayerEvent.Join(EntityConverter.instance().toNova(evt.player)));
}

@SubscribeEvent
public void playerLeave(net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent evt) {
Game.events().publish(new PlayerEvent.Leave(Game.natives().toNova(evt.player)));
Game.events().publish(new PlayerEvent.Leave(EntityConverter.instance().toNova(evt.player)));
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
import net.minecraftforge.oredict.OreDictionary;
import nova.core.item.Item;
import nova.core.item.ItemDictionary;
import nova.core.wrapper.mc.forge.v1_11_2.wrapper.VectorConverter;
import nova.core.wrapper.mc.forge.v1_11_2.wrapper.block.world.WorldConverter;
import nova.core.wrapper.mc.forge.v1_11_2.wrapper.entity.EntityConverter;
import nova.core.wrapper.mc.forge.v1_11_2.wrapper.item.ItemConverter;
import nova.internal.core.Game;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;

/**
* @author Stan, Calclavia
Expand All @@ -40,12 +42,12 @@ public class ForgeEventHandler {

@SubscribeEvent
public void worldUnload(WorldEvent.Load evt) {
Game.events().publish(new nova.core.event.WorldEvent.Load(Game.natives().toNova(evt.getWorld())));
Game.events().publish(new nova.core.event.WorldEvent.Load(WorldConverter.instance().toNova(evt.getWorld())));
}

@SubscribeEvent
public void worldLoad(WorldEvent.Unload evt) {
Game.events().publish(new nova.core.event.WorldEvent.Unload(Game.natives().toNova(evt.getWorld())));
Game.events().publish(new nova.core.event.WorldEvent.Unload(WorldConverter.instance().toNova(evt.getWorld())));
}

@SubscribeEvent
Expand All @@ -60,11 +62,11 @@ public void onOreRegister(OreDictionary.OreRegisterEvent event) {

@SubscribeEvent
public void playerInteractEvent(PlayerInteractEvent event) {
if (event.getWorld() != null && event.getPos() != null) {
if (event.getWorld() != null) {
nova.core.event.PlayerEvent.Interact evt = new nova.core.event.PlayerEvent.Interact(
Game.natives().toNova(event.getWorld()),
new Vector3D(event.getPos().getX(), event.getPos().getY(), event.getPos().getZ()),
Game.natives().toNova(event.getEntityPlayer()),
WorldConverter.instance().toNova(event.getWorld()),
VectorConverter.instance().toNova(event.getPos()),
EntityConverter.instance().toNova(event.getEntityPlayer()),
nova.core.event.PlayerEvent.Interact.Action.values()[toNovaInteractOrdinal(event)]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@

import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.server.FMLServerHandler;
import nova.core.retention.Data;
import nova.core.retention.Storable;
import nova.core.util.registry.RetentionManager;
import nova.core.wrapper.mc.forge.v1_11_2.wrapper.data.DataConverter;
import nova.internal.core.Game;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import net.minecraftforge.fml.server.FMLServerHandler;

/**
* A manager that handles external file saving.
Expand All @@ -60,13 +60,13 @@ public void saveAll() {
public void save(String filename, Storable storable) {
Data saveMap = new Data();
storable.save(saveMap);
saveFile(filename, Game.natives().toNative(saveMap));
saveFile(filename, DataConverter.instance().toNative(saveMap));
}

@Override
public void load(String filename, Storable storable) {
NBTTagCompound nbt = loadFile(filename);
storable.load(Game.natives().toNova(nbt));
storable.load(DataConverter.instance().toNova(nbt));
}

/**
Expand All @@ -77,7 +77,7 @@ public void load(String filename, Storable storable) {
*/
public boolean saveFile(File file, NBTTagCompound data) {
try {
File tempFile = new File(file.getParent(), file.getName() + "_tmp.dat");
File tempFile = new File(file.getParent(), file.getName().replaceFirst("\\.nbt$", ".tmp.nbt"));

CompressedStreamTools.writeCompressed(data, new FileOutputStream(tempFile));

Expand All @@ -95,7 +95,7 @@ public boolean saveFile(File file, NBTTagCompound data) {
}

public boolean saveFile(File saveDirectory, String filename, NBTTagCompound data) {
return saveFile(new File(saveDirectory, filename + ".dat"), data);
return saveFile(new File(saveDirectory, filename + ".nbt"), data);
}

public boolean saveFile(String filename, NBTTagCompound data) {
Expand Down Expand Up @@ -123,7 +123,7 @@ public NBTTagCompound loadFile(File file) {
* @return The NBT data
*/
public NBTTagCompound loadFile(File saveDirectory, String filename) {
return loadFile(new File(saveDirectory, filename + ".dat"));
return loadFile(new File(saveDirectory, filename + ".nbt"));
}

public NBTTagCompound loadFile(String filename) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public GuiScreen createConfigGui(GuiScreen parentScreen) {
}

@Override
@Deprecated
public Class<? extends GuiScreen> mainConfigGuiClass() {
return NovaGuiConfig.class;
}
Expand All @@ -56,6 +57,7 @@ public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
}

@Override
@Deprecated
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import net.minecraft.entity.player.EntityPlayer;
import nova.core.entity.Entity;
import nova.core.entity.component.Player;
import nova.core.network.handler.PacketHandler;
import nova.core.wrapper.mc.forge.v1_11_2.network.MCPacket;
import nova.core.wrapper.mc.forge.v1_11_2.network.netty.MCNetworkManager;
import nova.core.wrapper.mc.forge.v1_11_2.util.WrapUtility;
import nova.internal.core.Game;

/**
Expand Down Expand Up @@ -65,7 +64,7 @@ public void handle(EntityPlayer player) {
MCNetworkManager network = (MCNetworkManager) Game.network();
PacketHandler<?> packetHandler = network.getPacketType(data.readInt());
int subId = data.readInt();
MCPacket packet = new MCPacket(data.slice(), ((Entity) Game.natives().toNova(player)).components.get(Player.class));
MCPacket packet = new MCPacket(data.slice(), WrapUtility.getNovaPlayer(player).get());
//Set the ID of the packet
packet.setID(subId);
packetHandler.read(packet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.NonNullList;
import net.minecraft.util.WeightedRandom;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.util.text.translation.LanguageMap;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.fml.common.registry.EntityRegistry;
Expand Down Expand Up @@ -140,7 +139,7 @@ public static Map<String, Object> getChestLoot() {
@SuppressWarnings("deprecation")
public static Map<String, String> getTranslations() {
return getPrivateObject(
getPrivateStaticObject(I18n.class, "localizedName", "field_74839_a"),
getPrivateStaticObject(net.minecraft.util.text.translation.I18n.class, "localizedName", "field_74839_a"),
"languageList",
"field_74816_c");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
import net.minecraft.item.Item;
import nova.core.entity.Entity;
import nova.core.entity.component.Player;
import nova.core.wrapper.mc.forge.v1_11_2.wrapper.entity.EntityConverter;
import nova.core.wrapper.mc.forge.v1_11_2.wrapper.entity.backward.BWEntity;
import nova.internal.core.Game;

import java.util.Objects;
import java.util.Optional;
import javax.annotation.Nullable;

/**
* Wrap utility methods.
Expand All @@ -38,10 +39,10 @@ public class WrapUtility {

private WrapUtility() {}

public static Optional<Player> getNovaPlayer(EntityPlayer player) {
public static Optional<Player> getNovaPlayer(@Nullable EntityPlayer player) {
if (player == null)
return Optional.empty();
return ((Entity)Game.natives().toNova(player)).components.getOp(Player.class);
return EntityConverter.instance().toNova(player).components.getOp(Player.class);
}

public static String getItemID(Item item, int meta) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ public BWBlock(net.minecraft.block.Block block) {
public BWBlock(IBlockState blockState, World world, Vector3D pos) {
this.blockState = blockState;
components.add(new BWBlockTransform(this, world, pos));
components.add(new BlockProperty.Opacity().setOpacity(blockState().getMaterial().blocksLight() ? 1 : 0));
components.add(new BlockProperty.Opacity()).setOpacity(() -> blockState().getMaterial().isOpaque() ? 1 : 0);
BlockProperty.Replaceable replaceable = components.add(new BlockProperty.Replaceable());
if (block() != Blocks.AIR) {
replaceable.setReplaceable(() -> block().canPlaceBlockAt((net.minecraft.world.World) blockAccess(), blockPos()));
}

BlockProperty.BlockSound blockSound = components.add(new BlockProperty.BlockSound());
SoundType soundType;
Expand Down Expand Up @@ -135,7 +139,7 @@ public BWBlock(IBlockState blockState, World world, Vector3D pos) {
} else {
bb = blockState().getBoundingBox(blockAccess(), blockPos()).offset(blockPos());
}
Cuboid cuboid = Game.natives().toNova(bb);
Cuboid cuboid = CuboidConverter.instance().toNova(bb);
return Collections.singleton(cuboid.subtract(position()));
});
components.add(new StaticRenderer())
Expand Down Expand Up @@ -228,11 +232,6 @@ public Optional<TileEntity> tile() {
return Optional.ofNullable(mcTileEntity);
}

@Override
public boolean canReplace() {
return block().canPlaceBlockAt((net.minecraft.world.World) blockAccess(), blockPos());
}

@Override
public boolean shouldDisplacePlacement() {
if (block() == Blocks.SNOW_LAYER && (blockState().getValue(BlockSnow.LAYERS) < 1)) {
Expand All @@ -254,7 +253,7 @@ public void save(Data data) {
@Override
public void load(Data data) {
Storable.super.load(data);
tile().ifPresent(tile -> tile.deserializeNBT(Game.natives().toNative(data)));
tile().ifPresent(tile -> tile.deserializeNBT(DataConverter.instance().toNative(data)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import nova.core.world.World;
import nova.core.wrapper.mc.forge.v1_11_2.wrapper.VectorConverter;
import nova.core.wrapper.mc.forge.v1_11_2.wrapper.block.world.WorldConverter;
import nova.internal.core.Game;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;

import java.util.Optional;
Expand Down Expand Up @@ -68,8 +67,8 @@ public IBlockAccess blockAccess() {
@Override
public void setWorld(World world) {
BlockPos pos = blockPos();
net.minecraft.world.World oldWorld = Game.natives().toNative(this.world);
net.minecraft.world.World newWorld = Game.natives().toNative(world);
net.minecraft.world.World oldWorld = (net.minecraft.world.World) WorldConverter.instance().toNative(this.world);
net.minecraft.world.World newWorld = (net.minecraft.world.World) WorldConverter.instance().toNative(world);
Optional<TileEntity> tileEntity = Optional.ofNullable(oldWorld.getTileEntity(pos));
Optional<NBTTagCompound> nbt = Optional.empty();
if (tileEntity.isPresent()) {
Expand All @@ -91,7 +90,7 @@ public void setWorld(World world) {
public void setPosition(Vector3D position) {
BlockPos oldPos = blockPos();
BlockPos newPos = VectorConverter.instance().toNative(position);
net.minecraft.world.World world = Game.natives().toNative(this.world);
net.minecraft.world.World world = (net.minecraft.world.World) WorldConverter.instance().toNative(this.world);
Optional<TileEntity> tileEntity = Optional.ofNullable(blockAccess().getTileEntity(oldPos));
Optional<NBTTagCompound> nbt = Optional.empty();
if (tileEntity.isPresent()) {
Expand Down
Loading

0 comments on commit d4b8cc5

Please sign in to comment.