diff options
author | botn365 <42187820+botn365@users.noreply.github.com> | 2020-02-25 20:09:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-25 20:09:38 +0100 |
commit | c2f7c7716a43b64b9c2741b9d90b6164fb50b1ef (patch) | |
tree | 087b121f0d40b58914411438574eaf0fe63ed8e0 /src/main/java/gregtech/api/metatileentity | |
parent | 14ea6a3ba9de16dd6fbd731b7b0f80ed109d4541 (diff) | |
parent | 5680fbc57fedb9c3aec07bdbf6efc67e64832564 (diff) | |
download | GT5-Unofficial-c2f7c7716a43b64b9c2741b9d90b6164fb50b1ef.tar.gz GT5-Unofficial-c2f7c7716a43b64b9c2741b9d90b6164fb50b1ef.tar.bz2 GT5-Unofficial-c2f7c7716a43b64b9c2741b9d90b6164fb50b1ef.zip |
Merge pull request #1 from GTNewHorizons/experimental
sync
Diffstat (limited to 'src/main/java/gregtech/api/metatileentity')
7 files changed, 116 insertions, 39 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java index 6d9ce47ef2..257cc79adb 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java @@ -6,6 +6,7 @@ import static gregtech.api.enums.GT_Values.NW; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.UUID;
import gregtech.api.GregTech_API;
import gregtech.api.enums.Textures;
@@ -1176,6 +1177,16 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE }
@Override
+ public UUID getOwnerUuid() {
+ return GT_Utility.defaultUuid;
+ }
+
+ @Override
+ public void setOwnerUuid(UUID uuid) {
+
+ }
+
+ @Override
public byte getComparatorValue(byte aSide) {
return canAccessData() ? mMetaTileEntity.getComparatorValue(aSide) : 0;
}
diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index 1da2dffca9..58a97f644a 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -39,6 +39,7 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.UUID; import static gregtech.GT_Mod.GT_FML_LOGGER; import static gregtech.api.enums.GT_Values.NW; @@ -69,6 +70,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE public long mLastSoundTick = 0; private long mLastCheckTick = 0; private String mOwnerName = ""; + private UUID mOwnerUuid = GT_Utility.defaultUuid; private NBTTagCompound mRecipeStuff = new NBTTagCompound(); private static final Field ENTITY_ITEM_HEALTH_FIELD; @@ -116,6 +118,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE aNBT.setByte("mStrongRedstone", mStrongRedstone); aNBT.setShort("mFacing", mFacing); aNBT.setString("mOwnerName", mOwnerName); + aNBT.setString("mOwnerUuid", mOwnerUuid == null ? "" : mOwnerUuid.toString()); aNBT.setBoolean("mLockUpgrade", mLockUpgrade); aNBT.setBoolean("mMuffler", mMuffler); aNBT.setBoolean("mSteamConverter", mSteamConverter); @@ -181,6 +184,11 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE mStrongRedstone = aNBT.getByte("mStrongRedstone"); mFacing = oFacing = (byte) aNBT.getShort("mFacing"); mOwnerName = aNBT.getString("mOwnerName"); + try { + mOwnerUuid = UUID.fromString(aNBT.getString("mOwnerUuid")); + } catch (IllegalArgumentException e){ + mOwnerUuid = null; + } mLockUpgrade = aNBT.getBoolean("mLockUpgrade"); mMuffler = aNBT.getBoolean("mMuffler"); mSteamConverter = aNBT.getBoolean("mSteamConverter"); @@ -541,7 +549,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE oTexturePage = (hasValidMetaTileEntity() && mMetaTileEntity instanceof GT_MetaTileEntity_Hatch) ? ((GT_MetaTileEntity_Hatch) mMetaTileEntity).getTexturePage() : 0, oUpdateData = hasValidMetaTileEntity() ? mMetaTileEntity.getUpdateData() : 0, oRedstoneData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) | ((mSidedRedstone[2] > 0) ? 4 : 0) | ((mSidedRedstone[3] > 0) ? 8 : 0) | ((mSidedRedstone[4] > 0) ? 16 : 0) | ((mSidedRedstone[5] > 0) ? 32 : 0)), - oColor = mColor), + oColor = mColor), xCoord, zCoord); mSendClientData = false; } @@ -1191,8 +1199,10 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE public boolean playerOwnsThis(EntityPlayer aPlayer, boolean aCheckPrecicely) { if (!canAccessData()) return false; if (aCheckPrecicely || privateAccess() || (mOwnerName.length() == 0)) - if ((mOwnerName.length() == 0) && isServerSide()) setOwnerName(aPlayer.getDisplayName()); - else if (privateAccess() && !aPlayer.getDisplayName().equals("Player") && !mOwnerName.equals("Player") && !mOwnerName.equals(aPlayer.getDisplayName())) + if ((mOwnerName.length() == 0) && isServerSide()) { + setOwnerName(aPlayer.getDisplayName()); + setOwnerUuid(aPlayer.getUniqueID()); + } else if (privateAccess() && !aPlayer.getDisplayName().equals("Player") && !mOwnerName.equals("Player") && !mOwnerName.equals(aPlayer.getDisplayName())) return false; return true; } @@ -1244,7 +1254,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE mMetaTileEntity.doExplosion(aAmount); } } - + public void dropItems(ItemStack tItem){ if(tItem==null)return; EntityItem tItemEntity = new EntityItem(this.worldObj, this.xCoord + XSTR_INSTANCE.nextFloat() * 0.8F + 0.1F, this.yCoord + XSTR_INSTANCE.nextFloat() * 0.8F + 0.1F, this.zCoord + XSTR_INSTANCE.nextFloat() * 0.8F + 0.1F, new ItemStack(tItem.getItem(), tItem.stackSize, tItem.getItemDamage())); @@ -1261,7 +1271,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE ENTITY_ITEM_HEALTH_FIELD.setInt(tItemEntity, 99999999); } catch (Exception ignored) {} this.worldObj.spawnEntityInWorld(tItemEntity); - tItem.stackSize = 0; + tItem.stackSize = 0; } @Override @@ -1365,7 +1375,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE doEnetUpdate(); return true; } - + if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sWireCutterList)) { byte tSide = GT_Utility.determineWrenchingSide(aSide, aX, aY, aZ); if (mMetaTileEntity.onWireCutterRightClick(aSide, tSide, aPlayer, aX, aY, aZ)) { @@ -1421,6 +1431,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE if (isUpgradable() && !mLockUpgrade) { mLockUpgrade = true; setOwnerName(aPlayer.getDisplayName()); + setOwnerUuid(aPlayer.getUniqueID()); GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(3), 1.0F, -1, xCoord, yCoord, zCoord); if (!aPlayer.capabilities.isCreativeMode) aPlayer.inventory.getCurrentItem().stackSize--; } @@ -1527,7 +1538,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE public byte getOutputRedstoneSignal(byte aSide) { return getCoverBehaviorAtSide(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this) ? mSidedRedstone[aSide] : getGeneralRS(aSide); } - + public byte getGeneralRS(byte aSide){ if(mMetaTileEntity==null)return 0; return mMetaTileEntity.allowGeneralRedstoneOutput() ? mSidedRedstone[aSide] : 0; @@ -1727,6 +1738,16 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE } @Override + public UUID getOwnerUuid() { + return mOwnerUuid; + } + + @Override + public void setOwnerUuid(UUID uuid) { + mOwnerUuid = uuid; + } + + @Override public byte getComparatorValue(byte aSide) { return canAccessData() ? mMetaTileEntity.getComparatorValue(aSide) : 0; } diff --git a/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java index 5c0cd5ceb6..d35d4583d9 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java @@ -1,6 +1,5 @@ package gregtech.api.metatileentity; -import cpw.mods.fml.common.FMLCommonHandler; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.interfaces.tileentity.IHasWorldObjectAndCoords; diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBatteryBuffer.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBatteryBuffer.java index 5835a6c9ab..1a81e4d570 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBatteryBuffer.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBatteryBuffer.java @@ -240,6 +240,7 @@ public class GT_MetaTileEntity_BasicBatteryBuffer extends GT_MetaTileEntity_Tier mChargeableCount++; } } + count++; } @Override @@ -309,11 +310,11 @@ public class GT_MetaTileEntity_BasicBatteryBuffer extends GT_MetaTileEntity_Tier @Override public String[] getInfoData() { - count++; - if (mMax == 0 || count % 20 == 0) { + if (mMax == 0 || (count > 20)) { long[] tmp = getStoredEnergy(); mStored = tmp[0]; mMax = tmp[1]; + count = 0; } return new String[]{ diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch.java index d57aff8fc9..26e816a52c 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch.java @@ -43,19 +43,30 @@ public abstract class GT_MetaTileEntity_Hatch extends GT_MetaTileEntity_BasicTan @Override public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { - int textureIndex=actualTexture|(mTexturePage<<7);//Shift seven since one page is 128 textures! - int texturePointer=(byte)(actualTexture&0x7F);//just to be sure, from my testing the 8th bit cannot be set clientside - return aSide != aFacing ? - textureIndex > 0 ? - new ITexture[]{Textures.BlockIcons.casingTexturePages[mTexturePage][texturePointer]} : - new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1]} : - textureIndex > 0 ? - aActive ? - getTexturesActive(Textures.BlockIcons.casingTexturePages[mTexturePage][texturePointer]) : - getTexturesInactive(Textures.BlockIcons.casingTexturePages[mTexturePage][texturePointer]) : - aActive ? - getTexturesActive(Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1]) : - getTexturesInactive(Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1]); + int textureIndex = actualTexture | (mTexturePage << 7);//Shift seven since one page is 128 textures! + int texturePointer = (byte) (actualTexture & 0x7F);//just to be sure, from my testing the 8th bit cannot be set clientside + try { + if (aSide != aFacing) { + if (textureIndex > 0) + return new ITexture[]{Textures.BlockIcons.casingTexturePages[mTexturePage][texturePointer]}; + else + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1]}; + } else { + if (textureIndex > 0) { + if (aActive) + return getTexturesActive(Textures.BlockIcons.casingTexturePages[mTexturePage][texturePointer]); + else + return getTexturesInactive(Textures.BlockIcons.casingTexturePages[mTexturePage][texturePointer]); + } else { + if (aActive) + return getTexturesActive(Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1]); + else + return getTexturesInactive(Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1]); + } + } + } catch (NullPointerException npe) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[0][0]}; + } } @Override diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java index 9c74811b23..71eea9bf87 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java @@ -10,9 +10,9 @@ import gregtech.api.util.GT_Utility; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.StatCollector; import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.IFluidHandler; +import net.minecraftforge.fluids.*; public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch { private String lockedFluidName = null; @@ -207,7 +207,7 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch { playerThatLockedfluid = aPlayer; if (mFluid == null) { this.setLockedFluidName(null); - inBrackets = trans("115.3","currently none, will be locked to the next that is put in"); + inBrackets = trans("115.3","currently none, will be locked to the next that is put in (or use fluid cell to lock)"); } else { this.setLockedFluidName(this.getDrainableStack().getUnlocalizedName()); inBrackets = this.getDrainableStack().getLocalizedName(); @@ -218,7 +218,7 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch { playerThatLockedfluid = aPlayer; if (mFluid == null) { this.setLockedFluidName(null); - inBrackets = trans("115.3","currently none, will be locked to the next that is put in"); + inBrackets = trans("115.3","currently none, will be locked to the next that is put in (or use fluid cell to lock)"); } else { this.setLockedFluidName(this.getDrainableStack().getUnlocalizedName()); inBrackets = this.getDrainableStack().getLocalizedName(); @@ -227,7 +227,41 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch { break; } } - + private boolean tryToLockHatch(EntityPlayer aPlayer, byte aSide) { + if (!getBaseMetaTileEntity().getCoverBehaviorAtSide(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSide(aSide), getBaseMetaTileEntity())) + return false; + if (!isFluidLocked()) + return false; + ItemStack tCurrentItem = aPlayer.inventory.getCurrentItem(); + if (tCurrentItem == null) + return false; + FluidStack tFluid = FluidContainerRegistry.getFluidForFilledItem(tCurrentItem); + if (tFluid == null && tCurrentItem.getItem() instanceof IFluidContainerItem) + tFluid = ((IFluidContainerItem)tCurrentItem.getItem()).getFluid(tCurrentItem); + if (tFluid != null) { + if (getLockedFluidName() != null && !getLockedFluidName().equals(tFluid.getUnlocalizedName())) { + GT_Utility.sendChatToPlayer(aPlayer, String.format("%s %s", trans("151.3", + "Hatch is locked to a different fluid. To change the locking, empty it and made it locked to the next fluid with a screwdriver. Currently locked to") + , StatCollector.translateToLocal(getLockedFluidName()))); + } + else { + setLockedFluidName(tFluid.getUnlocalizedName()); + if (mMode == 8) + GT_Utility.sendChatToPlayer(aPlayer, String.format("%s (%s)", trans("151.1", "Outputs items and 1 specific Fluid"), tFluid.getLocalizedName())); + else + GT_Utility.sendChatToPlayer(aPlayer, String.format("%s (%s)", trans("151.2", "Outputs 1 specific Fluid"), tFluid.getLocalizedName())); + } + return true; + } + return false; + } + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { + if (tryToLockHatch(aPlayer, aSide)) + return true; + return super.onRightclick(aBaseMetaTileEntity, aPlayer, aSide, aX, aY, aZ); + } + public String trans(String aKey, String aEnglish){ return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_"+aKey, aEnglish, false); } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java index 2da97a1939..da80a9e231 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java @@ -8,8 +8,6 @@ import java.util.ArrayList; import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.ConfigCategories; -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; import gregtech.api.gui.GT_Container_MultiMachine; import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -19,7 +17,6 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_ModHandler; -import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; import gregtech.common.GT_Pollution; @@ -435,7 +432,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { NBTTagCompound tNBT = mInventory[1].getTagCompound(); if (tNBT != null) { NBTTagCompound tNBT2 = tNBT.getCompoundTag("GT.CraftingComponents");//tNBT2 dont use out if - if (!tNBT.getBoolean("mDis")) { + /*if (!tNBT.getBoolean("mDis")) { tNBT2 = new NBTTagCompound(); Materials tMaterial = GT_MetaGenerated_Tool.getPrimaryMaterial(mInventory[1]); ItemStack tTurbine = GT_OreDictUnificator.get(OrePrefixes.turbineBlade, tMaterial, 1); @@ -487,7 +484,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { tNBT.setBoolean("mDis", true); mInventory[1].setTagCompound(tNBT); - } + }*/ } ((GT_MetaGenerated_Tool) mInventory[1].getItem()).doDamage(mInventory[1], (long)getDamageToComponent(mInventory[1]) * (long) Math.min(mEUt / this.damageFactorLow, Math.pow(mEUt, this.damageFactorHigh))); if (mInventory[1].stackSize == 0) mInventory[1] = null; @@ -566,7 +563,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { //Isnt too low EUt check? int aAmpsToInject; int aRemainder; - + int ampsOnCurrentHatch; //xEUt *= 4;//this is effect of everclocking for (GT_MetaTileEntity_Hatch_Dynamo aDynamo : mDynamoHatches) { if (isValidMetaTileEntity(aDynamo)) { @@ -574,11 +571,14 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { aVoltage = aDynamo.maxEUOutput(); aAmpsToInject = (int) (leftToInject / aVoltage); aRemainder = (int) (leftToInject - (aAmpsToInject * aVoltage)); - long powerGain; - for (int i = 0; i < Math.min(aDynamo.maxAmperesOut(), aAmpsToInject > 0 ? aAmpsToInject : 1); i++) { - powerGain = aAmpsToInject > 0 ? aVoltage : aRemainder; - aDynamo.getBaseMetaTileEntity().increaseStoredEnergyUnits(powerGain, false); - injected += powerGain; + ampsOnCurrentHatch= (int) Math.min(aDynamo.maxAmperesOut(), aAmpsToInject); + for (int i = 0; i < ampsOnCurrentHatch; i++) { + aDynamo.getBaseMetaTileEntity().increaseStoredEnergyUnits(aVoltage, false); + } + injected+=aVoltage*ampsOnCurrentHatch; + if(aRemainder>0 && ampsOnCurrentHatch<aDynamo.maxAmperesOut()){ + aDynamo.getBaseMetaTileEntity().increaseStoredEnergyUnits(aRemainder, false); + injected+=aRemainder; } } } |