mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
More work on the miner. Now has a "Only Mine Ores"-mode
This commit is contained in:
parent
408d084ac5
commit
508b488405
6 changed files with 88 additions and 33 deletions
|
@ -81,10 +81,21 @@ public class BlockMiner extends BlockContainerBase{
|
|||
if(!world.isRemote){
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if(tile != null && tile instanceof TileEntityMiner){
|
||||
player.addChatComponentMessage(new ChatComponentText(((TileEntityMiner)tile).storage.getEnergyStored()+"/"+((TileEntityMiner)tile).storage.getMaxEnergyStored()+" RF"));
|
||||
player.addChatComponentMessage(new ChatComponentText("Mining at Y "+((TileEntityMiner)tile).layerAt+"."));
|
||||
if(player.isSneaking()){
|
||||
player.addChatComponentMessage(new ChatComponentText(((TileEntityMiner)tile).storage.getEnergyStored()+"/"+((TileEntityMiner)tile).storage.getMaxEnergyStored()+" RF"));
|
||||
player.addChatComponentMessage(new ChatComponentText("Mining at Y = "+((TileEntityMiner)tile).layerAt+"."));
|
||||
}
|
||||
else{
|
||||
if(!((TileEntityMiner)tile).onlyMineOres){
|
||||
player.addChatComponentMessage(new ChatComponentText("Now only mining Ores"));
|
||||
((TileEntityMiner)tile).onlyMineOres = true;
|
||||
}
|
||||
else{
|
||||
player.addChatComponentMessage(new ChatComponentText("Now mining everything"));
|
||||
((TileEntityMiner)tile).onlyMineOres = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class PacketHandler{
|
|||
theNetwork.registerMessage(PacketGuiButton.Handler.class, PacketGuiButton.class, 0, Side.SERVER);
|
||||
theNetwork.registerMessage(PacketGuiNumber.Handler.class, PacketGuiNumber.class, 1, Side.SERVER);
|
||||
theNetwork.registerMessage(PacketGuiString.Handler.class, PacketGuiString.class, 2, Side.SERVER);
|
||||
theNetwork.registerMessage(PacketAtomicReconstructor.Handler.class, PacketAtomicReconstructor.class, 3, Side.CLIENT);
|
||||
theNetwork.registerMessage(PacketParticle.Handler.class, PacketParticle.class, 3, Side.CLIENT);
|
||||
theNetwork.registerMessage(PacketBookletStandButton.Handler.class, PacketBookletStandButton.class, 4, Side.SERVER);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,15 +15,13 @@ import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
|||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import ellpeck.actuallyadditions.items.lens.Lens;
|
||||
import ellpeck.actuallyadditions.items.lens.Lenses;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.particle.EntityReddustFX;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class PacketAtomicReconstructor implements IMessage{
|
||||
public class PacketParticle implements IMessage{
|
||||
|
||||
private int startX;
|
||||
private int startY;
|
||||
|
@ -31,21 +29,25 @@ public class PacketAtomicReconstructor implements IMessage{
|
|||
private int endX;
|
||||
private int endY;
|
||||
private int endZ;
|
||||
private int lensTypeOrdinal;
|
||||
private float[] color;
|
||||
private int particleAmount;
|
||||
private float particleSize;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public PacketAtomicReconstructor(){
|
||||
public PacketParticle(){
|
||||
|
||||
}
|
||||
|
||||
public PacketAtomicReconstructor(int startX, int startY, int startZ, int endX, int endY, int endZ, Lens type){
|
||||
public PacketParticle(int startX, int startY, int startZ, int endX, int endY, int endZ, float[] color, int particleAmount, float particleSize){
|
||||
this.startX = startX;
|
||||
this.startY = startY;
|
||||
this.startZ = startZ;
|
||||
this.endX = endX;
|
||||
this.endY = endY;
|
||||
this.endZ = endZ;
|
||||
this.lensTypeOrdinal = Lenses.allLenses.indexOf(type);
|
||||
this.color = color;
|
||||
this.particleAmount = particleAmount;
|
||||
this.particleSize = particleSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,7 +58,13 @@ public class PacketAtomicReconstructor implements IMessage{
|
|||
this.endX = buf.readInt();
|
||||
this.endY = buf.readInt();
|
||||
this.endZ = buf.readInt();
|
||||
this.lensTypeOrdinal = buf.readInt();
|
||||
this.particleAmount = buf.readInt();
|
||||
this.particleSize = buf.readFloat();
|
||||
|
||||
this.color = new float[3];
|
||||
for(int i = 0; i < this.color.length; i++){
|
||||
this.color[i] = buf.readFloat();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -67,14 +75,19 @@ public class PacketAtomicReconstructor implements IMessage{
|
|||
buf.writeInt(this.endX);
|
||||
buf.writeInt(this.endY);
|
||||
buf.writeInt(this.endZ);
|
||||
buf.writeInt(this.lensTypeOrdinal);
|
||||
buf.writeInt(this.particleAmount);
|
||||
buf.writeFloat(this.particleSize);
|
||||
|
||||
for(float aColor : this.color){
|
||||
buf.writeFloat(aColor);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<PacketAtomicReconstructor, IMessage>{
|
||||
public static class Handler implements IMessageHandler<PacketParticle, IMessage>{
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IMessage onMessage(PacketAtomicReconstructor message, MessageContext ctx){
|
||||
public IMessage onMessage(PacketParticle message, MessageContext ctx){
|
||||
World world = Minecraft.getMinecraft().theWorld;
|
||||
|
||||
if(Minecraft.getMinecraft().thePlayer.getDistance(message.startX, message.startY, message.startZ) <= 64){
|
||||
|
@ -83,11 +96,9 @@ public class PacketAtomicReconstructor implements IMessage{
|
|||
int difZ = message.startZ-message.endZ;
|
||||
double distance = Vec3.createVectorHelper(message.startX, message.startY, message.startZ).distanceTo(Vec3.createVectorHelper(message.endX, message.endY, message.endZ));
|
||||
|
||||
for(int times = 0; times < 5; times++){
|
||||
for(double i = 0; i <= 1; i += 1/(distance*8)){
|
||||
Lens type = Lenses.allLenses.get(message.lensTypeOrdinal);
|
||||
float[] color = type.getColor();
|
||||
Minecraft.getMinecraft().effectRenderer.addEffect(new EntityReddustFX(world, (difX*i)+message.endX+0.5, (difY*i)+message.endY+0.5, (difZ*i)+message.endZ+0.5, 2F, color[0], color[1], color[2]));
|
||||
for(int times = 0; times < message.particleAmount/2; times++){
|
||||
for(double i = 0; i <= 1; i += 1/(distance*message.particleAmount)){
|
||||
Minecraft.getMinecraft().effectRenderer.addEffect(new EntityReddustFX(world, (difX*i)+message.endX+0.5, (difY*i)+message.endY+0.5, (difZ*i)+message.endZ+0.5, message.particleSize, message.color[0], message.color[1], message.color[2]));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,8 +16,8 @@ import cpw.mods.fml.common.network.NetworkRegistry;
|
|||
import ellpeck.actuallyadditions.items.lens.ItemLens;
|
||||
import ellpeck.actuallyadditions.items.lens.Lens;
|
||||
import ellpeck.actuallyadditions.items.lens.Lenses;
|
||||
import ellpeck.actuallyadditions.network.PacketAtomicReconstructor;
|
||||
import ellpeck.actuallyadditions.network.PacketHandler;
|
||||
import ellpeck.actuallyadditions.network.PacketParticle;
|
||||
import ellpeck.actuallyadditions.util.WorldPos;
|
||||
import ellpeck.actuallyadditions.util.WorldUtil;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -81,7 +81,7 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
|
|||
}
|
||||
|
||||
private void shootLaser(int endX, int endY, int endZ, Lens currentLens){
|
||||
PacketHandler.theNetwork.sendToAllAround(new PacketAtomicReconstructor(xCoord, yCoord, zCoord, endX, endY, endZ, currentLens), new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 64));
|
||||
PacketHandler.theNetwork.sendToAllAround(new PacketParticle(xCoord, yCoord, zCoord, endX, endY, endZ, currentLens.getColor(), 8, 2F), new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 64));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,6 +12,9 @@ package ellpeck.actuallyadditions.tile;
|
|||
|
||||
import cofh.api.energy.EnergyStorage;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import ellpeck.actuallyadditions.network.PacketHandler;
|
||||
import ellpeck.actuallyadditions.network.PacketParticle;
|
||||
import ellpeck.actuallyadditions.util.WorldUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
|
@ -19,6 +22,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
@ -28,6 +32,7 @@ public class TileEntityMiner extends TileEntityBase implements IEnergyReceiver{
|
|||
public static final int ENERGY_USE_PER_BLOCK = 300;
|
||||
|
||||
public int layerAt;
|
||||
public boolean onlyMineOres;
|
||||
|
||||
@Override
|
||||
public void updateEntity(){
|
||||
|
@ -47,7 +52,9 @@ public class TileEntityMiner extends TileEntityBase implements IEnergyReceiver{
|
|||
|
||||
private boolean mine(int range){
|
||||
TileEntity tileAbove = worldObj.getTileEntity(xCoord, yCoord+1, zCoord);
|
||||
boolean shouldContinueMining = true;
|
||||
boolean mined = false;
|
||||
|
||||
for(int anX = -range; anX <= range; anX++){
|
||||
for(int aZ = -range; aZ <= range; aZ++){
|
||||
if(this.storage.getEnergyStored() >= ENERGY_USE_PER_BLOCK){
|
||||
|
@ -58,28 +65,53 @@ public class TileEntityMiner extends TileEntityBase implements IEnergyReceiver{
|
|||
Block block = this.worldObj.getBlock(x, y, z);
|
||||
int meta = this.worldObj.getBlockMetadata(x, y, z);
|
||||
if(block != null && !block.isAir(this.worldObj, x, y, z)){
|
||||
if(block.getHarvestLevel(meta) <= 3F && block.getHarvestLevel(meta) >= 0F){
|
||||
if(block.getHarvestLevel(meta) <= 3F && block.getHarvestLevel(meta) >= 0F && this.isMinable(block, meta)){
|
||||
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
|
||||
drops.addAll(block.getDrops(worldObj, x, y, z, meta, 0));
|
||||
|
||||
if(tileAbove instanceof IInventory){
|
||||
if(WorldUtil.addToInventory((IInventory)tileAbove, drops, ForgeDirection.DOWN, false)){
|
||||
worldObj.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block)+(meta << 12));
|
||||
worldObj.setBlockToAir(x, y, z);
|
||||
if(tileAbove instanceof IInventory && WorldUtil.addToInventory((IInventory)tileAbove, drops, ForgeDirection.DOWN, false)){
|
||||
worldObj.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block)+(meta << 12));
|
||||
worldObj.setBlockToAir(x, y, z);
|
||||
|
||||
WorldUtil.addToInventory((IInventory)tileAbove, drops, ForgeDirection.DOWN, true);
|
||||
tileAbove.markDirty();
|
||||
WorldUtil.addToInventory((IInventory)tileAbove, drops, ForgeDirection.DOWN, true);
|
||||
tileAbove.markDirty();
|
||||
|
||||
this.storage.extractEnergy(ENERGY_USE_PER_BLOCK, false);
|
||||
mined = true;
|
||||
}
|
||||
this.storage.extractEnergy(ENERGY_USE_PER_BLOCK, false);
|
||||
mined = true;
|
||||
}
|
||||
else{
|
||||
shouldContinueMining = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return mined;
|
||||
if(mined){
|
||||
this.shootParticles();
|
||||
}
|
||||
|
||||
return shouldContinueMining;
|
||||
}
|
||||
|
||||
private boolean isMinable(Block block, int meta){
|
||||
if(!this.onlyMineOres){
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
int[] ids = OreDictionary.getOreIDs(new ItemStack(block, 1, meta));
|
||||
for(int id : ids){
|
||||
String name = OreDictionary.getOreName(id);
|
||||
if(name.substring(0, 3).equals("ore")){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void shootParticles(){
|
||||
PacketHandler.theNetwork.sendToAllAround(new PacketParticle(xCoord, yCoord, zCoord, xCoord, this.layerAt, zCoord, new float[]{62F/255F, 163F/255F, 74F/255F}, 5, 2.5F), new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 128));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -126,6 +126,7 @@ tile.actuallyadditions.blockCrystalGreen.name=Emeradic Crystal Block
|
|||
tile.actuallyadditions.blockCrystalBlack.name=Void Crystal Block
|
||||
tile.actuallyadditions.blockCrystalWhite.name=Enori Crystal Block
|
||||
tile.actuallyadditions.blockBookStand.name=Manual Stand
|
||||
tile.actuallyadditions.blockMiner.name=Vertical Digger
|
||||
|
||||
#ESD
|
||||
tile.actuallyadditions.blockInputter.name=ESD
|
||||
|
|
Loading…
Reference in a new issue