-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework Register System by using IItemContainer
- Loading branch information
Showing
28 changed files
with
623 additions
and
506 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
191 changes: 191 additions & 0 deletions
191
src/main/java/com/GTNH_Community/gtnhcommunitymod/common/GTCMItemList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/GTNH_Community/gtnhcommunitymod/common/block/BasicBlocks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
129 changes: 0 additions & 129 deletions
129
src/main/java/com/GTNH_Community/gtnhcommunitymod/common/block/BlockEnum.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.