Skip to content

Commit

Permalink
Rework Register System by using IItemContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
Nxer committed Oct 31, 2023
1 parent 211caa0 commit e21e0ef
Show file tree
Hide file tree
Showing 28 changed files with 623 additions and 506 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void preInit(FMLPreInitializationEvent event) {
TextHandler.initLangMap(isInDevMode);

proxy.preInit(event);
MaterialLoader.loadMaterial();// Load MaterialPool
MaterialLoader.load();// Load MaterialPool
}

@Mod.EventHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.GTNH_Community.gtnhcommunitymod.common;
package com.GTNH_Community.gtnhcommunitymod.client;

import static com.GTNH_Community.gtnhcommunitymod.common.item.itemAdders.ItemAdder01.MetaItem01;
import static com.GTNH_Community.gtnhcommunitymod.util.TextHandler.texter;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;

import com.GTNH_Community.gtnhcommunitymod.common.item.items.BasicItems;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

Expand All @@ -20,7 +21,7 @@ public class GTCMCreativeTabs {
@Override
@SideOnly(Side.CLIENT)
public Item getTabIconItem() {
return MetaItem01;
return BasicItems.MetaItem01;
}
};

Expand All @@ -33,7 +34,7 @@ public Item getTabIconItem() {
@Override
@SideOnly(Side.CLIENT)
public Item getTabIconItem() {
return MetaItem01;
return BasicItems.MetaItem01;
}
};

