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

148 lines
7.2 KiB
Java
Raw Normal View History

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;
2019-05-02 09:10:29 +02:00
import de.ellpeck.actuallyadditions.mod.tile.TileEntityPhantomBreaker;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityPhantomEnergyface;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityPhantomItemface;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityPhantomLiquiface;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityPhantomPlacer;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityPhantomRedstoneface;
2016-01-05 04:47:35 +01:00
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;
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;
import net.minecraft.item.Item;
2015-04-26 20:07:57 +02:00
import net.minecraft.item.ItemStack;
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.MathHelper;
2016-03-18 23:47:22 +01:00
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
2019-05-02 09:10:29 +02: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
2019-05-02 09:10:29 +02: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);
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
2019-05-02 09:10:29 +02:00
public boolean canProvidePower(IBlockState state) {
2016-05-05 17:29:39 +02:00
return this.type == Type.REDSTONEFACE;
}
@Override
2019-05-02 09:10:29 +02:00
public int getWeakPower(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) {
if (this.type == Type.REDSTONEFACE) {
2016-05-05 17:29:39 +02:00
TileEntity tile = world.getTileEntity(pos);
2019-05-02 09:10:29 +02:00
if (tile instanceof TileEntityPhantomRedstoneface) { return ((TileEntityPhantomRedstoneface) tile).providesWeak[side.ordinal()]; }
2016-05-05 17:29:39 +02:00
}
return 0;
2016-05-05 17:29:39 +02:00
}
@Override
2019-05-02 09:10:29 +02:00
public int getStrongPower(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) {
if (this.type == Type.REDSTONEFACE) {
2016-05-05 17:29:39 +02:00
TileEntity tile = world.getTileEntity(pos);
2019-05-02 09:10:29 +02:00
if (tile instanceof TileEntityPhantomRedstoneface) { return ((TileEntityPhantomRedstoneface) tile).providesStrong[side.ordinal()]; }
2016-05-05 17:29:39 +02:00
}
return 0;
2016-05-05 17:29:39 +02:00
}
2015-05-25 17:00:54 +02:00
@Override
2019-05-02 09:10:29 +02:00
public boolean shouldDropInventory(World world, BlockPos pos) {
return this.type == Type.PLACER || this.type == Type.BREAKER;
2015-05-25 17:00:54 +02:00
}
2015-10-03 10:19:40 +02:00
@Override
2019-05-02 09:10:29 +02:00
public TileEntity createNewTileEntity(World world, int par2) {
switch (this.type) {
2019-02-27 19:53:05 +01:00
case PLACER:
return new TileEntityPhantomPlacer();
case BREAKER:
return new TileEntityPhantomBreaker();
case LIQUIFACE:
return new TileEntityPhantomLiquiface();
case ENERGYFACE:
return new TileEntityPhantomEnergyface();
case REDSTONEFACE:
return new TileEntityPhantomRedstoneface();
default:
return new TileEntityPhantomItemface();
2015-10-03 10:19:40 +02:00
}
}
@Override
2019-05-02 09:10:29 +02:00
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (this.tryToggleRedstone(world, pos, player)) { return true; }
if (!world.isRemote) {
TileEntity tile = world.getTileEntity(pos);
2019-05-02 09:10:29 +02:00
if (tile instanceof IPhantomTile && ((IPhantomTile) tile).getGuiID() != -1) {
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
}
@Override
2019-05-02 09:10:29 +02:00
public EnumRarity getRarity(ItemStack stack) {
return EnumRarity.EPIC;
}
@Override
2015-12-21 22:22:02 +01:00
@SideOnly(Side.CLIENT)
2019-05-02 09:10:29 +02:00
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution) {
2016-11-26 21:32:27 +01:00
TileEntity tile = minecraft.world.getTileEntity(posHit.getBlockPos());
2019-05-02 09:10:29 +02:00
if (tile != null) {
if (tile instanceof IPhantomTile) {
IPhantomTile phantom = (IPhantomTile) tile;
minecraft.fontRenderer.drawStringWithShadow(TextFormatting.GOLD + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".blockPhantomRange.desc") + ": " + phantom.getRange(), resolution.getScaledWidth() / 2 + 5, resolution.getScaledHeight() / 2 - 40, StringUtil.DECIMAL_COLOR_WHITE);
if (phantom.hasBoundPosition()) {
int distance = MathHelper.ceil(new Vec3d(posHit.getBlockPos()).distanceTo(new Vec3d(phantom.getBoundPosition())));
2016-11-26 21:32:27 +01:00
IBlockState state = minecraft.world.getBlockState(phantom.getBoundPosition());
2016-07-04 20:15:41 +02:00
Block block = state.getBlock();
Item item = Item.getItemFromBlock(block);
String name = item == null ? "Something Unrecognizable" : item.getItemStackDisplayName(new ItemStack(block, 1, block.getMetaFromState(state)));
2019-05-02 09:10:29 +02:00
StringUtil.drawSplitString(minecraft.fontRenderer, StringUtil.localizeFormatted("tooltip." + ActuallyAdditions.MODID + ".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);
2019-05-02 09:10:29 +02:00
if (phantom.isBoundThingInRange()) {
StringUtil.drawSplitString(minecraft.fontRenderer, TextFormatting.DARK_GREEN + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".phantom.connectedRange.desc"), resolution.getScaledWidth() / 2 + 5, resolution.getScaledHeight() / 2 + 25, 200, StringUtil.DECIMAL_COLOR_WHITE, true);
} else {
StringUtil.drawSplitString(minecraft.fontRenderer, TextFormatting.DARK_RED + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".phantom.connectedNoRange.desc"), resolution.getScaledWidth() / 2 + 5, resolution.getScaledHeight() / 2 + 25, 200, StringUtil.DECIMAL_COLOR_WHITE, true);
}
2019-05-02 09:10:29 +02:00
} else {
minecraft.fontRenderer.drawStringWithShadow(TextFormatting.RED + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".phantom.notConnected.desc"), resolution.getScaledWidth() / 2 + 5, resolution.getScaledHeight() / 2 + 25, StringUtil.DECIMAL_COLOR_WHITE);
}
}
}
}
2019-05-02 09:10:29 +02:00
public enum Type {
2015-10-03 10:16:18 +02:00
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
}