2015-11-18 21:59:08 +01:00
|
|
|
package techreborn.blocks;
|
|
|
|
|
2016-05-23 18:22:50 +02:00
|
|
|
import com.google.common.collect.Lists;
|
2016-01-22 14:39:20 +01:00
|
|
|
import me.modmuss50.jsonDestroyer.api.ITexturedBlock;
|
2016-03-13 17:08:30 +01:00
|
|
|
import net.minecraft.block.state.BlockStateContainer;
|
2015-11-23 20:51:40 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2015-11-18 21:59:08 +01:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2015-11-22 12:16:54 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-11-18 21:59:08 +01:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2015-11-22 12:16:54 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-03-15 09:13:05 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-13 18:38:12 +01:00
|
|
|
import net.minecraft.util.EnumHand;
|
2016-11-19 15:41:00 +01:00
|
|
|
import net.minecraft.util.NonNullList;
|
2016-03-13 17:08:30 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.text.TextComponentString;
|
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2016-05-22 06:51:26 +02:00
|
|
|
import net.minecraft.util.text.translation.I18n;
|
2015-11-22 12:16:54 +01:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
2015-11-18 21:59:08 +01:00
|
|
|
import net.minecraft.world.World;
|
2015-11-23 20:19:18 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2016-03-23 21:00:00 +01:00
|
|
|
import reborncore.common.blocks.BlockMachineBase;
|
2016-05-23 18:22:50 +02:00
|
|
|
import reborncore.common.blocks.PropertyString;
|
|
|
|
import reborncore.common.util.ArrayUtils;
|
2016-05-22 06:51:26 +02:00
|
|
|
import reborncore.common.util.ChatUtils;
|
2016-05-23 18:22:50 +02:00
|
|
|
import reborncore.common.util.StringUtils;
|
2015-11-18 21:59:08 +01:00
|
|
|
import techreborn.client.TechRebornCreativeTab;
|
2016-05-22 06:51:26 +02:00
|
|
|
import techreborn.lib.MessageIDs;
|
2015-11-22 12:16:54 +01:00
|
|
|
import techreborn.tiles.TilePlayerDectector;
|
2015-11-18 21:59:08 +01:00
|
|
|
|
2016-05-22 06:51:26 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public class BlockPlayerDetector extends BlockMachineBase implements ITexturedBlock {
|
2016-03-25 10:47:34 +01:00
|
|
|
|
|
|
|
public static final String[] types = new String[] { "all", "others", "you" };
|
2016-05-23 18:22:50 +02:00
|
|
|
public PropertyString TYPE;
|
|
|
|
static List<String> typeNamesList = Lists.newArrayList(ArrayUtils.arrayToLowercase(types));
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public BlockPlayerDetector() {
|
2016-05-17 12:41:37 +02:00
|
|
|
super(true);
|
2016-03-25 10:47:34 +01:00
|
|
|
setUnlocalizedName("techreborn.playerDetector");
|
|
|
|
setCreativeTab(TechRebornCreativeTab.instance);
|
|
|
|
setHardness(2f);
|
2016-05-23 18:22:50 +02:00
|
|
|
this.setDefaultState(this.getDefaultState().withProperty(TYPE, "all"));
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return Item.getItemFromBlock(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2016-11-19 15:41:00 +01:00
|
|
|
public void getSubBlocks(Item item, CreativeTabs creativeTabs, NonNullList<ItemStack> list) {
|
2016-10-08 21:46:16 +02:00
|
|
|
for (int meta = 0; meta < types.length; meta++) {
|
2016-03-25 10:47:34 +01:00
|
|
|
list.add(new ItemStack(item, 1, meta));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return new TilePlayerDectector();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean canProvidePower(IBlockState state) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
|
2016-03-25 10:47:34 +01:00
|
|
|
TileEntity entity = blockAccess.getTileEntity(pos);
|
2016-10-08 21:46:16 +02:00
|
|
|
if (entity instanceof TilePlayerDectector) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return ((TilePlayerDectector) entity).isProvidingPower() ? 15 : 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public int getStrongPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
|
2016-03-25 10:47:34 +01:00
|
|
|
TileEntity entity = blockAccess.getTileEntity(pos);
|
2016-10-08 21:46:16 +02:00
|
|
|
if (entity instanceof TilePlayerDectector) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return ((TilePlayerDectector) entity).isProvidingPower() ? 15 : 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer,
|
2016-10-08 21:46:16 +02:00
|
|
|
ItemStack stack) {
|
2016-03-25 10:47:34 +01:00
|
|
|
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
|
|
|
|
TileEntity tile = worldIn.getTileEntity(pos);
|
2016-10-08 21:46:16 +02:00
|
|
|
if (tile instanceof TilePlayerDectector) {
|
2016-03-25 10:47:34 +01:00
|
|
|
((TilePlayerDectector) tile).owenerUdid = placer.getUniqueID().toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer entityPlayer,
|
2016-11-19 15:41:00 +01:00
|
|
|
EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
|
2016-05-23 18:22:50 +02:00
|
|
|
String type = state.getValue(TYPE);
|
2016-10-08 21:46:16 +02:00
|
|
|
String newType = type;
|
2016-05-23 18:22:50 +02:00
|
|
|
TextFormatting color = TextFormatting.GREEN;
|
2016-10-08 21:46:16 +02:00
|
|
|
if (type.equals("all")) {
|
2016-05-23 18:22:50 +02:00
|
|
|
newType = "others";
|
|
|
|
color = TextFormatting.RED;
|
2016-10-08 21:46:16 +02:00
|
|
|
} else if (type.equals("others")) {
|
2016-05-23 18:22:50 +02:00
|
|
|
newType = "you";
|
|
|
|
color = TextFormatting.BLUE;
|
2016-10-08 21:46:16 +02:00
|
|
|
} else if (type.equals("you")) {
|
2016-05-23 18:22:50 +02:00
|
|
|
newType = "all";
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
2016-05-23 18:22:50 +02:00
|
|
|
world.setBlockState(pos, state.withProperty(TYPE, newType));
|
2017-02-13 11:17:34 +01:00
|
|
|
if (world.isRemote) {
|
2016-05-22 06:51:26 +02:00
|
|
|
ChatUtils.sendNoSpamMessages(MessageIDs.playerDetectorID, new TextComponentString(
|
2016-10-08 21:46:16 +02:00
|
|
|
TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.detects") + " " + color
|
|
|
|
+ StringUtils.toFirstCapital(newType)));
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public String getTextureNameFromState(IBlockState blockState, EnumFacing facing) {
|
2016-11-28 13:54:44 +01:00
|
|
|
return "techreborn:blocks/machines/tier1_machines/player_detector_" + types[getMetaFromState(blockState)].toLowerCase();
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public int amountOfStates() {
|
2016-03-25 10:47:34 +01:00
|
|
|
return types.length;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
protected BlockStateContainer createBlockState() {
|
2016-05-23 18:22:50 +02:00
|
|
|
TYPE = new PropertyString("type", types);
|
|
|
|
return new BlockStateContainer(this, TYPE);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-23 18:22:50 +02:00
|
|
|
public IBlockState getStateFromMeta(int meta) {
|
2016-10-08 21:46:16 +02:00
|
|
|
if (meta > types.length) {
|
2016-05-23 18:22:50 +02:00
|
|
|
meta = 0;
|
|
|
|
}
|
|
|
|
return getBlockState().getBaseState().withProperty(TYPE, typeNamesList.get(meta));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMetaFromState(IBlockState state) {
|
|
|
|
return typeNamesList.indexOf(state.getValue(TYPE));
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
2015-11-18 21:59:08 +01:00
|
|
|
}
|