Skip to content

Commit

Permalink
Merge pull request #191 from NOVA-Team/enhancement/identifier
Browse files Browse the repository at this point in the history
ID should only exist in factories
  • Loading branch information
calclavia committed Sep 11, 2015
2 parents 19a9a69 + fcb82ed commit 5e0a9a8
Show file tree
Hide file tree
Showing 56 changed files with 519 additions and 421 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private static String findOreDictEntryFor(List ingredient) {

private static ItemStack wrapSpecific(SpecificItemIngredient ingredient) {
for (Item item : ingredient.getExampleItems().get()) {
return Game.natives().toNative(item.factory().build());
return Game.natives().toNative(item.getFactory().build());
}

throw new AssertionError("this can't be!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public net.minecraft.block.Block toNative(Block novaBlock) {
return ((BWBlock) novaBlock).mcBlock;
}

return toNative(novaBlock.factory());
return toNative(novaBlock.getFactory());
}

public net.minecraft.block.Block toNative(BlockFactory blockFactory) {
Expand All @@ -105,24 +105,24 @@ public void preInit() {
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(() -> new BWBlock((net.minecraft.block.Block) obj), evt -> {
})));
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 -> {
})
)
);
}

private void registerNOVAToMinecraft() {
BlockManager blockManager = Game.blocks();

//Register air block
BlockFactory airBlock = new BlockFactory(() -> new BWBlock(Blocks.air) {
BlockFactory airBlock = new BlockFactory("air", () -> new BWBlock(Blocks.air) {
@Override
public boolean canReplace() {
return true;
}

@Override
public String getID() {
return "air";
}
}, evt -> {
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,6 @@ public boolean shouldDisplacePlacement() {
return super.shouldDisplacePlacement();
}

@Override
public String getID() {
return net.minecraft.block.Block.blockRegistry.getNameForObject(mcBlock);
}

@Override
public void save(Data data) {
Storable.super.save(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ public World world() {
@Override
public void setWorld(World world) {
this.world.removeBlock(position);
world.setBlock(position, block.factory());
world.setBlock(position, block.getFactory());
}

@Override
public void setPosition(Vector3D position) {
world.removeBlock(position);
world.setBlock(position, block.factory());
world.setBlock(position, block.getFactory());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import nova.core.entity.Entity;
import nova.core.entity.EntityFactory;
import nova.core.loader.Loadable;
import nova.core.nativewrapper.NativeConverter;
import nova.core.wrapper.mc17.wrapper.entity.backward.BWEntity;
Expand All @@ -31,6 +32,8 @@
import nova.core.wrapper.mc17.wrapper.entity.forward.MCEntityTransform;
import nova.internal.core.Game;

import java.util.Optional;

public class EntityConverter implements NativeConverter<Entity, net.minecraft.entity.Entity>, Loadable {

@Override
Expand All @@ -50,7 +53,16 @@ public Entity toNova(net.minecraft.entity.Entity mcEntity) {
return ((FWEntity) mcEntity).getWrapped();
}

return new BWEntity(mcEntity);
//TODO: Make this BWRegistry non-lazy
//Lazy registry
String id = mcEntity.getClass().getName();
Optional<EntityFactory> entityFactory = Game.entities().get(id);

if (entityFactory.isPresent()) {
return entityFactory.get().build();
} else {
return Game.entities().register(id, () -> new BWEntity(mcEntity)).build();
}
}

@Override
Expand All @@ -72,6 +84,6 @@ public void preInit() {
*/

//Look up for particle factory and pass it into BWEntityFX
BWEntityFX.fxMap.forEach((k, v) -> Game.entities().register(() -> new BWEntityFX(k)));
BWEntityFX.fxMap.forEach((k, v) -> Game.entities().register(Game.info().name + ":" + k, () -> new BWEntityFX(k)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ public void damage(double amount, DamageType type) {
}
}

@Override
public String getID() {
return entity.getClass().getName();
}

public static class MCPlayer extends Player {
public final BWEntity bwEntity;
public final net.minecraft.entity.player.EntityPlayer entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,4 @@ public EntityFX createEntityFX() {
//TODO: Handle velocity?
return FMLClientHandler.instance().getClient().renderGlobal.doSpawnParticle(particleID, 0, 0, 0, 0, 0, 0);
}

@Override
public String getID() {
return Game.info().name + ":" + particleID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public class BWItem extends Item implements Storable {
private final int meta;
private final NBTTagCompound tag;

private final String id;

EntityItem fakeEntity = new EntityItem(null, 0, 0, 0, makeItemStack(count()));

public BWItem(ItemStack itemStack) {
Expand All @@ -57,8 +55,6 @@ public BWItem(net.minecraft.item.Item item, int meta, NBTTagCompound tag) {
this.meta = meta;
this.tag = tag;

id = net.minecraft.item.Item.itemRegistry.getNameForObject(item) + (item.getHasSubtypes() ? ":" + meta : "");

add(new ItemRenderer())
.onRender(model -> {
model.addChild(new CustomModel(self -> {
Expand Down Expand Up @@ -99,11 +95,6 @@ public net.minecraft.item.ItemStack makeItemStack(int stackSize) {
return result;
}

@Override
public String getID() {
return id;
}

@Override
public String toString() {
return getID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package nova.core.wrapper.mc17.wrapper.item;

import net.minecraft.nbt.NBTTagCompound;
import nova.core.component.misc.FactoryProvider;
import nova.core.item.Item;
import nova.core.item.ItemFactory;
import nova.core.retention.Data;
Expand All @@ -31,12 +32,12 @@
* @author Stan
* @since 3/02/2015.
*/
public class MCItemFactory extends ItemFactory {
public class BWItemFactory extends ItemFactory {
private final net.minecraft.item.Item item;
private final int meta;

public MCItemFactory(net.minecraft.item.Item item, int meta) {
super(() -> new BWItem(item, meta, null));
public BWItemFactory(net.minecraft.item.Item item, int meta) {
super(net.minecraft.item.Item.itemRegistry.getNameForObject(item) + (item.getHasSubtypes() ? ":" + meta : ""), () -> new BWItem(item, meta, null));

this.item = item;
this.meta = meta;
Expand All @@ -54,7 +55,9 @@ public int getMeta() {
public Item build(Data data) {
int meta = (Integer) data.getOrDefault("damage", this.meta);
NBTTagCompound nbtData = Game.natives().toNative(data);
return new BWItem(item, meta, nbtData);
BWItem bwItem = new BWItem(item, meta, nbtData);
bwItem.add(new FactoryProvider(this));
return bwItem;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
import java.util.Iterator;

/**
* Created by Stan on 3/02/2015.
* A wrapped NBTTagCompound object that references the item instance
* @author Stan
* @since 3/02/2015.
*/
public class WrappedNBTTagCompound extends NBTTagCompound {
public class FWNBTTagCompound extends NBTTagCompound {
private final Item item;

public WrappedNBTTagCompound(Item item) {
public FWNBTTagCompound(Item item) {
this.item = item;
}

Expand All @@ -42,7 +44,7 @@ public Item getItem() {

@Override
public NBTBase copy() {
WrappedNBTTagCompound result = new WrappedNBTTagCompound(item);
FWNBTTagCompound result = new FWNBTTagCompound(item);
Iterator iterator = this.func_150296_c().iterator();

while (iterator.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public Item getNovaItem(ItemStack itemStack) {
return getNovaItem(new ItemStack(itemStack.getItem(), 1, 0));
}

if (itemStack.getTagCompound() != null && itemStack.getTagCompound() instanceof WrappedNBTTagCompound) {
return ((WrappedNBTTagCompound) itemStack.getTagCompound()).getItem();
if (itemStack.getTagCompound() != null && itemStack.getTagCompound() instanceof FWNBTTagCompound) {
return ((FWNBTTagCompound) itemStack.getTagCompound()).getItem();
} else {
ItemFactory itemFactory = registerMinecraftMapping(itemStack.getItem(), itemStack.getItemDamage());

Expand All @@ -108,7 +108,7 @@ public ItemStack toNative(Item item) {
return ((BWItem) item).makeItemStack(item.count());
} else {
ItemFactory itemFactory = Game.items().get(item.getID()).get();
WrappedNBTTagCompound tag = new WrappedNBTTagCompound(item);
FWNBTTagCompound tag = new FWNBTTagCompound(item);

MinecraftItemMapping mapping = get(itemFactory);
if (mapping == null) {
Expand All @@ -122,7 +122,7 @@ public ItemStack toNative(Item item) {
}

public ItemStack toNative(ItemFactory itemFactory) {
WrappedNBTTagCompound tag = new WrappedNBTTagCompound(itemFactory.build());
FWNBTTagCompound tag = new FWNBTTagCompound(itemFactory.build());

MinecraftItemMapping mapping = get(itemFactory);
if (mapping == null) {
Expand Down Expand Up @@ -154,7 +154,7 @@ public net.minecraft.item.ItemStack updateMCItemStack(ItemStack itemStack, nova.
if (itemStack.stackSize <= 0) {
return null;
}
itemStack.setTagCompound(Game.natives().toNative(item.factory().save(item)));
itemStack.setTagCompound(Game.natives().toNative(item.getFactory().save(item)));
return itemStack;
}

Expand Down Expand Up @@ -266,7 +266,7 @@ private ItemFactory registerMinecraftMapping(net.minecraft.item.Item item, int m
return map.inverse().get(mapping);
}

MCItemFactory itemFactory = new MCItemFactory(item, meta);
BWItemFactory itemFactory = new BWItemFactory(item, meta);
map.put(itemFactory, mapping);

Game.items().register(itemFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private static String findOreDictEntryFor(List ingredient) {

private static ItemStack wrapSpecific(SpecificItemIngredient ingredient) {
for (Item item : ingredient.getExampleItems().get()) {
return Game.natives().toNative(item.factory().build());
return Game.natives().toNative(item.getFactory().build());
}

throw new AssertionError("this can't be!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public net.minecraft.block.Block toNative(Block novaBlock) {
return ((BWBlock) novaBlock).mcBlock;
}

return toNative(novaBlock.factory());
return toNative(novaBlock.getFactory());
}

public net.minecraft.block.Block toNative(BlockFactory blockFactory) {
Expand All @@ -106,24 +106,24 @@ public void preInit() {
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(() -> new BWBlock((net.minecraft.block.Block) obj), evt -> {
})));
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 -> {
})
)
);
}

private void registerNOVAToMinecraft() {
BlockManager blockManager = Game.blocks();

//Register air block
BlockFactory airBlock = new BlockFactory(() -> new BWBlock(Blocks.air) {
BlockFactory airBlock = new BlockFactory("air", () -> new BWBlock(Blocks.air) {
@Override
public boolean canReplace() {
return true;
}

@Override
public String getID() {
return "air";
}
}, evt -> {
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ public boolean shouldDisplacePlacement() {
return super.shouldDisplacePlacement();
}

@Override
public String getID() {
return net.minecraft.block.Block.blockRegistry.getNameForObject(mcBlock).toString();
}

@Override
public void save(Data data) {
Storable.super.save(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ public World world() {
@Override
public void setWorld(World world) {
this.world.removeBlock(position);
world.setBlock(position, block.factory());
world.setBlock(position, block.getFactory());
}

@Override
public void setPosition(Vector3D position) {
world.removeBlock(position);
world.setBlock(position, block.factory());
world.setBlock(position, block.getFactory());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import nova.core.wrapper.mc18.wrapper.block.backward.BWBlock;
import nova.core.wrapper.mc18.wrapper.block.forward.FWBlock;
import nova.core.wrapper.mc18.wrapper.block.forward.MCBlockTransform;
import nova.core.wrapper.mc18.wrapper.entity.EntityConverter;
import nova.core.wrapper.mc18.wrapper.entity.backward.BWEntity;
import nova.core.wrapper.mc18.wrapper.entity.forward.FWEntity;
import nova.core.wrapper.mc18.wrapper.entity.forward.MCEntityTransform;
Expand Down Expand Up @@ -145,7 +146,7 @@ public Set<Entity> getEntities(Cuboid bound) {
public Entity addEntity(Vector3D position, Item item) {
EntityItem entityItem = new EntityItem(world(), position.getX(), position.getY(), position.getZ(), Game.natives().toNative(item));
world().spawnEntityInWorld(entityItem);
return new BWEntity(entityItem);
return Game.natives().toNova(entityItem);
}

@Override
Expand Down
Loading

0 comments on commit 5e0a9a8

Please sign in to comment.