Skip to content

Commit

Permalink
Pre-initialize all mod helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Dec 7, 2024
1 parent aaac84c commit 39d47f3
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,95 @@
* @author rubensworks
*/
public abstract class ModHelpersCommon implements IModHelpers {

private IMinecraftClientHelpers minecraftClientHelpers;
private IL10NHelpers l10nHelpers;
private IBlockHelpers blockHelpers;
private ILocationHelpers locationHelpers;
private IBlockEntityHelpers blockEntityHelpers;
private IInventoryHelpers inventoryHelpers;
private IRenderHelpers renderHelpers;
private IBaseHelpers baseHelpers;
private ICraftingHelpers craftingHelpers;
private IWorldHelpers worldHelpers;
private IGuiHelpers guiHelpers;

protected ModHelpersCommon() {
this.initializeHelpers();
}

protected void initializeHelpers() {
if (this.getMinecraftHelpers().isClientSide()) {
this.minecraftClientHelpers = new MinecraftClientHelpersCommon();
this.renderHelpers = new RenderHelpersCommon();
this.guiHelpers = new GuiHelpersCommon(this);
} else {
this.minecraftClientHelpers = null;
this.renderHelpers = null;
this.guiHelpers = null;
}
this.l10nHelpers = new L10NHelpersCommon(this);
this.blockHelpers = new BlockHelpersCommon(this);
this.locationHelpers = new LocationHelpersCommon();
this.blockEntityHelpers = new BlockEntityHelpersCommon();
this.inventoryHelpers = new InventoryHelpersCommon(this);
this.baseHelpers = new BaseHelpersCommon();
this.craftingHelpers = new CraftingHelpersCommon(this);
this.worldHelpers = new WorldHelpersCommon(this);
}

@Override
public IMinecraftClientHelpers getMinecraftClientHelpers() {
return new MinecraftClientHelpersCommon();
return this.minecraftClientHelpers;
}

@Override
public IL10NHelpers getL10NHelpers() {
return new L10NHelpersCommon(this);
return this.l10nHelpers;
}

@Override
public IBlockHelpers getBlockHelpers() {
return new BlockHelpersCommon(this);
return this.blockHelpers;
}

@Override
public ILocationHelpers getLocationHelpers() {
return new LocationHelpersCommon();
return this.locationHelpers;
}

@Override
public IBlockEntityHelpers getBlockEntityHelpers() {
return new BlockEntityHelpersCommon();
return this.blockEntityHelpers;
}

@Override
public IInventoryHelpers getInventoryHelpers() {
return new InventoryHelpersCommon(this);
return this.inventoryHelpers;
}

@Override
public IRenderHelpers getRenderHelpers() {
return new RenderHelpersCommon();
return this.renderHelpers;
}

@Override
public IBaseHelpers getBaseHelpers() {
return new BaseHelpersCommon();
return this.baseHelpers;
}

@Override
public ICraftingHelpers getCraftingHelpers() {
return new CraftingHelpersCommon(this);
return this.craftingHelpers;
}

@Override
public IWorldHelpers getWorldHelpers() {
return new WorldHelpersCommon(this);
return this.worldHelpers;
}

@Override
public IGuiHelpers getGuiHelpers() {
return new GuiHelpersCommon(this);
return this.guiHelpers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,29 @@ public class ModHelpersFabric extends ModHelpersCommon implements IModHelpersFab

public static final ModHelpersFabric INSTANCE = new ModHelpersFabric();

private final IMinecraftHelpers minecraftHelpers;
private IMinecraftHelpers minecraftHelpers;
private IItemStackHelpers itemStackHelpers;
private IFluidHelpersFabric fluidHelpers;
private IRenderHelpersFabric renderHelpers;
private IRegistrationHelpers registrationHelpers;
private IGuiHelpersFabric guiHelpers;

private ModHelpersFabric() {
private ModHelpersFabric() {}

@Override
protected void initializeHelpers() {
this.minecraftHelpers = new MinecraftHelpersFabric();
super.initializeHelpers();
if (this.getMinecraftHelpers().isClientSide()) {
this.renderHelpers = new RenderHelpersFabric(this);
this.guiHelpers = new GuiHelpersFabric(this);
} else {
this.renderHelpers = null;
this.guiHelpers = null;
}
this.itemStackHelpers = new ItemStackHelpersFabric();
this.fluidHelpers = new FluidHelpersFabric();
this.registrationHelpers = new RegistrationHelpersFabric();
}

@Override
Expand All @@ -20,26 +39,26 @@ public IMinecraftHelpers getMinecraftHelpers() {

@Override
public IItemStackHelpers getItemStackHelpers() {
return new ItemStackHelpersFabric();
return this.itemStackHelpers;
}

@Override
public IFluidHelpersFabric getFluidHelpers() {
return new FluidHelpersFabric();
return this.fluidHelpers;
}

@Override
public IRenderHelpersFabric getRenderHelpers() {
return new RenderHelpersFabric(this);
return this.renderHelpers;
}

@Override
public IRegistrationHelpers getRegistrationHelpers() {
return new RegistrationHelpersFabric();
return this.registrationHelpers;
}

@Override
public IGuiHelpersFabric getGuiHelpers() {
return new GuiHelpersFabric(this);
return this.guiHelpers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,65 @@ public class ModHelpersForge extends ModHelpersCommon implements IModHelpersForg

public static final ModHelpersForge INSTANCE = new ModHelpersForge();

private IMinecraftHelpers minecraftHelpers;
private IRenderHelpersForge renderHelpers;
private IRegistrationHelpers registrationHelpers;
private IItemStackHelpers itemStackHelpers;
private ICapabilityHelpersForge capabilityHelpers;
private IFluidHelpersForge fluidHelpers;
private IGuiHelpersForge guiHelpers;

private ModHelpersForge() {}

@Override
public IRenderHelpersForge getRenderHelpers() {
return new RenderHelpersForge(this);
protected void initializeHelpers() {
this.minecraftHelpers = new MinecraftHelpersForge();
super.initializeHelpers();
if (this.getMinecraftHelpers().isClientSide()) {
this.renderHelpers = new RenderHelpersForge(this);
this.guiHelpers = new GuiHelpersForge(this);
} else {
this.renderHelpers = null;
this.guiHelpers = null;
}
this.registrationHelpers = new RegistrationHelpersForge();
this.itemStackHelpers = new ItemStackHelpersForge();
this.capabilityHelpers = new CapabilityHelpersForge(this);
this.fluidHelpers = new FluidHelpersForge();
}

@Override
public IRegistrationHelpers getRegistrationHelpers() {
return new RegistrationHelpersForge();
public IMinecraftHelpers getMinecraftHelpers() {
return this.minecraftHelpers;
}

@Override
public IMinecraftHelpers getMinecraftHelpers() {
return new MinecraftHelpersForge();
public IRenderHelpersForge getRenderHelpers() {
return this.renderHelpers;
}

@Override
public IRegistrationHelpers getRegistrationHelpers() {
return this.registrationHelpers;
}

@Override
public IItemStackHelpers getItemStackHelpers() {
return new ItemStackHelpersForge();
return this.itemStackHelpers;
}

@Override
public ICapabilityHelpersForge getCapabilityHelpers() {
return new CapabilityHelpersForge(this);
return this.capabilityHelpers;
}

@Override
public IFluidHelpersForge getFluidHelpers() {
return new FluidHelpersForge();
return this.fluidHelpers;
}

@Override
public IGuiHelpersForge getGuiHelpers() {
return new GuiHelpersForge(this);
return this.guiHelpers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,65 @@ public class ModHelpersNeoForge extends ModHelpersCommon implements IModHelpersN

public static final ModHelpersNeoForge INSTANCE = new ModHelpersNeoForge();

private IMinecraftHelpers minecraftHelpers;
private IItemStackHelpers itemStackHelpers;
private ICapabilityHelpersNeoForge capabilityHelpers;
private IFluidHelpersNeoForge fluidHelpers;
private IRenderHelpersNeoForge renderHelpers;
private IRegistrationHelpers registrationHelpers;
private IGuiHelpersNeoForge guiHelpers;

private ModHelpersNeoForge() {}

@Override
protected void initializeHelpers() {
this.minecraftHelpers = new MinecraftHelpersNeoForge();
super.initializeHelpers();
if (this.getMinecraftHelpers().isClientSide()) {
this.renderHelpers = new RenderHelpersNeoForge(this);
this.guiHelpers = new GuiHelpersNeoForge(this);
} else {
this.renderHelpers = null;
this.guiHelpers = null;
}
this.itemStackHelpers = new ItemStackHelpersNeoForge();
this.capabilityHelpers = new CapabilityHelpersNeoForge(this);
this.fluidHelpers = new FluidHelpersNeoForge();
this.registrationHelpers = new RegistrationHelpersNeoForge();
}

@Override
public IMinecraftHelpers getMinecraftHelpers() {
return new MinecraftHelpersNeoForge();
return this.minecraftHelpers;
}

@Override
public IItemStackHelpers getItemStackHelpers() {
return new ItemStackHelpersNeoForge();
return this.itemStackHelpers;
}

@Override
public ICapabilityHelpersNeoForge getCapabilityHelpers() {
return new CapabilityHelpersNeoForge(this);
return this.capabilityHelpers;
}

@Override
public IFluidHelpersNeoForge getFluidHelpers() {
return new FluidHelpersNeoForge();
return this.fluidHelpers;
}

@Override
public IRenderHelpersNeoForge getRenderHelpers() {
return new RenderHelpersNeoForge(this);
return this.renderHelpers;
}

@Override
public IRegistrationHelpers getRegistrationHelpers() {
return new RegistrationHelpersNeoForge();
return this.registrationHelpers;
}

@Override
public IGuiHelpersNeoForge getGuiHelpers() {
return new GuiHelpersNeoForge(this);
return this.guiHelpers;
}
}

0 comments on commit 39d47f3

Please sign in to comment.