ActuallyAdditions/src/main/java/ellpeck/actuallyadditions/blocks/BlockPhantom.java

175 lines
6.8 KiB
Java
Raw Normal View History

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
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* <EFBFBD> 2015 Ellpeck
*/
2015-04-26 20:07:57 +02:00
package ellpeck.actuallyadditions.blocks;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
2015-05-25 17:00:54 +02:00
import ellpeck.actuallyadditions.ActuallyAdditions;
2015-06-06 01:25:53 +02:00
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
import ellpeck.actuallyadditions.tile.IPhantomTile;
2015-05-25 17:00:54 +02:00
import ellpeck.actuallyadditions.tile.TileEntityPhantomPlacer;
2015-05-20 22:39:43 +02:00
import ellpeck.actuallyadditions.tile.TileEntityPhantomface;
import ellpeck.actuallyadditions.util.IActAddItemOrBlock;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.StringUtil;
2015-04-26 20:07:57 +02:00
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.Item;
2015-04-26 20:07:57 +02:00
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
2015-05-20 22:39:43 +02:00
import net.minecraft.util.ChatComponentText;
2015-04-26 20:07:57 +02:00
import net.minecraft.util.IIcon;
import net.minecraft.util.Vec3;
2015-04-26 20:07:57 +02:00
import net.minecraft.world.World;
public class BlockPhantom extends BlockContainerBase implements IActAddItemOrBlock{
2015-04-26 20:07:57 +02:00
public Type type;
2015-06-06 01:25:53 +02:00
public int range;
2015-10-03 10:19:40 +02:00
public BlockPhantom(Type type){
2015-05-20 22:39:43 +02:00
super(Material.rock);
2015-05-25 17:00:54 +02:00
this.type = type;
2015-05-20 22:39:43 +02:00
this.setHarvestLevel("pickaxe", 0);
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
if(type == Type.FACE || type == Type.LIQUIFACE || type == Type.ENERGYFACE){
this.range = ConfigIntValues.PHANTOMFACE_RANGE.getValue();
}
else if(type == Type.BREAKER || type == Type.PLACER){
this.range = ConfigIntValues.PHANTOM_PLACER_RANGE.getValue();
}
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:
return new TileEntityPhantomface.TileEntityPhantomLiquiface();
case ENERGYFACE:
return new TileEntityPhantomface.TileEntityPhantomEnergyface();
default:
return new TileEntityPhantomface.TileEntityPhantomItemface();
}
}
@Override
public IIcon getIcon(int side, int metadata){
return this.blockIcon;
}
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){
if(!world.isRemote){
2015-05-25 17:00:54 +02:00
TileEntity tile = world.getTileEntity(x, y, z);
2015-05-20 22:39:43 +02:00
if(tile != null){
2015-08-12 14:47:13 +02:00
if(tile instanceof IPhantomTile){
IPhantomTile phantom = (IPhantomTile)tile;
if(player.isSneaking() || phantom.getGuiID() == -1){
2015-10-02 16:48:01 +02:00
player.addChatComponentMessage(new ChatComponentText(StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".blockPhantomRange.desc")+": "+phantom.getRange()));
2015-05-25 17:00:54 +02:00
if(phantom.hasBoundPosition()){
int distance = (int)Vec3.createVectorHelper(x, y, z).distanceTo(Vec3.createVectorHelper(phantom.getBoundPosition().getX(), phantom.getBoundPosition().getY(), phantom.getBoundPosition().getZ()));
Item item = phantom.getBoundPosition().getItemBlock();
String name = item == null ? "Absolutely Nothing" : item.getItemStackDisplayName(new ItemStack(phantom.getBoundPosition().getBlock(), 1, phantom.getBoundPosition().getMetadata()));
player.addChatComponentMessage(new ChatComponentText(StringUtil.localizeFormatted("tooltip."+ModUtil.MOD_ID_LOWER+".phantom.blockInfo.desc", name, phantom.getBoundPosition().getX(), phantom.getBoundPosition().getY(), phantom.getBoundPosition().getZ(), distance)));
2015-10-02 16:48:01 +02:00
if(phantom.isBoundThingInRange()){
player.addChatComponentMessage(new ChatComponentText(StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".phantom.connectedRange.desc")));
}
else{
player.addChatComponentMessage(new ChatComponentText(StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".phantom.connectedNoRange.desc")));
}
2015-05-25 17:00:54 +02:00
}
2015-10-02 16:48:01 +02:00
else{
player.addChatComponentMessage(new ChatComponentText(StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".phantom.notConnected.desc")));
}
}
else{
player.openGui(ActuallyAdditions.instance, phantom.getGuiID(), world, x, y, z);
2015-05-25 17:00:54 +02:00
}
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-10-02 16:48:01 +02:00
this.blockIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName());
2015-04-26 20:07:57 +02:00
}
@Override
public String getName(){
2015-05-27 21:57:53 +02:00
switch(this.type){
case PLACER:
return "blockPhantomPlacer";
case BREAKER:
return "blockPhantomBreaker";
case LIQUIFACE:
return "blockPhantomLiquiface";
case ENERGYFACE:
return "blockPhantomEnergyface";
2015-05-27 21:57:53 +02:00
default:
return "blockPhantomface";
}
2015-04-26 20:07:57 +02:00
}
2015-10-03 10:16:18 +02:00
public enum Type{
FACE,
PLACER,
BREAKER,
LIQUIFACE,
ENERGYFACE
}
2015-04-26 20:07:57 +02:00
public static class TheItemBlock extends ItemBlock{
public TheItemBlock(Block block){
super(block);
this.setHasSubtypes(false);
this.setMaxDamage(0);
}
@Override
public String getUnlocalizedName(ItemStack stack){
return this.getUnlocalizedName();
}
@Override
public int getMetadata(int damage){
return damage;
}
2015-10-03 10:19:40 +02:00
@Override
public EnumRarity getRarity(ItemStack stack){
return EnumRarity.epic;
}
2015-04-26 20:07:57 +02:00
}
2015-05-27 21:57:53 +02:00
}