mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
Added Ore Magnet which can pull ores to the surface. Currently doesn't use energy etc, but it pulls the stuff up!
This commit is contained in:
parent
3067e37ebe
commit
b5b8730642
8 changed files with 440 additions and 2 deletions
|
@ -0,0 +1,105 @@
|
|||
package ellpeck.actuallyadditions.blocks;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import ellpeck.actuallyadditions.ActuallyAdditions;
|
||||
import ellpeck.actuallyadditions.inventory.GuiHandler;
|
||||
import ellpeck.actuallyadditions.tile.TileEntityOreMagnet;
|
||||
import ellpeck.actuallyadditions.util.BlockUtil;
|
||||
import ellpeck.actuallyadditions.util.INameableItem;
|
||||
import ellpeck.actuallyadditions.util.ModUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BlockOreMagnet extends BlockContainerBase implements INameableItem{
|
||||
|
||||
public BlockOreMagnet(){
|
||||
super(Material.rock);
|
||||
this.setHarvestLevel("pickaxe", 0);
|
||||
this.setHardness(1.5F);
|
||||
this.setResistance(10.0F);
|
||||
this.setStepSound(soundTypeStone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int par2){
|
||||
return new TileEntityOreMagnet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(int side, int meta){
|
||||
return this.blockIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerBlockIcons(IIconRegister iconReg){
|
||||
this.blockIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER + ":" + this.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
|
||||
if(!world.isRemote){
|
||||
TileEntityOreMagnet magnet = (TileEntityOreMagnet)world.getTileEntity(x, y, z);
|
||||
if (magnet != null) player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.ORE_MAGNET.ordinal(), world, x, y, z);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, Block block, int par6){
|
||||
this.dropInventory(world, x, y, z);
|
||||
super.breakBlock(world, x, y, z, block, par6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(){
|
||||
return "blockOreMagnet";
|
||||
}
|
||||
|
||||
public static class TheItemBlock extends ItemBlock{
|
||||
|
||||
private Block theBlock;
|
||||
|
||||
public TheItemBlock(Block block){
|
||||
super(block);
|
||||
this.theBlock = block;
|
||||
this.setHasSubtypes(false);
|
||||
this.setMaxDamage(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumRarity getRarity(ItemStack stack){
|
||||
return EnumRarity.rare;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack stack){
|
||||
return this.getUnlocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isHeld) {
|
||||
BlockUtil.addInformation(theBlock, list, 1, "");
|
||||
//TODO Energy stuffs
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetadata(int damage){
|
||||
return damage;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -79,12 +79,15 @@ public class InitBlocks{
|
|||
public static Block blockLampPowerer;
|
||||
|
||||
public static Block blockTreasureChest;
|
||||
|
||||
public static Block blockXPSolidifier;
|
||||
public static Block blockOreMagnet;
|
||||
|
||||
public static void init(){
|
||||
ModUtil.LOGGER.info("Initializing Blocks...");
|
||||
|
||||
blockOreMagnet = new BlockOreMagnet();
|
||||
BlockUtil.register(blockOreMagnet, BlockOreMagnet.TheItemBlock.class);
|
||||
|
||||
blockXPSolidifier = new BlockXPSolidifier();
|
||||
BlockUtil.register(blockXPSolidifier, BlockXPSolidifier.TheItemBlock.class);
|
||||
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
package ellpeck.actuallyadditions.inventory;
|
||||
|
||||
import ellpeck.actuallyadditions.blocks.InitBlocks;
|
||||
import ellpeck.actuallyadditions.inventory.slot.SlotOutput;
|
||||
import ellpeck.actuallyadditions.tile.TileEntityBase;
|
||||
import ellpeck.actuallyadditions.tile.TileEntityOreMagnet;
|
||||
import invtweaks.api.container.InventoryContainer;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
@InventoryContainer
|
||||
public class ContainerOreMagnet extends Container{
|
||||
|
||||
private TileEntityOreMagnet magnet;
|
||||
|
||||
public ContainerOreMagnet(InventoryPlayer inventory, TileEntityBase tile){
|
||||
this.magnet = (TileEntityOreMagnet)tile;
|
||||
|
||||
this.addSlotToContainer(new Slot(this.magnet, 0, 98, 74));
|
||||
this.addSlotToContainer(new SlotOutput(this.magnet, 1, 98, 43));
|
||||
|
||||
this.addSlotToContainer(new SlotOutput(this.magnet, 2, 71, 43));
|
||||
|
||||
for (int i = 0; i < 3; i++){
|
||||
for (int j = 0; j < 9; j++){
|
||||
this.addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 97 + i * 18));
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 9; i++){
|
||||
this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 155));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player){
|
||||
return this.magnet.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slot){
|
||||
final int inventoryStart = 2;
|
||||
final int inventoryEnd = inventoryStart+26;
|
||||
final int hotbarStart = inventoryEnd+1;
|
||||
final int hotbarEnd = hotbarStart+8;
|
||||
|
||||
Slot theSlot = (Slot)this.inventorySlots.get(slot);
|
||||
|
||||
if (theSlot != null && theSlot.getHasStack()){
|
||||
ItemStack newStack = theSlot.getStack();
|
||||
ItemStack currentStack = newStack.copy();
|
||||
|
||||
//Other Slots in Inventory excluded
|
||||
if(slot >= inventoryStart){
|
||||
//Shift from Inventory
|
||||
//TODO
|
||||
if(FluidContainerRegistry.containsFluid(newStack, new FluidStack(InitBlocks.fluidOil, 1))){
|
||||
if(!this.mergeItemStack(newStack, 0, 1, false)) return null;
|
||||
}
|
||||
//
|
||||
|
||||
else if(slot >= inventoryStart && slot <= inventoryEnd){
|
||||
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null;
|
||||
}
|
||||
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null;
|
||||
}
|
||||
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)) return null;
|
||||
|
||||
if (newStack.stackSize == 0) theSlot.putStack(null);
|
||||
else theSlot.onSlotChanged();
|
||||
|
||||
if (newStack.stackSize == currentStack.stackSize) return null;
|
||||
theSlot.onPickupFromSlot(player, newStack);
|
||||
|
||||
return currentStack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -62,6 +62,8 @@ public class GuiHandler implements IGuiHandler{
|
|||
return new ContainerEnervator(entityPlayer, tile);
|
||||
case XP_SOLIDIFIER:
|
||||
return new ContainerXPSolidifier(entityPlayer.inventory, tile);
|
||||
case ORE_MAGNET:
|
||||
return new ContainerOreMagnet(entityPlayer.inventory, tile);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
@ -118,6 +120,8 @@ public class GuiHandler implements IGuiHandler{
|
|||
return new GuiEnervator(entityPlayer, tile);
|
||||
case XP_SOLIDIFIER:
|
||||
return new GuiXPSolidifier(entityPlayer.inventory, tile, x, y, z, world);
|
||||
case ORE_MAGNET:
|
||||
return new GuiOreMagnet(entityPlayer.inventory, tile);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
@ -145,7 +149,8 @@ public class GuiHandler implements IGuiHandler{
|
|||
DRILL,
|
||||
ENERGIZER,
|
||||
ENERVATOR,
|
||||
XP_SOLIDIFIER
|
||||
XP_SOLIDIFIER,
|
||||
ORE_MAGNET
|
||||
}
|
||||
|
||||
public static void init(){
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
package ellpeck.actuallyadditions.inventory.gui;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import ellpeck.actuallyadditions.inventory.ContainerOreMagnet;
|
||||
import ellpeck.actuallyadditions.tile.TileEntityBase;
|
||||
import ellpeck.actuallyadditions.tile.TileEntityOreMagnet;
|
||||
import ellpeck.actuallyadditions.util.AssetUtil;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiOreMagnet extends GuiContainer{
|
||||
|
||||
private TileEntityOreMagnet magnet;
|
||||
|
||||
private static final ResourceLocation resLoc = AssetUtil.getGuiLocation("guiOreMagnet");
|
||||
|
||||
public GuiOreMagnet(InventoryPlayer inventory, TileEntityBase tile){
|
||||
super(new ContainerOreMagnet(inventory, tile));
|
||||
this.magnet = (TileEntityOreMagnet)tile;
|
||||
this.xSize = 176;
|
||||
this.ySize = 93+86;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawGuiContainerForegroundLayer(int x, int y){
|
||||
AssetUtil.displayNameString(this.fontRendererObj, xSize, -10, this.magnet.getInventoryName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawGuiContainerBackgroundLayer(float f, int x, int y){
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
this.mc.getTextureManager().bindTexture(AssetUtil.GUI_INVENTORY_LOCATION);
|
||||
this.drawTexturedModalRect(this.guiLeft, this.guiTop+93, 0, 0, 176, 86);
|
||||
|
||||
this.mc.getTextureManager().bindTexture(resLoc);
|
||||
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, 176, 93);
|
||||
|
||||
if(this.magnet.storage.getEnergyStored() > 0){
|
||||
int i = this.magnet.getEnergyScaled(83);
|
||||
drawTexturedModalRect(this.guiLeft+43, this.guiTop+89-i, 176, 0, 16, i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int x, int y, float f){
|
||||
super.drawScreen(x, y, f);
|
||||
String text1 = this.magnet.storage.getEnergyStored() + "/" + this.magnet.storage.getMaxEnergyStored() + " RF";
|
||||
if(x >= guiLeft+43 && y >= guiTop+6 && x <= guiLeft+58 && y <= guiTop+88){
|
||||
this.func_146283_a(Collections.singletonList(text1), x, y);
|
||||
}
|
||||
String text2 = this.magnet.tank.getFluidAmount() + "/" + this.magnet.tank.getCapacity() + " mB " +StatCollector.translateToLocal("fluid.oil");
|
||||
if(x >= guiLeft+117 && y >= guiTop+6 && x <= guiLeft+132 && y <= guiTop+88){
|
||||
this.func_146283_a(Collections.singletonList(text2), x, y);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -59,6 +59,7 @@ public class TileEntityBase extends TileEntity{
|
|||
GameRegistry.registerTileEntity(TileEntityEnergizer.class, ModUtil.MOD_ID_LOWER + ":tileEntityEnergizer");
|
||||
GameRegistry.registerTileEntity(TileEntityEnervator.class, ModUtil.MOD_ID_LOWER + ":tileEntityEnervator");
|
||||
GameRegistry.registerTileEntity(TileEntityXPSolidifier.class, ModUtil.MOD_ID_LOWER+":tileEntityXPSolidifier");
|
||||
GameRegistry.registerTileEntity(TileEntityOreMagnet.class, ModUtil.MOD_ID_LOWER+":tileEntityOreMagnet");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,177 @@
|
|||
package ellpeck.actuallyadditions.tile;
|
||||
|
||||
import cofh.api.energy.EnergyStorage;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import ellpeck.actuallyadditions.blocks.InitBlocks;
|
||||
import ellpeck.actuallyadditions.network.sync.IPacketSyncerToClient;
|
||||
import ellpeck.actuallyadditions.network.sync.PacketSyncerToClient;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.*;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class TileEntityOreMagnet extends TileEntityInventoryBase implements IEnergyReceiver, IFluidHandler, IPacketSyncerToClient{
|
||||
|
||||
public EnergyStorage storage = new EnergyStorage(40000);
|
||||
public FluidTank tank = new FluidTank(8*FluidContainerRegistry.BUCKET_VOLUME);
|
||||
private int currentWorkTimer;
|
||||
|
||||
private static final int MAX_WORK_TIMER = 30;
|
||||
private static final int RANGE = 5;
|
||||
|
||||
public TileEntityOreMagnet(){
|
||||
super(3, "oreMagnet");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void updateEntity(){
|
||||
if(!worldObj.isRemote){
|
||||
|
||||
if(this.currentWorkTimer > 0){
|
||||
currentWorkTimer--;
|
||||
|
||||
if(currentWorkTimer <= 0){
|
||||
int x = MathHelper.getRandomIntegerInRange(worldObj.rand, -RANGE, RANGE);
|
||||
int z = MathHelper.getRandomIntegerInRange(worldObj.rand, -RANGE, RANGE);
|
||||
//Can the block at the top be replaced?
|
||||
for(int toPlaceY = 0; toPlaceY < 5; toPlaceY++){
|
||||
if(worldObj.isAirBlock(xCoord+x, yCoord+toPlaceY, zCoord+z) || worldObj.getBlock(xCoord+x, yCoord+toPlaceY, zCoord+z).isReplaceable(worldObj, xCoord+x, yCoord+toPlaceY, zCoord+z)){
|
||||
//Find the first available block
|
||||
for(int y = this.yCoord-1; y > 0; y--){
|
||||
Block block = worldObj.getBlock(xCoord+x, y, zCoord+z);
|
||||
int meta = worldObj.getBlockMetadata(xCoord+x, y, zCoord+z);
|
||||
|
||||
int[] oreIDs = OreDictionary.getOreIDs(new ItemStack(block, 1, meta));
|
||||
for(int ID : oreIDs){
|
||||
String oreName = OreDictionary.getOreName(ID);
|
||||
//Is the block an ore according to the OreDictionary?
|
||||
if(oreName.substring(0, 3).equals("ore")){
|
||||
//Remove the Block
|
||||
worldObj.setBlockToAir(xCoord+x, y, zCoord+z);
|
||||
worldObj.playAuxSFX(2001, xCoord+x, y, zCoord+z, Block.getIdFromBlock(block)+(meta << 12));
|
||||
|
||||
//Set the Block at the Top again
|
||||
worldObj.setBlock(xCoord+x, yCoord+toPlaceY, zCoord+z, block, meta, 2);
|
||||
worldObj.playSoundEffect((double)xCoord+x+0.5D, (double)yCoord+toPlaceY+0.5D, (double)zCoord+z+0.5D, block.stepSound.func_150496_b(), (block.stepSound.getVolume()+1.0F)/2.0F, block.stepSound.getPitch()*0.8F);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else this.currentWorkTimer = MathHelper.getRandomIntegerInRange(worldObj.rand, MAX_WORK_TIMER, MAX_WORK_TIMER*5);
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getEnergyScaled(int i){
|
||||
return this.storage.getEnergyStored()*i/this.storage.getMaxEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound compound){
|
||||
this.storage.writeToNBT(compound);
|
||||
this.tank.writeToNBT(compound);
|
||||
super.writeToNBT(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound compound){
|
||||
this.storage.readFromNBT(compound);
|
||||
this.tank.readFromNBT(compound);
|
||||
super.readFromNBT(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack stack){
|
||||
return false;
|
||||
//TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int slot, ItemStack stack, int side){
|
||||
return this.isItemValidForSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int slot, ItemStack stack, int side){
|
||||
return false;
|
||||
//TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate){
|
||||
return this.storage.receiveEnergy(maxReceive, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from){
|
||||
return this.storage.getEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from){
|
||||
return this.storage.getMaxEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectEnergy(ForgeDirection from){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill){
|
||||
if(resource.getFluid() == InitBlocks.fluidOil) return this.tank.fill(resource, doFill);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain){
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain){
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid){
|
||||
return from != ForgeDirection.DOWN && fluid == InitBlocks.fluidOil;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from){
|
||||
return new FluidTankInfo[]{this.tank.getInfo()};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getValues(){
|
||||
//TODO
|
||||
return new int[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValues(int[] values){
|
||||
//TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendUpdate(){
|
||||
PacketSyncerToClient.sendPacket(this);
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
Loading…
Reference in a new issue