2015-08-29 14:33:25 +02:00
|
|
|
/*
|
|
|
|
* This file ("BlockPhantom.java") is part of the Actually Additions Mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-01-03 16:05:51 +01:00
|
|
|
* http://ellpeck.de/actaddlicense/
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-01-03 16:05:51 +01:00
|
|
|
* © 2016 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.blocks;
|
2015-04-26 20:07:57 +02:00
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.block.IHudDisplay;
|
|
|
|
import de.ellpeck.actuallyadditions.api.tile.IPhantomTile;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.proxy.ClientProxy;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.*;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
2015-04-26 20:07:57 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.material.Material;
|
2015-12-21 22:18:33 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.ScaledResolution;
|
2015-04-26 20:07:57 +02:00
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.EnumRarity;
|
2015-07-31 11:50:43 +02:00
|
|
|
import net.minecraft.item.Item;
|
2015-04-26 20:07:57 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2015-12-21 22:18:33 +01:00
|
|
|
import net.minecraft.profiler.Profiler;
|
2015-04-26 20:07:57 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2015-12-21 22:18:33 +01:00
|
|
|
import net.minecraft.util.EnumChatFormatting;
|
2015-04-26 20:07:57 +02:00
|
|
|
import net.minecraft.util.IIcon;
|
2015-12-21 22:18:33 +01:00
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
2015-07-07 20:20:24 +02:00
|
|
|
import net.minecraft.util.Vec3;
|
2015-04-26 20:07:57 +02:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2015-12-21 22:18:33 +01:00
|
|
|
public class BlockPhantom extends BlockContainerBase implements IHudDisplay{
|
2015-04-26 20:07:57 +02:00
|
|
|
|
2015-08-10 22:55:34 +02:00
|
|
|
public Type type;
|
2015-06-06 01:25:53 +02:00
|
|
|
public int range;
|
2015-10-03 10:19:40 +02:00
|
|
|
|
2015-10-28 14:46:04 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2015-10-18 19:56:18 +02:00
|
|
|
private IIcon iconSeasonal;
|
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
public BlockPhantom(Type type, String name){
|
|
|
|
super(Material.rock, name);
|
2015-05-25 17:00:54 +02:00
|
|
|
this.type = type;
|
2015-05-20 22:39:43 +02:00
|
|
|
this.setHarvestLevel("pickaxe", 0);
|
2015-07-07 01:13:39 +02:00
|
|
|
this.setHardness(4.5F);
|
|
|
|
this.setResistance(10.0F);
|
2015-05-20 22:39:43 +02:00
|
|
|
this.setStepSound(soundTypeStone);
|
2015-06-06 01:25:53 +02:00
|
|
|
|
2015-08-10 22:55:34 +02:00
|
|
|
if(type == Type.FACE || type == Type.LIQUIFACE || type == Type.ENERGYFACE){
|
2015-11-28 19:02:01 +01:00
|
|
|
this.range = TileEntityPhantomface.RANGE;
|
2015-08-10 10:37:44 +02:00
|
|
|
}
|
2015-08-10 22:55:34 +02:00
|
|
|
else if(type == Type.BREAKER || type == Type.PLACER){
|
2015-11-28 19:02:01 +01:00
|
|
|
this.range = TileEntityPhantomPlacer.RANGE;
|
2015-08-10 10:37:44 +02:00
|
|
|
}
|
2015-04-26 20:07:57 +02:00
|
|
|
}
|
|
|
|
|
2015-05-25 17:00:54 +02:00
|
|
|
@Override
|
|
|
|
public void breakBlock(World world, int x, int y, int z, Block block, int par6){
|
2015-10-03 10:16:18 +02:00
|
|
|
if(this.type == Type.PLACER || this.type == Type.BREAKER){
|
|
|
|
this.dropInventory(world, x, y, z);
|
|
|
|
}
|
2015-05-25 17:00:54 +02:00
|
|
|
super.breakBlock(world, x, y, z, block, par6);
|
|
|
|
}
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
@Override
|
|
|
|
public TileEntity createNewTileEntity(World world, int par2){
|
|
|
|
switch(this.type){
|
|
|
|
case PLACER:
|
|
|
|
return new TileEntityPhantomPlacer();
|
|
|
|
case BREAKER:
|
|
|
|
return new TileEntityPhantomPlacer.TileEntityPhantomBreaker();
|
|
|
|
case LIQUIFACE:
|
2015-10-10 02:58:07 +02:00
|
|
|
return new TileEntityPhantomLiquiface();
|
2015-10-03 10:19:40 +02:00
|
|
|
case ENERGYFACE:
|
2015-10-10 02:58:07 +02:00
|
|
|
return new TileEntityPhantomEnergyface();
|
2015-10-03 10:19:40 +02:00
|
|
|
default:
|
2015-10-10 02:58:07 +02:00
|
|
|
return new TileEntityPhantomItemface();
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-28 14:46:04 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2015-10-03 10:19:40 +02:00
|
|
|
public IIcon getIcon(int side, int metadata){
|
2015-10-18 19:56:18 +02:00
|
|
|
return (this.type == Type.FACE && ClientProxy.pumpkinBlurPumpkinBlur && side > 1) ? this.iconSeasonal : this.blockIcon;
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
|
2015-04-26 20:07:57 +02:00
|
|
|
@Override
|
2015-05-20 22:39:43 +02:00
|
|
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int hitSide, float hitX, float hitY, float hitZ){
|
2015-12-17 18:47:46 +01:00
|
|
|
if(this.tryToggleRedstone(world, x, y, z, player)){
|
|
|
|
return true;
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
if(!world.isRemote){
|
2015-05-25 17:00:54 +02:00
|
|
|
TileEntity tile = world.getTileEntity(x, y, z);
|
2015-12-21 22:18:33 +01:00
|
|
|
if(tile instanceof IPhantomTile && ((IPhantomTile)tile).getGuiID() != -1){
|
|
|
|
player.openGui(ActuallyAdditions.instance, ((IPhantomTile)tile).getGuiID(), world, x, y, z);
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-25 17:00:54 +02:00
|
|
|
return true;
|
2015-04-26 20:07:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-05-20 22:39:43 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void registerBlockIcons(IIconRegister iconReg){
|
2015-12-03 20:15:07 +01:00
|
|
|
this.blockIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getBaseName());
|
2015-10-18 19:56:18 +02:00
|
|
|
|
|
|
|
this.iconSeasonal = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":blockPhantomfacePumpkin");
|
2015-04-26 20:07:57 +02:00
|
|
|
}
|
|
|
|
|
2015-10-23 16:48:56 +02:00
|
|
|
@Override
|
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
|
|
|
return EnumRarity.epic;
|
|
|
|
}
|
|
|
|
|
2015-12-21 22:18:33 +01:00
|
|
|
@Override
|
2015-12-21 22:22:02 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2015-12-21 22:18:33 +01:00
|
|
|
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, MovingObjectPosition posHit, Profiler profiler, ScaledResolution resolution){
|
|
|
|
TileEntity tile = minecraft.theWorld.getTileEntity(posHit.blockX, posHit.blockY, posHit.blockZ);
|
|
|
|
if(tile != null){
|
|
|
|
if(tile instanceof IPhantomTile){
|
|
|
|
IPhantomTile phantom = (IPhantomTile)tile;
|
2015-12-21 23:40:19 +01:00
|
|
|
minecraft.fontRenderer.drawStringWithShadow(EnumChatFormatting.GOLD+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".blockPhantomRange.desc")+": "+phantom.getRange(), resolution.getScaledWidth()/2+5, resolution.getScaledHeight()/2-40, StringUtil.DECIMAL_COLOR_WHITE);
|
2015-12-21 22:18:33 +01:00
|
|
|
if(phantom.hasBoundPosition()){
|
|
|
|
int distance = (int)Vec3.createVectorHelper(posHit.blockX, posHit.blockY, posHit.blockZ).distanceTo(Vec3.createVectorHelper(phantom.getBoundPosition().getX(), phantom.getBoundPosition().getY(), phantom.getBoundPosition().getZ()));
|
2015-12-23 01:43:49 +01:00
|
|
|
Item item = phantom.getBoundPosition().getItemBlock(minecraft.theWorld);
|
|
|
|
String name = item == null ? "Absolutely Nothing" : item.getItemStackDisplayName(new ItemStack(phantom.getBoundPosition().getBlock(minecraft.theWorld), 1, phantom.getBoundPosition().getMetadata(minecraft.theWorld)));
|
2015-12-23 20:42:20 +01:00
|
|
|
StringUtil.drawSplitString(minecraft.fontRenderer, StringUtil.localizeFormatted("tooltip."+ModUtil.MOD_ID_LOWER+".phantom.blockInfo.desc", name, phantom.getBoundPosition().getX(), phantom.getBoundPosition().getY(), phantom.getBoundPosition().getZ(), distance), resolution.getScaledWidth()/2+5, resolution.getScaledHeight()/2-30, 200, StringUtil.DECIMAL_COLOR_WHITE, true);
|
2015-12-21 22:18:33 +01:00
|
|
|
|
|
|
|
if(phantom.isBoundThingInRange()){
|
2015-12-23 20:42:20 +01:00
|
|
|
StringUtil.drawSplitString(minecraft.fontRenderer, EnumChatFormatting.DARK_GREEN+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".phantom.connectedRange.desc"), resolution.getScaledWidth()/2+5, resolution.getScaledHeight()/2+25, 200, StringUtil.DECIMAL_COLOR_WHITE, true);
|
2015-12-21 22:18:33 +01:00
|
|
|
}
|
|
|
|
else{
|
2015-12-23 20:42:20 +01:00
|
|
|
StringUtil.drawSplitString(minecraft.fontRenderer, EnumChatFormatting.DARK_RED+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".phantom.connectedNoRange.desc"), resolution.getScaledWidth()/2+5, resolution.getScaledHeight()/2+25, 200, StringUtil.DECIMAL_COLOR_WHITE, true);
|
2015-12-21 22:18:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2015-12-22 14:55:10 +01:00
|
|
|
minecraft.fontRenderer.drawStringWithShadow(EnumChatFormatting.RED+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".phantom.notConnected.desc"), resolution.getScaledWidth()/2+5, resolution.getScaledHeight()/2+25, StringUtil.DECIMAL_COLOR_WHITE);
|
2015-12-21 22:18:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-03 10:16:18 +02:00
|
|
|
public enum Type{
|
|
|
|
FACE,
|
|
|
|
PLACER,
|
|
|
|
BREAKER,
|
|
|
|
LIQUIFACE,
|
|
|
|
ENERGYFACE
|
|
|
|
}
|
2015-05-27 21:57:53 +02:00
|
|
|
}
|