mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
more API stuff, ore cluster functionality with auto miners
This commit is contained in:
parent
62d755432e
commit
35e6d6b5cd
42
src/main/java/api/hbm/block/IDrillInteraction.java
Normal file
42
src/main/java/api/hbm/block/IDrillInteraction.java
Normal file
@ -0,0 +1,42 @@
|
||||
package api.hbm.block;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IDrillInteraction {
|
||||
|
||||
/**
|
||||
* Whether the breaking of the block should be successful. Will destroy the block and not drop anything from clusters.
|
||||
* Should use a random function, otherwise the clusters will stay there indefinitely printing free ore.
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param drill Might be a tool, tile entity or anything that breaks blocks
|
||||
* @return
|
||||
*/
|
||||
public boolean canBreak(World world, int x, int y, int z, int meta, IMiningDrill drill);
|
||||
|
||||
/**
|
||||
* Returns an itemstack, usually when the block is not destroyed. Laser drills may drop this and mechanical drills will add it to their inventories.
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param drill Might be a tool, tile entity or anything that breaks blocks
|
||||
* @return
|
||||
*/
|
||||
public ItemStack extractResource(World world, int x, int y, int z, int meta, IMiningDrill drill);
|
||||
|
||||
/**
|
||||
* The hardness that should be considered instead of the hardness value of the block itself
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param meta
|
||||
* @param drill
|
||||
* @return
|
||||
*/
|
||||
public float getRelativeHardness(World world, int x, int y, int z, int meta, IMiningDrill drill);
|
||||
}
|
||||
22
src/main/java/api/hbm/block/IMiningDrill.java
Normal file
22
src/main/java/api/hbm/block/IMiningDrill.java
Normal file
@ -0,0 +1,22 @@
|
||||
package api.hbm.block;
|
||||
|
||||
public interface IMiningDrill {
|
||||
|
||||
/**
|
||||
* What era the drill belongs to, usually for IDrillInteraction to adjust outputs
|
||||
* @return
|
||||
*/
|
||||
public DrillType getDrillTier();
|
||||
|
||||
/**
|
||||
* An arbitrary "rating" of the drill. Hand powered pre-industrial drills would be <10, the auto mining drill is 50 and the laser miner is 100.
|
||||
* @return
|
||||
*/
|
||||
public int getDrillRating();
|
||||
|
||||
public static enum DrillType {
|
||||
PRIMITIVE,
|
||||
INDUSTRIAL,
|
||||
HITECH
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,8 @@ import java.util.Random;
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
import com.hbm.items.ModItems;
|
||||
|
||||
import api.hbm.block.IDrillInteraction;
|
||||
import api.hbm.block.IMiningDrill;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
@ -14,7 +16,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
|
||||
public class BlockCluster extends Block {
|
||||
public class BlockCluster extends Block implements IDrillInteraction {
|
||||
|
||||
public BlockCluster(Material mat) {
|
||||
super(mat);
|
||||
@ -63,4 +65,19 @@ public class BlockCluster extends Block {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreak(World world, int x, int y, int z, int meta, IMiningDrill drill) {
|
||||
return drill.getDrillRating() <= 70 && world.rand.nextFloat() < 0.05;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack extractResource(World world, int x, int y, int z, int meta, IMiningDrill drill) {
|
||||
return canBreak(world, x, y, z, meta, drill) ? new ItemStack(getDrop()) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRelativeHardness(World world, int x, int y, int z, int meta, IMiningDrill drill) {
|
||||
return this.getBlockHardness(world, x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,6 +49,10 @@ public class HbmAnimations {
|
||||
if(stack == null)
|
||||
return null;
|
||||
|
||||
if(slot < 0 || slot > 8) { //for freak of nature hotbars, probably won't work right but at least it doesn't crash
|
||||
slot = Math.abs(slot) % 9;
|
||||
}
|
||||
|
||||
if(hotbar[slot] == null)
|
||||
return null;
|
||||
|
||||
|
||||
@ -4,7 +4,10 @@ import java.util.Random;
|
||||
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
import com.hbm.interfaces.IConsumer;
|
||||
import com.hbm.interfaces.Spaghetti;
|
||||
import com.hbm.inventory.UpgradeManager;
|
||||
import com.hbm.items.ModItems;
|
||||
import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType;
|
||||
import com.hbm.lib.Library;
|
||||
import com.hbm.packet.AuxElectricityPacket;
|
||||
import com.hbm.packet.LoopedSoundPacket;
|
||||
@ -13,6 +16,8 @@ import com.hbm.packet.TEDrillPacket;
|
||||
import com.hbm.sound.SoundLoopMachine;
|
||||
import com.hbm.tileentity.TileEntityMachineBase;
|
||||
|
||||
import api.hbm.block.IDrillInteraction;
|
||||
import api.hbm.block.IMiningDrill;
|
||||
import api.hbm.energy.IBatteryItem;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@ -27,7 +32,8 @@ import net.minecraft.tileentity.TileEntityChest;
|
||||
import net.minecraft.tileentity.TileEntityHopper;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
|
||||
public class TileEntityMachineMiningDrill extends TileEntityMachineBase implements IConsumer {
|
||||
@Spaghetti("if i had a time machine i'd go back to the year 2017 and uppercut myself")
|
||||
public class TileEntityMachineMiningDrill extends TileEntityMachineBase implements IConsumer, IMiningDrill {
|
||||
|
||||
public long power;
|
||||
public int warning;
|
||||
@ -100,69 +106,18 @@ public class TileEntityMachineMiningDrill extends TileEntityMachineBase implemen
|
||||
this.radius = 1;
|
||||
this.fortune = 0;
|
||||
|
||||
for(int i = 10; i < 13; i++) {
|
||||
ItemStack stack = slots[i];
|
||||
|
||||
if(stack != null) {
|
||||
if(stack.getItem() == ModItems.upgrade_effect_1) {
|
||||
this.radius += 1;
|
||||
this.consumption += 80;
|
||||
}
|
||||
if(stack.getItem() == ModItems.upgrade_effect_2) {
|
||||
this.radius += 2;
|
||||
this.consumption += 160;
|
||||
}
|
||||
if(stack.getItem() == ModItems.upgrade_effect_3) {
|
||||
this.radius += 3;
|
||||
this.consumption += 240;
|
||||
}
|
||||
if(stack.getItem() == ModItems.upgrade_speed_1) {
|
||||
this.timer -= 15;
|
||||
this.consumption += 300;
|
||||
}
|
||||
if(stack.getItem() == ModItems.upgrade_speed_2) {
|
||||
this.timer -= 30;
|
||||
this.consumption += 600;
|
||||
}
|
||||
if(stack.getItem() == ModItems.upgrade_speed_3) {
|
||||
this.timer -= 45;
|
||||
this.consumption += 900;
|
||||
}
|
||||
if(stack.getItem() == ModItems.upgrade_power_1) {
|
||||
this.consumption -= 30;
|
||||
this.timer += 5;
|
||||
}
|
||||
if(stack.getItem() == ModItems.upgrade_power_2) {
|
||||
this.consumption -= 60;
|
||||
this.timer += 10;
|
||||
}
|
||||
if(stack.getItem() == ModItems.upgrade_power_3) {
|
||||
this.consumption -= 90;
|
||||
this.timer += 15;
|
||||
}
|
||||
if(stack.getItem() == ModItems.upgrade_fortune_1) {
|
||||
this.fortune += 1;
|
||||
this.timer += 15;
|
||||
}
|
||||
if(stack.getItem() == ModItems.upgrade_fortune_2) {
|
||||
this.fortune += 2;
|
||||
this.timer += 30;
|
||||
}
|
||||
if(stack.getItem() == ModItems.upgrade_fortune_3) {
|
||||
this.fortune += 3;
|
||||
this.timer += 45;
|
||||
}
|
||||
}
|
||||
}
|
||||
UpgradeManager.eval(slots, 10, 13);
|
||||
this.radius += Math.min(UpgradeManager.getLevel(UpgradeType.EFFECT), 3);
|
||||
this.consumption += Math.min(UpgradeManager.getLevel(UpgradeType.EFFECT), 3) * 80;
|
||||
|
||||
if(timer < 5)
|
||||
timer = 5;
|
||||
if(consumption < 40)
|
||||
consumption = 40;
|
||||
if(radius > 4)
|
||||
radius = 4;
|
||||
if(fortune > 3)
|
||||
fortune = 3;
|
||||
this.timer -= Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3) * 15;
|
||||
this.consumption += Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3) * 300;
|
||||
|
||||
this.consumption -= Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3) * 30;
|
||||
this.timer += Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3) * 5;
|
||||
|
||||
this.fortune += Math.min(UpgradeManager.getLevel(UpgradeType.FORTUNE), 3);
|
||||
this.timer += Math.min(UpgradeManager.getLevel(UpgradeType.FORTUNE), 3) * 15;
|
||||
|
||||
age++;
|
||||
if(age >= timer)
|
||||
@ -420,6 +375,20 @@ public class TileEntityMachineMiningDrill extends TileEntityMachineBase implemen
|
||||
|
||||
Block b = worldObj.getBlock(x, y, z);
|
||||
int meta = worldObj.getBlockMetadata(x, y, z);
|
||||
|
||||
if(b instanceof IDrillInteraction) {
|
||||
IDrillInteraction in = (IDrillInteraction) b;
|
||||
|
||||
ItemStack sta = in.extractResource(worldObj, x, y, z, meta, this);
|
||||
|
||||
if(hasSpace(sta)) {
|
||||
this.addItemToInventory(sta);
|
||||
}
|
||||
|
||||
if(!in.canBreak(worldObj, x, y, z, meta, this))
|
||||
return true; //true because the block is still there and mining should continue
|
||||
}
|
||||
|
||||
ItemStack stack = new ItemStack(b.getItemDropped(meta, rand, fortune), b.quantityDropped(meta, fortune, rand), b.damageDropped(meta));
|
||||
|
||||
//yup that worked
|
||||
@ -536,4 +505,14 @@ public class TileEntityMachineMiningDrill extends TileEntityMachineBase implemen
|
||||
{
|
||||
return 65536.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DrillType getDrillTier() {
|
||||
return DrillType.INDUSTRIAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDrillRating() {
|
||||
return 50;
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,6 +22,8 @@ import com.hbm.lib.Library;
|
||||
import com.hbm.tileentity.TileEntityMachineBase;
|
||||
import com.hbm.util.InventoryUtil;
|
||||
|
||||
import api.hbm.block.IDrillInteraction;
|
||||
import api.hbm.block.IMiningDrill;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
@ -37,7 +39,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
|
||||
public class TileEntityMachineMiningLaser extends TileEntityMachineBase implements IConsumer, IFluidSource {
|
||||
public class TileEntityMachineMiningLaser extends TileEntityMachineBase implements IConsumer, IFluidSource, IMiningDrill {
|
||||
|
||||
public long power;
|
||||
public int age = 0;
|
||||
@ -227,6 +229,7 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
Block b = worldObj.getBlock(targetX, targetY, targetZ);
|
||||
int meta = worldObj.getBlockMetadata(targetX, targetY, targetZ);
|
||||
boolean normal = true;
|
||||
boolean doesBreak = true;
|
||||
|
||||
if(b == Blocks.lit_redstone_ore)
|
||||
b = Blocks.redstone_ore;
|
||||
@ -273,9 +276,22 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
}
|
||||
}
|
||||
|
||||
if(normal)
|
||||
b.dropBlockAsItem(worldObj, targetX, targetY, targetZ, meta, fortune);
|
||||
worldObj.func_147480_a(targetX, targetY, targetZ, false);
|
||||
if(normal && b instanceof IDrillInteraction) {
|
||||
IDrillInteraction in = (IDrillInteraction) b;
|
||||
ItemStack drop = in.extractResource(worldObj, targetX, targetY, targetZ, meta, this);
|
||||
|
||||
if(drop != null) {
|
||||
worldObj.spawnEntityInWorld(new EntityItem(worldObj, targetX + 0.5, targetY + 0.5, targetZ + 0.5, drop.copy()));
|
||||
}
|
||||
|
||||
doesBreak = in.canBreak(worldObj, targetX, targetY, targetZ, meta, this);
|
||||
}
|
||||
|
||||
if(doesBreak) {
|
||||
if(normal) b.dropBlockAsItem(worldObj, targetX, targetY, targetZ, meta, fortune);
|
||||
worldObj.func_147480_a(targetX, targetY, targetZ, false);
|
||||
}
|
||||
|
||||
suckDrops();
|
||||
|
||||
if(doesScream()) {
|
||||
@ -292,6 +308,7 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
Item.getItemFromBlock(Blocks.sand),
|
||||
Item.getItemFromBlock(Blocks.sandstone),
|
||||
Item.getItemFromBlock(Blocks.gravel),
|
||||
Item.getItemFromBlock(ModBlocks.basalt),
|
||||
Item.getItemFromBlock(ModBlocks.stone_gneiss),
|
||||
Items.flint,
|
||||
Items.snowball,
|
||||
@ -396,46 +413,6 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
return block != Blocks.air && block.getBlockHardness(worldObj, x, y, z) >= 0 && !block.getMaterial().isLiquid() && block != Blocks.bedrock;
|
||||
}
|
||||
|
||||
public int getOverdrive() {
|
||||
|
||||
int speed = 1;
|
||||
|
||||
for(int i = 1; i < 9; i++) {
|
||||
|
||||
if(slots[i] != null) {
|
||||
|
||||
if(slots[i].getItem() == ModItems.upgrade_overdrive_1)
|
||||
speed += 1;
|
||||
else if(slots[i].getItem() == ModItems.upgrade_overdrive_2)
|
||||
speed += 2;
|
||||
else if(slots[i].getItem() == ModItems.upgrade_overdrive_3)
|
||||
speed += 3;
|
||||
}
|
||||
}
|
||||
|
||||
return Math.min(speed, 4);
|
||||
}
|
||||
|
||||
public int getSpeed() {
|
||||
|
||||
int speed = 1;
|
||||
|
||||
for(int i = 1; i < 9; i++) {
|
||||
|
||||
if(slots[i] != null) {
|
||||
|
||||
if(slots[i].getItem() == ModItems.upgrade_speed_1)
|
||||
speed += 2;
|
||||
else if(slots[i].getItem() == ModItems.upgrade_speed_2)
|
||||
speed += 4;
|
||||
else if(slots[i].getItem() == ModItems.upgrade_speed_3)
|
||||
speed += 6;
|
||||
}
|
||||
}
|
||||
|
||||
return Math.min(speed, 13);
|
||||
}
|
||||
|
||||
public int getRange() {
|
||||
|
||||
int range = 1;
|
||||
@ -456,26 +433,6 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
return Math.min(range, 25);
|
||||
}
|
||||
|
||||
public int getFortune() {
|
||||
|
||||
int fortune = 0;
|
||||
|
||||
for(int i = 1; i < 9; i++) {
|
||||
|
||||
if(slots[i] != null) {
|
||||
|
||||
if(slots[i].getItem() == ModItems.upgrade_fortune_1)
|
||||
fortune += 1;
|
||||
else if(slots[i].getItem() == ModItems.upgrade_fortune_2)
|
||||
fortune += 2;
|
||||
else if(slots[i].getItem() == ModItems.upgrade_fortune_3)
|
||||
fortune += 3;
|
||||
}
|
||||
}
|
||||
|
||||
return Math.min(fortune, 3);
|
||||
}
|
||||
|
||||
public boolean hasNullifier() {
|
||||
|
||||
for(int i = 1; i < 9; i++) {
|
||||
@ -561,10 +518,7 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
}
|
||||
|
||||
public int getConsumption() {
|
||||
|
||||
int consumption = this.consumption;
|
||||
|
||||
return consumption;
|
||||
return this.consumption;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
@ -713,4 +667,14 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
tank.writeToNBT(nbt, "oil");
|
||||
nbt.setBoolean("isOn", isOn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DrillType getDrillTier() {
|
||||
return DrillType.HITECH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDrillRating() {
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user