2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("BlockPhantom.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-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
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
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.tile.*;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
2016-07-04 20:15:41 +02:00
|
|
|
import net.minecraft.block.Block;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.block.SoundType;
|
2015-04-26 20:07:57 +02:00
|
|
|
import net.minecraft.block.material.Material;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
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.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;
|
2016-05-02 17:12:31 +02:00
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.EnumHand;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
|
|
|
import net.minecraft.util.math.Vec3d;
|
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2016-05-05 17:29:39 +02:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
2015-04-26 20:07:57 +02:00
|
|
|
import net.minecraft.world.World;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-04-26 20:07:57 +02:00
|
|
|
|
2015-12-21 22:18:33 +01:00
|
|
|
public class BlockPhantom extends BlockContainerBase implements IHudDisplay{
|
2015-04-26 20:07:57 +02:00
|
|
|
|
2016-05-19 20:05:12 +02:00
|
|
|
public final Type type;
|
2015-10-03 10:19:40 +02:00
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
public BlockPhantom(Type type, String name){
|
2016-04-20 21:39:03 +02:00
|
|
|
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);
|
2016-04-20 21:39:03 +02:00
|
|
|
this.setSoundType(SoundType.STONE);
|
2015-04-26 20:07:57 +02:00
|
|
|
}
|
|
|
|
|
2016-05-05 17:29:39 +02:00
|
|
|
@Override
|
|
|
|
public boolean canProvidePower(IBlockState state){
|
|
|
|
return this.type == Type.REDSTONEFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getWeakPower(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side){
|
|
|
|
if(this.type == Type.REDSTONEFACE){
|
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
if(tile instanceof TileEntityPhantomRedstoneface){
|
|
|
|
return ((TileEntityPhantomRedstoneface)tile).providesWeak[side.ordinal()];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.getWeakPower(state, world, pos, side);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getStrongPower(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side){
|
|
|
|
if(this.type == Type.REDSTONEFACE){
|
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
if(tile instanceof TileEntityPhantomRedstoneface){
|
|
|
|
return ((TileEntityPhantomRedstoneface)tile).providesStrong[side.ordinal()];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.getStrongPower(state, world, pos, side);
|
|
|
|
}
|
|
|
|
|
2015-05-25 17:00:54 +02:00
|
|
|
@Override
|
2016-05-29 23:49:35 +02:00
|
|
|
public void breakBlock(World world, BlockPos pos, IBlockState state){
|
2015-10-03 10:16:18 +02:00
|
|
|
if(this.type == Type.PLACER || this.type == Type.BREAKER){
|
2016-01-08 13:31:58 +01:00
|
|
|
this.dropInventory(world, pos);
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
2016-01-07 18:20:59 +01:00
|
|
|
super.breakBlock(world, pos, state);
|
2015-05-25 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
2016-05-29 23:49:35 +02:00
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
@Override
|
2016-05-29 23:49:35 +02:00
|
|
|
public TileEntity createNewTileEntity(World world, int par2){
|
2015-10-03 10:19:40 +02:00
|
|
|
switch(this.type){
|
|
|
|
case PLACER:
|
|
|
|
return new TileEntityPhantomPlacer();
|
|
|
|
case BREAKER:
|
2016-05-14 17:50:10 +02:00
|
|
|
return new TileEntityPhantomBreaker();
|
2015-10-03 10:19:40 +02:00
|
|
|
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();
|
2016-05-05 17:29:39 +02:00
|
|
|
case REDSTONEFACE:
|
|
|
|
return new TileEntityPhantomRedstoneface();
|
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
|
2016-03-18 23:47:22 +01:00
|
|
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ){
|
2016-01-08 13:31:58 +01:00
|
|
|
if(this.tryToggleRedstone(world, pos, player)){
|
2015-12-17 18:47:46 +01:00
|
|
|
return true;
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
if(!world.isRemote){
|
2016-01-07 19:04:29 +01:00
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
2015-12-21 22:18:33 +01:00
|
|
|
if(tile instanceof IPhantomTile && ((IPhantomTile)tile).getGuiID() != -1){
|
2016-01-07 19:04:29 +01:00
|
|
|
player.openGui(ActuallyAdditions.instance, ((IPhantomTile)tile).getGuiID(), world, pos.getX(), pos.getY(), pos.getZ());
|
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
|
|
|
}
|
|
|
|
|
2015-10-23 16:48:56 +02:00
|
|
|
@Override
|
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
2016-01-07 19:04:29 +01:00
|
|
|
return EnumRarity.EPIC;
|
2015-10-23 16:48:56 +02:00
|
|
|
}
|
|
|
|
|
2015-12-21 22:18:33 +01:00
|
|
|
@Override
|
2015-12-21 22:22:02 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2016-03-18 23:47:22 +01:00
|
|
|
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, Profiler profiler, ScaledResolution resolution){
|
2016-01-07 19:04:29 +01:00
|
|
|
TileEntity tile = minecraft.theWorld.getTileEntity(posHit.getBlockPos());
|
2015-12-21 22:18:33 +01:00
|
|
|
if(tile != null){
|
|
|
|
if(tile instanceof IPhantomTile){
|
|
|
|
IPhantomTile phantom = (IPhantomTile)tile;
|
2016-04-20 21:39:03 +02:00
|
|
|
minecraft.fontRendererObj.drawStringWithShadow(TextFormatting.GOLD+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".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()){
|
2016-03-18 23:47:22 +01:00
|
|
|
int distance = (int)new Vec3d(posHit.getBlockPos()).distanceTo(new Vec3d(phantom.getBoundPosition()));
|
2016-07-04 20:15:41 +02:00
|
|
|
IBlockState state = minecraft.theWorld.getBlockState(phantom.getBoundPosition());
|
|
|
|
Block block = state.getBlock();
|
|
|
|
Item item = Item.getItemFromBlock(block);
|
|
|
|
String name = item == null ? "Absolutely Nothing" : item.getItemStackDisplayName(new ItemStack(block, 1, block.getMetaFromState(state)));
|
2016-04-20 21:39:03 +02:00
|
|
|
StringUtil.drawSplitString(minecraft.fontRendererObj, StringUtil.localizeFormatted("tooltip."+ModUtil.MOD_ID+".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()){
|
2016-04-20 21:39:03 +02:00
|
|
|
StringUtil.drawSplitString(minecraft.fontRendererObj, TextFormatting.DARK_GREEN+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".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{
|
2016-04-20 21:39:03 +02:00
|
|
|
StringUtil.drawSplitString(minecraft.fontRendererObj, TextFormatting.DARK_RED+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".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{
|
2016-04-20 21:39:03 +02:00
|
|
|
minecraft.fontRendererObj.drawStringWithShadow(TextFormatting.RED+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".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,
|
2016-05-05 17:29:39 +02:00
|
|
|
ENERGYFACE,
|
|
|
|
REDSTONEFACE
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
2015-05-27 21:57:53 +02:00
|
|
|
}
|