2015-10-22 00:47:13 +00:00
|
|
|
package gregtech.common.blocks;
|
|
|
|
|
2015-10-25 21:52:57 +00:00
|
|
|
import gregtech.GT_Mod;
|
2015-10-22 00:47:13 +00:00
|
|
|
import gregtech.api.GregTech_API;
|
|
|
|
import gregtech.api.enums.GT_Values;
|
|
|
|
import gregtech.api.enums.Materials;
|
|
|
|
import gregtech.api.enums.OrePrefixes;
|
|
|
|
import gregtech.api.interfaces.ITexture;
|
|
|
|
import gregtech.api.interfaces.tileentity.ITexturedTileEntity;
|
2016-08-10 19:43:37 +00:00
|
|
|
import gregtech.api.items.GT_Generic_Block;
|
2015-10-22 00:47:13 +00:00
|
|
|
import gregtech.api.objects.GT_CopiedBlockTexture;
|
|
|
|
import gregtech.api.objects.GT_RenderedTexture;
|
|
|
|
import gregtech.api.util.GT_OreDictUnificator;
|
|
|
|
import gregtech.api.util.GT_Utility;
|
2016-08-10 19:43:37 +00:00
|
|
|
import gregtech.api.world.GT_Worldgen_Ore_Normal;
|
2015-10-22 00:47:13 +00:00
|
|
|
import net.minecraft.block.Block;
|
2016-08-10 19:43:37 +00:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2015-10-22 00:47:13 +00:00
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.network.Packet;
|
2016-08-10 19:43:37 +00:00
|
|
|
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
2015-10-22 00:47:13 +00:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-08-10 19:43:37 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2015-10-22 00:47:13 +00:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2016-08-10 19:43:37 +00:00
|
|
|
import javax.annotation.Nullable;
|
2015-10-22 02:06:25 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Random;
|
|
|
|
|
2016-07-18 18:00:53 +00:00
|
|
|
public class GT_TileEntity_Ores extends TileEntity implements ITexturedTileEntity {
|
2015-10-22 02:06:25 +00:00
|
|
|
public short mMetaData = 0;
|
|
|
|
public boolean mNatural = false;
|
|
|
|
public boolean mBlocked = true;
|
|
|
|
|
|
|
|
public static byte getHarvestData(short aMetaData) {
|
|
|
|
Materials aMaterial = GregTech_API.sGeneratedMaterials[(aMetaData % 1000)];
|
2015-10-25 21:52:57 +00:00
|
|
|
byte tByte = aMaterial == null ? 0 : (byte) Math.max((aMetaData % 16000 / 1000 == 3) || (aMetaData % 16000 / 1000 == 4) ? 3 : 0, Math.min(7, aMaterial.mToolQuality - (aMetaData < 16000 ? 0 : 1)));
|
|
|
|
if(GT_Mod.gregtechproxy.mChangeHarvestLevels ){
|
2016-07-18 18:00:53 +00:00
|
|
|
tByte = aMaterial == null ? 0 : (byte) Math.max((aMetaData % 16000 / 1000 == 3) || (aMetaData % 16000 / 1000 == 4) ? GT_Mod.gregtechproxy.mGraniteHavestLevel : 0, Math.min(GT_Mod.gregtechproxy.mMaxHarvestLevel, GT_Mod.gregtechproxy.mHarvestLevel[aMaterial.mMetaItemSubID] - (aMetaData < 16000 ? 0 : 1)));
|
2015-10-25 21:52:57 +00:00
|
|
|
}
|
|
|
|
return tByte;
|
2015-10-22 00:47:13 +00:00
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
|
2016-07-25 22:04:21 +00:00
|
|
|
public static boolean setOreBlock(World aWorld, int aX, int aY, int aZ, int aMetaData, boolean isSmallOre) {
|
|
|
|
return setOreBlock(aWorld, aX, aY, aZ, aMetaData, isSmallOre, false);
|
2016-07-18 18:00:53 +00:00
|
|
|
}
|
|
|
|
|
2016-07-25 22:04:21 +00:00
|
|
|
public static boolean setOreBlock(World aWorld, int aX, int aY, int aZ, int aMetaData, boolean isSmallOre, boolean air) {
|
2015-10-22 02:06:25 +00:00
|
|
|
if (!air) {
|
|
|
|
aY = Math.min(aWorld.getActualHeight(), Math.max(aY, 1));
|
2015-10-22 00:47:13 +00:00
|
|
|
}
|
2016-08-10 19:43:37 +00:00
|
|
|
BlockPos blockPos = new BlockPos(aX, aY, aZ);
|
|
|
|
IBlockState blockState = aWorld.getBlockState(blockPos);
|
|
|
|
Block tBlock = blockState.getBlock();
|
2016-07-18 18:00:53 +00:00
|
|
|
Block tOreBlock = GregTech_API.sBlockOres1;
|
2016-08-10 19:43:37 +00:00
|
|
|
int BlockMeta = tBlock.getMetaFromState(blockState);
|
2016-07-22 00:41:51 +00:00
|
|
|
String BlockName = tBlock.getUnlocalizedName();
|
2016-07-25 22:04:21 +00:00
|
|
|
aMetaData += isSmallOre ? 16000 : 0;
|
2016-08-10 19:43:37 +00:00
|
|
|
if ((aMetaData > 0) && ((tBlock != Blocks.AIR) || air)) {
|
2016-07-22 00:41:51 +00:00
|
|
|
if (BlockName.equals("tile.igneousStone")) {
|
2016-07-27 03:21:53 +00:00
|
|
|
if (GregTech_API.sBlockOresUb1 != null) {
|
|
|
|
tOreBlock = GregTech_API.sBlockOresUb1;
|
|
|
|
aMetaData += (BlockMeta * 1000);
|
|
|
|
}
|
2016-07-22 00:41:51 +00:00
|
|
|
} else if (BlockName.equals("tile.metamorphicStone")) {
|
2016-07-27 03:21:53 +00:00
|
|
|
if (GregTech_API.sBlockOresUb2 != null) {
|
|
|
|
tOreBlock = GregTech_API.sBlockOresUb2;
|
|
|
|
aMetaData += (BlockMeta * 1000);
|
|
|
|
}
|
2016-07-22 00:41:51 +00:00
|
|
|
} else if (BlockName.equals("tile.sedimentaryStone")) {
|
2016-07-27 03:21:53 +00:00
|
|
|
if (GregTech_API.sBlockOresUb3 != null) {
|
|
|
|
tOreBlock = GregTech_API.sBlockOresUb3;
|
|
|
|
aMetaData += (BlockMeta * 1000);
|
|
|
|
}
|
2016-08-10 19:43:37 +00:00
|
|
|
} else if (tBlock.isReplaceableOreGen(blockState, aWorld, blockPos, GT_Worldgen_Ore_Normal.STONE)) {
|
2016-07-22 00:41:51 +00:00
|
|
|
aMetaData += 1000;
|
2015-10-22 02:06:25 +00:00
|
|
|
}
|
2016-08-10 19:43:37 +00:00
|
|
|
aWorld.setBlockState(blockPos, tOreBlock.getStateFromMeta(getHarvestData((short) aMetaData)), 0);
|
|
|
|
TileEntity tTileEntity = aWorld.getTileEntity(blockPos);
|
2015-10-22 02:06:25 +00:00
|
|
|
if ((tTileEntity instanceof GT_TileEntity_Ores)) {
|
|
|
|
((GT_TileEntity_Ores) tTileEntity).mMetaData = ((short) aMetaData);
|
|
|
|
((GT_TileEntity_Ores) tTileEntity).mNatural = true;
|
|
|
|
}
|
|
|
|
return true;
|
2015-10-22 00:47:13 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
|
2016-08-10 19:43:37 +00:00
|
|
|
@Override
|
2015-10-22 02:06:25 +00:00
|
|
|
public void readFromNBT(NBTTagCompound aNBT) {
|
|
|
|
super.readFromNBT(aNBT);
|
|
|
|
this.mMetaData = aNBT.getShort("m");
|
|
|
|
this.mNatural = aNBT.getBoolean("n");
|
2015-10-22 00:47:13 +00:00
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
|
2016-08-10 19:43:37 +00:00
|
|
|
@Override
|
|
|
|
public NBTTagCompound writeToNBT(NBTTagCompound aNBT) {
|
2015-10-22 02:06:25 +00:00
|
|
|
super.writeToNBT(aNBT);
|
|
|
|
aNBT.setShort("m", this.mMetaData);
|
|
|
|
aNBT.setBoolean("n", this.mNatural);
|
2016-08-10 19:43:37 +00:00
|
|
|
return aNBT;
|
2015-10-22 00:47:13 +00:00
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
|
|
|
|
public void onUpdated() {
|
|
|
|
if ((!this.worldObj.isRemote) && (this.mBlocked)) {
|
|
|
|
this.mBlocked = false;
|
2016-08-10 19:43:37 +00:00
|
|
|
GT_Values.NW.sendPacketToAllPlayersInRange(this.worldObj, new GT_Packet_Ores(getPos(), this.mMetaData), getPos().getX(), getPos().getZ());
|
2015-10-22 00:47:13 +00:00
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
}
|
|
|
|
|
2016-08-10 19:43:37 +00:00
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public SPacketUpdateTileEntity getUpdatePacket() {
|
2015-10-22 02:06:25 +00:00
|
|
|
if (!this.worldObj.isRemote) {
|
2016-08-10 19:43:37 +00:00
|
|
|
updateBlocked();
|
|
|
|
if (!this.mBlocked) {
|
|
|
|
GT_Values.NW.sendPacketToAllPlayersInRange(this.worldObj, new GT_Packet_Ores(getPos(), this.mMetaData), getPos().getX(), getPos().getZ());
|
2015-10-22 02:06:25 +00:00
|
|
|
}
|
2015-10-22 00:47:13 +00:00
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-08-10 19:43:37 +00:00
|
|
|
public void updateBlocked() {
|
|
|
|
mBlocked = !(GT_Utility.isOpaqueBlock(worldObj, getPos().up()) ||
|
|
|
|
GT_Utility.isOpaqueBlock(worldObj, getPos().down()) ||
|
|
|
|
GT_Utility.isOpaqueBlock(worldObj, getPos().east()) ||
|
|
|
|
GT_Utility.isOpaqueBlock(worldObj, getPos().west()) ||
|
|
|
|
GT_Utility.isOpaqueBlock(worldObj, getPos().south()) ||
|
|
|
|
GT_Utility.isOpaqueBlock(worldObj, getPos().north()));
|
|
|
|
}
|
|
|
|
|
2015-10-22 02:06:25 +00:00
|
|
|
public void overrideOreBlockMaterial(Block aOverridingStoneBlock, byte aOverridingStoneMeta) {
|
2016-07-22 03:31:57 +00:00
|
|
|
this.mMetaData = ((short) (int) (this.mMetaData % 1000L + this.mMetaData / 16000L * 16000L));
|
2016-08-10 19:43:37 +00:00
|
|
|
if (aOverridingStoneBlock.isReplaceableOreGen(worldObj.getBlockState(getPos()), this.worldObj, getPos(), state -> state.getBlock() == Blocks.NETHERRACK)) {
|
2016-07-22 03:31:57 +00:00
|
|
|
this.mMetaData = ((short) (this.mMetaData + 1000));
|
2016-08-10 19:43:37 +00:00
|
|
|
} else if (aOverridingStoneBlock.isReplaceableOreGen(worldObj.getBlockState(getPos()), this.worldObj, getPos(), state -> state.getBlock() == Blocks.END_STONE)) {
|
2016-07-22 03:31:57 +00:00
|
|
|
this.mMetaData = ((short) (this.mMetaData + 2000));
|
2016-08-10 19:43:37 +00:00
|
|
|
} else if (aOverridingStoneBlock.isReplaceableOreGen(worldObj.getBlockState(getPos()), this.worldObj, getPos(), state -> state.getBlock() == GregTech_API.sBlockGranites)) {
|
2016-07-22 03:31:57 +00:00
|
|
|
if (aOverridingStoneBlock == GregTech_API.sBlockGranites) {
|
|
|
|
if (aOverridingStoneMeta < 8) {
|
|
|
|
this.mMetaData = ((short) (this.mMetaData + 3000));
|
|
|
|
} else {
|
|
|
|
this.mMetaData = ((short) (this.mMetaData + 4000));
|
|
|
|
}
|
2016-07-22 00:41:51 +00:00
|
|
|
} else {
|
2016-07-22 03:31:57 +00:00
|
|
|
this.mMetaData = ((short) (this.mMetaData + 3000));
|
2015-10-22 02:06:25 +00:00
|
|
|
}
|
2016-08-10 19:43:37 +00:00
|
|
|
} else if (aOverridingStoneBlock.isReplaceableOreGen(worldObj.getBlockState(getPos()), this.worldObj, getPos(), state -> state.getBlock() == GregTech_API.sBlockStones)) {
|
2016-07-22 03:31:57 +00:00
|
|
|
if (aOverridingStoneBlock == GregTech_API.sBlockStones) {
|
|
|
|
if (aOverridingStoneMeta < 8) {
|
|
|
|
this.mMetaData = ((short) (this.mMetaData + 5000));
|
|
|
|
} else {
|
|
|
|
this.mMetaData = ((short) (this.mMetaData + 6000));
|
|
|
|
}
|
2016-07-23 02:09:25 +00:00
|
|
|
} else {
|
|
|
|
this.mMetaData = ((short) (this.mMetaData + 5000));
|
2016-07-16 22:48:25 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-10 19:43:37 +00:00
|
|
|
this.worldObj.setBlockState(getPos(), getBlockType().getStateFromMeta(getHarvestData(this.mMetaData)), 0);
|
2016-07-21 06:24:42 +00:00
|
|
|
}
|
|
|
|
|
2016-07-25 22:04:21 +00:00
|
|
|
public void convertOreBlock(World aWorld, int aX, int aY, int aZ) {
|
|
|
|
short aMeta = ((short) (int) (this.mMetaData % 1000 + (this.mMetaData / 16000 * 16000)));
|
2016-08-10 19:43:37 +00:00
|
|
|
aWorld.setBlockState(new BlockPos(aX, aY, aZ), GregTech_API.sBlockOres1.getStateFromMeta(getHarvestData(aMeta)));
|
|
|
|
TileEntity tTileEntity = aWorld.getTileEntity(new BlockPos(aX, aY, aZ));
|
2016-07-22 03:31:57 +00:00
|
|
|
if (tTileEntity instanceof GT_TileEntity_Ores) {
|
2016-07-25 22:04:21 +00:00
|
|
|
((GT_TileEntity_Ores) tTileEntity).mMetaData = aMeta;
|
2015-10-22 00:47:13 +00:00
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public short getMetaData() {
|
|
|
|
return this.mMetaData;
|
|
|
|
}
|
|
|
|
|
2016-07-21 06:24:42 +00:00
|
|
|
public ArrayList<ItemStack> getDrops(Block aDroppedOre, int aFortune) {
|
2016-08-10 19:43:37 +00:00
|
|
|
ArrayList<ItemStack> rList = new ArrayList<>();
|
2015-10-22 02:06:25 +00:00
|
|
|
if (this.mMetaData <= 0) {
|
2016-08-10 19:43:37 +00:00
|
|
|
rList.add(new ItemStack(Blocks.COBBLESTONE, 1, 0));
|
2015-10-22 02:06:25 +00:00
|
|
|
return rList;
|
2015-10-22 00:47:13 +00:00
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
if (this.mMetaData < 16000) {
|
2016-07-21 06:24:42 +00:00
|
|
|
rList.add(new ItemStack(aDroppedOre, 1, this.mMetaData));
|
2015-10-22 02:06:25 +00:00
|
|
|
return rList;
|
2015-10-22 00:47:13 +00:00
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
Materials aMaterial = GregTech_API.sGeneratedMaterials[(this.mMetaData % 1000)];
|
|
|
|
if (!this.mNatural) {
|
|
|
|
aFortune = 0;
|
2015-10-22 00:47:13 +00:00
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
if (aMaterial != null) {
|
2016-08-10 19:43:37 +00:00
|
|
|
Random tRandom = new Random(getPos().hashCode());
|
|
|
|
ArrayList<ItemStack> tSelector = new ArrayList<>();
|
2015-10-22 02:06:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
ItemStack tStack = GT_OreDictUnificator.get(OrePrefixes.gemExquisite, aMaterial, GT_OreDictUnificator.get(OrePrefixes.gem, aMaterial, 1L), 1L);
|
|
|
|
if (tStack != null) {
|
|
|
|
for (int i = 0; i < 1; i++) {
|
|
|
|
tSelector.add(tStack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tStack = GT_OreDictUnificator.get(OrePrefixes.gemFlawless, aMaterial, GT_OreDictUnificator.get(OrePrefixes.gem, aMaterial, 1L), 1L);
|
|
|
|
if (tStack != null) {
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
tSelector.add(tStack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tStack = GT_OreDictUnificator.get(OrePrefixes.gem, aMaterial, 1L);
|
|
|
|
if (tStack != null) {
|
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
tSelector.add(tStack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tStack = GT_OreDictUnificator.get(OrePrefixes.gemFlawed, aMaterial, GT_OreDictUnificator.get(OrePrefixes.crushed, aMaterial, 1L), 1L);
|
|
|
|
if (tStack != null) {
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
tSelector.add(tStack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tStack = GT_OreDictUnificator.get(OrePrefixes.crushed, aMaterial, 1L);
|
|
|
|
if (tStack != null) {
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
tSelector.add(tStack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tStack = GT_OreDictUnificator.get(OrePrefixes.gemChipped, aMaterial, GT_OreDictUnificator.get(OrePrefixes.dustImpure, aMaterial, 1L), 1L);
|
|
|
|
if (tStack != null) {
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
tSelector.add(tStack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tStack = GT_OreDictUnificator.get(OrePrefixes.dustImpure, aMaterial, 1L);
|
|
|
|
if (tStack != null) {
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
tSelector.add(tStack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tSelector.size() > 0) {
|
|
|
|
int i = 0;
|
|
|
|
for (int j = Math.max(1, aMaterial.mOreMultiplier + (aFortune > 0 ? tRandom.nextInt(1 + aFortune * aMaterial.mOreMultiplier) : 0) / 2); i < j; i++) {
|
2016-08-10 19:43:37 +00:00
|
|
|
rList.add(GT_Utility.copyAmount(1L, tSelector.get(tRandom.nextInt(tSelector.size()))));
|
2015-10-22 02:06:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tRandom.nextInt(3 + aFortune) > 1) {
|
2016-07-25 22:04:21 +00:00
|
|
|
Materials dustMat = ((GT_Block_Ores_Abstract) aDroppedOre).getDroppedDusts()[this.mMetaData / 1000 % 16];
|
|
|
|
if (dustMat != null) rList.add(GT_OreDictUnificator.get(tRandom.nextInt(3) > 0 ? OrePrefixes.dustImpure : OrePrefixes.dust, dustMat, 1L));
|
2015-10-22 02:06:25 +00:00
|
|
|
}
|
2015-10-22 00:47:13 +00:00
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
return rList;
|
2015-10-22 00:47:13 +00:00
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
|
2016-07-21 06:24:42 +00:00
|
|
|
public ITexture[] getTexture(Block aBlock, byte aSide) {
|
|
|
|
Materials aMaterial = GregTech_API.sGeneratedMaterials[(this.mMetaData % 1000)];
|
|
|
|
if ((aMaterial != null) && (this.mMetaData < 32000)) {
|
2016-07-22 00:41:51 +00:00
|
|
|
GT_RenderedTexture aIconSet = new GT_RenderedTexture(aMaterial.mIconSet.mTextures[this.mMetaData / 16000 == 0 ? OrePrefixes.ore.mTextureIndex : OrePrefixes.oreSmall.mTextureIndex], aMaterial.mRGBa);
|
|
|
|
if (aBlock instanceof GT_Block_Ores_Abstract) {
|
2016-07-25 22:04:21 +00:00
|
|
|
return new ITexture[]{((GT_Block_Ores_Abstract) aBlock).getTextureSet()[((this.mMetaData / 1000) % 16)], aIconSet};
|
2016-07-18 18:00:53 +00:00
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
}
|
2016-09-09 14:51:35 +00:00
|
|
|
return new ITexture[]{
|
|
|
|
new GT_RenderedTexture("minecraft:blocks/stone", null),
|
|
|
|
new GT_RenderedTexture(gregtech.api.enums.TextureSet.SET_NONE.mTextures[OrePrefixes.ore.mTextureIndex])};
|
2015-10-22 00:47:13 +00:00
|
|
|
}
|
|
|
|
}
|