Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup MuTEMaster code #2282

Merged
merged 23 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import com.gtnewhorizons.modularui.common.widget.SlotWidget;
import com.gtnewhorizons.modularui.common.widget.TextWidget;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import gregtech.GT_Mod;
import gregtech.api.enums.Dyes;
import gregtech.api.enums.GT_Values;
Expand Down Expand Up @@ -173,13 +175,18 @@ public final int getOffsetZ(ForgeDirection side, int aMultiplier) {
@Override
public final boolean isServerSide() {
if (worldObj == null) {
return false;
return FMLCommonHandler.instance()
.getEffectiveSide() == Side.SERVER;
}
return !worldObj.isRemote;
}

@Override
public final boolean isClientSide() {
if (worldObj == null) {
return FMLCommonHandler.instance()
.getEffectiveSide() == Side.CLIENT;
}
return worldObj.isRemote;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,17 @@ public final void harvestBlock(World aWorld, EntityPlayer aPlayer, int aX, int a
final int aFortune = EnchantmentHelper.getFortuneModifier(aPlayer);
float aChance = 1.0F;
final TileEntity aTileEntity = getTileEntity(aWorld, aX, aY, aZ, true);
if (aTileEntity instanceof IMultiTileEntity) {
final ArrayList<ItemStack> tList = ((IMultiTileEntity) aTileEntity).getDrops(aFortune, aSilkTouch);
aChance = ForgeEventFactory
.fireBlockHarvesting(tList, aWorld, this, aX, aY, aZ, aMeta, aFortune, aChance, aSilkTouch, aPlayer);
for (final ItemStack tStack : tList)
if (XSTR.XSTR_INSTANCE.nextFloat() <= aChance) dropBlockAsItem(aWorld, aX, aY, aZ, tStack);

if (!(aTileEntity instanceof IMultiTileEntity)) {
return;
}

final ArrayList<ItemStack> tList = ((IMultiTileEntity) aTileEntity).getDrops(aFortune, aSilkTouch);
aChance = ForgeEventFactory
.fireBlockHarvesting(tList, aWorld, this, aX, aY, aZ, aMeta, aFortune, aChance, aSilkTouch, aPlayer);
for (final ItemStack tStack : tList)
if (XSTR.XSTR_INSTANCE.nextFloat() <= aChance) dropBlockAsItem(aWorld, aX, aY, aZ, tStack);

}

@Override
Expand Down Expand Up @@ -473,12 +477,17 @@ public boolean hasComparatorInputOverride() {
@Override
public final int getComparatorInputOverride(World aWorld, int aX, int aY, int aZ, int ordinalSide) {
final TileEntity aTileEntity = aWorld.getTileEntity(aX, aY, aZ);
return aTileEntity instanceof IMTE_GetComparatorInputOverride override
? override.getComparatorInputOverride(ForgeDirection.getOrientation(ordinalSide))
: aTileEntity instanceof IMTE_IsProvidingWeakPower power ? power.isProvidingWeakPower(
if (aTileEntity instanceof IMTE_GetComparatorInputOverride override) {
return override.getComparatorInputOverride(ForgeDirection.getOrientation(ordinalSide));
}

if (aTileEntity instanceof IMTE_IsProvidingWeakPower power) {
return power.isProvidingWeakPower(
ForgeDirection.getOrientation(ordinalSide)
.getOpposite())
: super.getComparatorInputOverride(aWorld, aX, aY, aZ, ordinalSide);
.getOpposite());
}

return super.getComparatorInputOverride(aWorld, aX, aY, aZ, ordinalSide);
}

@Override
Expand Down Expand Up @@ -629,14 +638,6 @@ public void receiveCoverData(IMultiTileEntity mte, int aCover0, int aCover1, int
mte.issueBlockUpdate();
}
}
//
// te.receiveClientData(GregTechTileClientEvents.CHANGE_COMMON_DATA, aTextureData);
//
// te.receiveClientData(GregTechTileClientEvents.CHANGE_CUSTOM_DATA, aUpdateData & 0x7F);
// te.receiveClientData(GregTechTileClientEvents.CHANGE_CUSTOM_DATA, aTexturePage | 0x80);
//
// te.receiveClientData(GregTechTileClientEvents.CHANGE_COLOR, aColorData);
// te.receiveClientData(GregTechTileClientEvents.CHANGE_REDSTONE_OUTPUT, aRedstoneData);

@Override
public final TileEntity createTileEntity(World aWorld, int aMeta) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,25 @@ public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List<String>
@SuppressWarnings("unchecked")
public void getSubItems(Item aItem, CreativeTabs aTab, List<ItemStack> aList) {
for (MultiTileEntityClassContainer tClass : mBlock.mMultiTileEntityRegistry.mRegistrations) {
if (!tClass.mHidden) {
if (((IMultiTileEntity) tClass.mCanonicalTileEntity)
.getSubItems(mBlock, aItem, aTab, aList, tClass.mID)) {
aList.add(mBlock.mMultiTileEntityRegistry.getItem(tClass.mID));
}
if (!tClass.mHidden && ((IMultiTileEntity) tClass.mCanonicalTileEntity)
.getSubItems(mBlock, aItem, aTab, aList, tClass.mID)) {
aList.add(mBlock.mMultiTileEntityRegistry.getItem(tClass.mID));
}
}
}

@Override
public boolean onItemUse(ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ,
int ordinalSide, float aHitX, float aHitY, float aHitZ) {

if (aY < 0 || aY > aWorld.getHeight()) return false;

if (aPlayer == null) return false;

try {
ForgeDirection side = ForgeDirection.getOrientation(ordinalSide);
final Block tClickedBlock = aWorld.getBlock(aX, aY, aZ);

if (tClickedBlock instanceof BlockSnow && (aWorld.getBlockMetadata(aX, aY, aZ) & 7) < 1) {
ordinalSide = SIDE_TOP;
side = ForgeDirection.UP;
Expand All @@ -102,79 +105,89 @@ public boolean onItemUse(ItemStack aStack, EntityPlayer aPlayer, World aWorld, i
final Block tReplacedBlock = aWorld.getBlock(aX, aY, aZ);

if (!tReplacedBlock.isReplaceable(aWorld, aX, aY, aZ)
|| !mBlock.canReplace(aWorld, aX, aY, aZ, ordinalSide, aStack)) return false;
if (aStack.stackSize == 0 || (aPlayer != null && !aPlayer.canPlayerEdit(aX, aY, aZ, ordinalSide, aStack)))
|| !mBlock.canReplace(aWorld, aX, aY, aZ, ordinalSide, aStack)) {
return false;
}

if (aStack.stackSize == 0 || (!aPlayer.canPlayerEdit(aX, aY, aZ, ordinalSide, aStack))) {
return false;
}

final MultiTileEntityContainer aMTEContainer = mBlock.mMultiTileEntityRegistry
.getNewTileEntityContainer(aWorld, aX, aY, aZ, aStack);

if (aMTEContainer != null
&& (aPlayer == null || aPlayer.isSneaking()
|| !(aMTEContainer.mTileEntity instanceof IMTE_OnlyPlaceableWhenSneaking mteSNeaking)
|| !mteSNeaking.onlyPlaceableWhenSneaking())
&& (aWorld.checkNoEntityCollision(AxisAlignedBB.getBoundingBox(aX, aY, aZ, aX + 1, aY + 1, aZ + 1))
|| (aMTEContainer.mTileEntity instanceof IMTE_IgnoreEntityCollisionWhenPlacing mteIgnoreCollision
&& mteIgnoreCollision.ignoreEntityCollisionWhenPlacing(
aStack,
aPlayer,
aWorld,
aX,
aY,
aZ,
side,
aHitX,
aHitY,
aHitZ)))
&& (!(aMTEContainer.mTileEntity instanceof IMTE_CanPlace mteCanPlace)
|| mteCanPlace.canPlace(aStack, aPlayer, aWorld, aX, aY, aZ, side, aHitX, aHitY, aHitZ))
&& aWorld.setBlock(aX, aY, aZ, aMTEContainer.mBlock, 15 - aMTEContainer.mBlockMetaData, 2)) {
aMTEContainer.setMultiTile(aWorld, aX, aY, aZ);

try {
if (((IMultiTileEntity) aMTEContainer.mTileEntity)
.onPlaced(aStack, aPlayer, aWorld, aX, aY, aZ, side, aHitX, aHitY, aHitZ)) {
aWorld.playSoundEffect(
aX + 0.5,
aY + 0.5,
aZ + 0.5,
aMTEContainer.mBlock.stepSound.func_150496_b(),
(aMTEContainer.mBlock.stepSound.getVolume() + 1) / 2,
aMTEContainer.mBlock.stepSound.getPitch() * 0.8F);
}
} catch (Throwable e) {
GT_FML_LOGGER.error("onPlaced", e);
}
try {
if (aMTEContainer.mTileEntity instanceof IMTE_HasMultiBlockMachineRelevantData mteData
&& (mteData.hasMultiBlockMachineRelevantData())) {
GregTech_API.causeMachineUpdate(aWorld, aX, aY, aZ);
}
} catch (Throwable e) {
GT_FML_LOGGER.error("causeMachineUpdate", e);
}
try {
if (!aWorld.isRemote) {
aWorld.notifyBlockChange(aX, aY, aZ, tReplacedBlock);
aWorld.func_147453_f /* updateNeighborsAboutBlockChange */(aX, aY, aZ, aMTEContainer.mBlock);
}
} catch (Throwable e) {
GT_FML_LOGGER.error("notifyBlockChange", e);
if (aMTEContainer == null) return false;

if (!aPlayer.isSneaking() && aMTEContainer.mTileEntity instanceof IMTE_OnlyPlaceableWhenSneaking mteSNeaking
&& mteSNeaking.onlyPlaceableWhenSneaking()) {
return false;
}

if (!aWorld.checkNoEntityCollision(AxisAlignedBB.getBoundingBox(aX, aY, aZ, aX + 1, aY + 1, aZ + 1))) {
return false;
}

if (!(aMTEContainer.mTileEntity instanceof IMTE_IgnoreEntityCollisionWhenPlacing mteIgnoreCollision)
|| !mteIgnoreCollision
.ignoreEntityCollisionWhenPlacing(aStack, aPlayer, aWorld, aX, aY, aZ, side, aHitX, aHitY, aHitZ)) {
return false;
}

if (aMTEContainer.mTileEntity instanceof IMTE_CanPlace mteCanPlace
&& !mteCanPlace.canPlace(aStack, aPlayer, aWorld, aX, aY, aZ, side, aHitX, aHitY, aHitZ)) {
return false;
}

if (!aWorld.setBlock(aX, aY, aZ, aMTEContainer.mBlock, 15 - aMTEContainer.mBlockMetaData, 2)) {
return false;
}

aMTEContainer.setMultiTile(aWorld, aX, aY, aZ);

try {
if (((IMultiTileEntity) aMTEContainer.mTileEntity)
.onPlaced(aStack, aPlayer, aWorld, aX, aY, aZ, side, aHitX, aHitY, aHitZ)) {
aWorld.playSoundEffect(
aX + 0.5,
aY + 0.5,
aZ + 0.5,
aMTEContainer.mBlock.stepSound.func_150496_b(),
(aMTEContainer.mBlock.stepSound.getVolume() + 1) / 2,
aMTEContainer.mBlock.stepSound.getPitch() * 0.8F);
}
try {
((IMultiTileEntity) aMTEContainer.mTileEntity).onTileEntityPlaced();
} catch (Throwable e) {
GT_FML_LOGGER.error("onTileEntityPlaced", e);
} catch (Throwable e) {
GT_FML_LOGGER.error("onPlaced", e);
}
try {
if (aMTEContainer.mTileEntity instanceof IMTE_HasMultiBlockMachineRelevantData mteData
&& (mteData.hasMultiBlockMachineRelevantData())) {
GregTech_API.causeMachineUpdate(aWorld, aX, aY, aZ);
}
try {
aWorld.func_147451_t /* updateAllLightTypes */(aX, aY, aZ);
} catch (Throwable e) {
GT_FML_LOGGER.error("updateAllLightTypes", e);
} catch (Throwable e) {
GT_FML_LOGGER.error("causeMachineUpdate", e);
}
try {
if (!aWorld.isRemote) {
aWorld.notifyBlockChange(aX, aY, aZ, tReplacedBlock);
aWorld.func_147453_f /* updateNeighborsAboutBlockChange */(aX, aY, aZ, aMTEContainer.mBlock);
}

aStack.stackSize--;
return true;
} catch (Throwable e) {
GT_FML_LOGGER.error("notifyBlockChange", e);
}
try {
((IMultiTileEntity) aMTEContainer.mTileEntity).onTileEntityPlaced();
} catch (Throwable e) {
GT_FML_LOGGER.error("onTileEntityPlaced", e);
}
try {
aWorld.func_147451_t /* updateAllLightTypes */(aX, aY, aZ);
} catch (Throwable e) {
GT_FML_LOGGER.error("updateAllLightTypes", e);
}

aStack.stackSize--;
return true;

} catch (Throwable e) {
GT_FML_LOGGER.error("onItemUse", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,7 @@ public boolean onRightClick(EntityPlayer aPlayer, ForgeDirection side, float aX,
}

if (!getCoverInfoAtSide(side).isGUIClickable()) return false;
}
if (isServerSide()) {
} else { // server side
if (!privateAccess() || aPlayer.getDisplayName()
.equalsIgnoreCase(getOwnerName())) {
final ItemStack tCurrentItem = aPlayer.inventory.getCurrentItem();
Expand Down
Loading