Expand All @@ -45,7 +46,7 @@ public Item getTabIconItem() {
@Override
@SideOnly(Side.CLIENT)
public Item getTabIconItem() {
return MetaItem01;
return BasicItems.MetaItem01;
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
package com.GTNH_Community.gtnhcommunitymod.common;

import static gregtech.api.enums.GT_Values.W;

import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

import gregtech.api.interfaces.IItemContainer;
import gregtech.api.util.GT_Log;
import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Utility;

public enum GTCMItemList implements IItemContainer {

// Items
TestItem0,

SpaceWarper,

// Blocks

TestMetaBlock01_0,
PhotonControllerUpgradeLV,
PhotonControllerUpgradeMV,
PhotonControllerUpgradeHV,
PhotonControllerUpgradeEV,
PhotonControllerUpgradeIV,
PhotonControllerUpgradeLuV,
PhotonControllerUpgradeZPM,
PhotonControllerUpgradeUV,
PhotonControllerUpgradeUHV,
PhotonControllerUpgradeUEV,
PhotonControllerUpgradeUIV,
PhotonControllerUpgradeUMV,
PhotonControllerUpgradeUXV,
PhotonControllerUpgradeMAX

;

// region Member Variables

private boolean mHasNotBeenSet;
private boolean mDeprecated;
private boolean mWarned;

private ItemStack mStack;

// endregion

GTCMItemList() {
mHasNotBeenSet = true;
}

GTCMItemList(boolean aDeprecated) {
if (aDeprecated) {
mDeprecated = true;
mHasNotBeenSet = true;
}
}

@Override
public Item getItem() {
sanityCheck();
if (GT_Utility.isStackInvalid(mStack)) return null;// TODO replace a default issue item
return mStack.getItem();
}

@Override
public Block getBlock() {
sanityCheck();
return Block.getBlockFromItem(getItem());
}

@Override
public boolean isStackEqual(Object aStack) {
return isStackEqual(aStack, false, false);
}

@Override
public boolean isStackEqual(Object aStack, boolean aWildcard, boolean aIgnoreNBT) {
if (mDeprecated && !mWarned) {
new Exception(this + " is now deprecated").printStackTrace(GT_Log.err);
// warn only once
mWarned = true;
}
if (GT_Utility.isStackInvalid(aStack)) return false;
return GT_Utility.areUnificationsEqual((ItemStack) aStack, aWildcard ? getWildcard(1) : get(1), aIgnoreNBT);
}

@Override
public ItemStack get(long aAmount, Object... aReplacements) {
sanityCheck();
// if invalid, return a replacements
if (GT_Utility.isStackInvalid(mStack)) {
GT_Log.out.println("Object in the ItemList is null at:");
new NullPointerException().printStackTrace(GT_Log.out);
return GT_Utility.copyAmount(aAmount, aReplacements);
}
return GT_Utility.copyAmount(aAmount, GT_OreDictUnificator.get(mStack));
}

@Override
public ItemStack getWildcard(long aAmount, Object... aReplacements) {
sanityCheck();
if (GT_Utility.isStackInvalid(mStack)) return GT_Utility.copyAmount(aAmount, aReplacements);
return GT_Utility.copyAmountAndMetaData(aAmount, W, GT_OreDictUnificator.get(mStack));
}

@Override
public ItemStack getUndamaged(long aAmount, Object... aReplacements) {
sanityCheck();
if (GT_Utility.isStackInvalid(mStack)) return GT_Utility.copyAmount(aAmount, aReplacements);
return GT_Utility.copyAmountAndMetaData(aAmount, 0, GT_OreDictUnificator.get(mStack));
}

@Override
public ItemStack getAlmostBroken(long aAmount, Object... aReplacements) {
sanityCheck();
if (GT_Utility.isStackInvalid(mStack)) return GT_Utility.copyAmount(aAmount, aReplacements);
return GT_Utility.copyAmountAndMetaData(aAmount, mStack.getMaxDamage() - 1, GT_OreDictUnificator.get(mStack));
}

@Override
public ItemStack getWithDamage(long aAmount, long aMetaValue, Object... aReplacements) {
sanityCheck();
if (GT_Utility.isStackInvalid(mStack)) return GT_Utility.copyAmount(aAmount, aReplacements);
return GT_Utility.copyAmountAndMetaData(aAmount, aMetaValue, GT_OreDictUnificator.get(mStack));
}

@Override
public IItemContainer set(Item aItem) {
mHasNotBeenSet = false;
if (aItem == null) return this;
ItemStack aStack = new ItemStack(aItem, 1, 0);
mStack = GT_Utility.copyAmount(1, aStack);
return this;
}

@Override
public IItemContainer set(ItemStack aStack) {
if (aStack != null) {
mHasNotBeenSet = false;
mStack = GT_Utility.copyAmount(1, aStack);
}
return this;
}

@Override
public IItemContainer registerOre(Object... aOreNames) {
return null;
}

@Override
public IItemContainer registerWildcardAsOre(Object... aOreNames) {
return null;
}

@Override
public ItemStack getWithCharge(long aAmount, int aEnergy, Object... aReplacements) {
return null;
}

@Override
public ItemStack getWithName(long aAmount, String aDisplayName, Object... aReplacements) {
return null;
}

@Override
public boolean hasBeenSet() {
return !mHasNotBeenSet;
}

/**
* Returns the internal stack. This method is unsafe. It's here only for quick operations. DON'T CHANGE THE RETURNED
* VALUE!
*/
public ItemStack getInternalStack_unsafe() {
return mStack;
}

private void sanityCheck() {
if (mHasNotBeenSet)
throw new IllegalAccessError("The Enum '" + name() + "' has not been set to an Item at this time!");
if (mDeprecated && !mWarned) {
new Exception(this + " is now deprecated").printStackTrace(GT_Log.err);
// warn only once
mWarned = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.GTNH_Community.gtnhcommunitymod.common.block;

import net.minecraft.block.Block;

import com.GTNH_Community.gtnhcommunitymod.common.block.blockClass.BlockBase01;
import com.GTNH_Community.gtnhcommunitymod.common.block.blockClass.Casings.PhotonControllerUpgradeCasing;

public class BasicBlocks {

public static final Block MetaBlock01 = new BlockBase01("MetaBlock01", "MetaBlock01");
public static final Block PhotonControllerUpgrade = new PhotonControllerUpgradeCasing(
"PhotonControllerUpgrades",
"Photon Controller Upgrade");
}

This file was deleted.

Loading

0 comments on commit e21e0ef

Please sign in to comment.