Skip to content

Commit

Permalink
Ensure TEs are registered exactly once
Browse files Browse the repository at this point in the history
  • Loading branch information
boq committed Jan 21, 2018
1 parent 0401866 commit e35aaed
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ private static ItemBlock initializeItemBlock(Class<? extends ItemBlock> cls, Blo
public void registerBlocks(Class<? extends BlockInstances> klazz, IForgeRegistry<Block> blocks, IForgeRegistry<Item> items) {
final CachedInstanceFactory<IFixerFactory> fixerFactories = CachedInstanceFactory.create();
final DataFixer fixerRegistry = FMLCommonHandler.instance().getDataFixer();

final Set<Class<? extends TileEntity>> registeredTes = Sets.newHashSet();
processAnnotations(klazz, Block.class, RegisterBlock.class, blockFactory,
new IAnnotationAccess<RegisterBlock, Block>() {
@Override
Expand Down Expand Up @@ -388,7 +390,8 @@ public void visit(final Block block, RegisterBlock annotation) {

setBlockPrefixedId(annotation.unlocalizedName(), id, langDecorator, block::setUnlocalizedName);

if (teClass != null) {
if (teClass != null && !registeredTes.contains(teClass)) {
registeredTes.add(teClass);
final String teName = new ResourceLocation(modId, id).toString();
GameRegistry.registerTileEntity(teClass, teName);

Expand All @@ -398,10 +401,13 @@ public void visit(final Block block, RegisterBlock annotation) {
if (block instanceof IRegisterableBlock) ((IRegisterableBlock)block).setupBlock(modContainer, id, teClass, itemBlock);

for (RegisterTileEntity te : annotation.tileEntities()) {
final String teName = new ResourceLocation(modId, te.name()).toString();
GameRegistry.registerTileEntity(te.cls(), teName);
if (!registeredTes.contains(teClass)) {
registeredTes.add(teClass);
final String teName = new ResourceLocation(modId, te.name()).toString();
GameRegistry.registerTileEntity(te.cls(), teName);

registerFixer(te.cls());
registerFixer(te.cls());
}
}

if (annotation.addToModCreativeTab())
Expand Down

0 comments on commit e35aaed

Please sign in to comment.