Fix player detectors
This commit is contained in:
parent
9fa5e560e1
commit
401093a70b
2 changed files with 34 additions and 31 deletions
|
@ -1,5 +1,6 @@
|
||||||
package techreborn.blocks;
|
package techreborn.blocks;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import me.modmuss50.jsonDestroyer.api.ITexturedBlock;
|
import me.modmuss50.jsonDestroyer.api.ITexturedBlock;
|
||||||
import net.minecraft.block.properties.PropertyInteger;
|
import net.minecraft.block.properties.PropertyInteger;
|
||||||
import net.minecraft.block.state.BlockStateContainer;
|
import net.minecraft.block.state.BlockStateContainer;
|
||||||
|
@ -21,7 +22,10 @@ import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
import reborncore.common.blocks.BlockMachineBase;
|
import reborncore.common.blocks.BlockMachineBase;
|
||||||
|
import reborncore.common.blocks.PropertyString;
|
||||||
|
import reborncore.common.util.ArrayUtils;
|
||||||
import reborncore.common.util.ChatUtils;
|
import reborncore.common.util.ChatUtils;
|
||||||
|
import reborncore.common.util.StringUtils;
|
||||||
import techreborn.client.TechRebornCreativeTab;
|
import techreborn.client.TechRebornCreativeTab;
|
||||||
import techreborn.lib.MessageIDs;
|
import techreborn.lib.MessageIDs;
|
||||||
import techreborn.tiles.TilePlayerDectector;
|
import techreborn.tiles.TilePlayerDectector;
|
||||||
|
@ -33,7 +37,8 @@ public class BlockPlayerDetector extends BlockMachineBase implements ITexturedBl
|
||||||
{
|
{
|
||||||
|
|
||||||
public static final String[] types = new String[] { "all", "others", "you" };
|
public static final String[] types = new String[] { "all", "others", "you" };
|
||||||
public PropertyInteger METADATA;
|
public PropertyString TYPE;
|
||||||
|
static List<String> typeNamesList = Lists.newArrayList(ArrayUtils.arrayToLowercase(types));
|
||||||
|
|
||||||
public BlockPlayerDetector()
|
public BlockPlayerDetector()
|
||||||
{
|
{
|
||||||
|
@ -41,7 +46,7 @@ public class BlockPlayerDetector extends BlockMachineBase implements ITexturedBl
|
||||||
setUnlocalizedName("techreborn.playerDetector");
|
setUnlocalizedName("techreborn.playerDetector");
|
||||||
setCreativeTab(TechRebornCreativeTab.instance);
|
setCreativeTab(TechRebornCreativeTab.instance);
|
||||||
setHardness(2f);
|
setHardness(2f);
|
||||||
this.setDefaultState(this.getDefaultState().withProperty(METADATA, 0));
|
this.setDefaultState(this.getDefaultState().withProperty(TYPE, "all"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -116,26 +121,23 @@ public class BlockPlayerDetector extends BlockMachineBase implements ITexturedBl
|
||||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer entityPlayer,
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer entityPlayer,
|
||||||
EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
|
EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
|
||||||
{
|
{
|
||||||
// int newMeta = (world.getBlockMetadata(x, y, z) + 1) % 3;
|
String type = state.getValue(TYPE);
|
||||||
int newMeta = getMetaFromState(state);
|
String newType = type;
|
||||||
String message = "";
|
TextFormatting color = TextFormatting.GREEN;
|
||||||
switch (newMeta)
|
if(type.equals("all")){
|
||||||
{
|
newType = "others";
|
||||||
case 0:
|
color = TextFormatting.RED;
|
||||||
message = TextFormatting.GREEN + I18n.translateToLocal("techreborn.message.allPlayers");
|
} else if(type.equals("others")){
|
||||||
break;
|
newType = "you";
|
||||||
case 1:
|
color = TextFormatting.BLUE;
|
||||||
message = TextFormatting.RED + I18n.translateToLocal("techreborn.message.onlyOtherPlayers");
|
}else if(type.equals("you")){
|
||||||
break;
|
newType = "all";
|
||||||
case 2:
|
|
||||||
message = TextFormatting.BLUE + I18n.translateToLocal("techreborn.message.onlyYou");
|
|
||||||
}
|
}
|
||||||
if (!world.isRemote)
|
world.setBlockState(pos, state.withProperty(TYPE, newType));
|
||||||
{
|
if (!world.isRemote) {
|
||||||
ChatUtils.sendNoSpamMessages(MessageIDs.playerDetectorID, new TextComponentString(
|
ChatUtils.sendNoSpamMessages(MessageIDs.playerDetectorID, new TextComponentString(
|
||||||
TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.detects") + " "
|
TextFormatting.GRAY + I18n.translateToLocal("techreborn.message.detects") + " " + color
|
||||||
+ message));
|
+ StringUtils.toFirstCapital(newType)));
|
||||||
// world.setBlockMetadataWithNotify(x, y, z, newMeta, 2);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -152,21 +154,23 @@ public class BlockPlayerDetector extends BlockMachineBase implements ITexturedBl
|
||||||
return types.length;
|
return types.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMetaFromState(IBlockState state)
|
|
||||||
{
|
|
||||||
return state.getValue(METADATA);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected BlockStateContainer createBlockState()
|
protected BlockStateContainer createBlockState()
|
||||||
{
|
{
|
||||||
METADATA = PropertyInteger.create("type", 0, types.length - 1);
|
TYPE = new PropertyString("type", types);
|
||||||
return new BlockStateContainer(this, METADATA);
|
return new BlockStateContainer(this, TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBlockState getStateFromMeta(int meta)
|
public IBlockState getStateFromMeta(int meta) {
|
||||||
{
|
if(meta > types.length){
|
||||||
return this.getDefaultState().withProperty(METADATA, meta);
|
meta = 0;
|
||||||
|
}
|
||||||
|
return getBlockState().getBaseState().withProperty(TYPE, typeNamesList.get(meta));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetaFromState(IBlockState state) {
|
||||||
|
return typeNamesList.indexOf(state.getValue(TYPE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ public class StackWIPHandler
|
||||||
wipBlocks.add(ModBlocks.MagicalAbsorber);
|
wipBlocks.add(ModBlocks.MagicalAbsorber);
|
||||||
wipBlocks.add(ModBlocks.ChunkLoader);
|
wipBlocks.add(ModBlocks.ChunkLoader);
|
||||||
wipBlocks.add(ModBlocks.ElectricCraftingTable);
|
wipBlocks.add(ModBlocks.ElectricCraftingTable);
|
||||||
wipBlocks.add(ModBlocks.playerDetector);
|
|
||||||
wipBlocks.add(ModBlocks.chargeBench);
|
wipBlocks.add(ModBlocks.chargeBench);
|
||||||
wipBlocks.add(ModBlocks.Magicenergeyconverter);
|
wipBlocks.add(ModBlocks.Magicenergeyconverter);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue