Доброго времени суток.
Есть блок портала с метадатой:
Есть блок портала с метадатой:
Код:
public class Portals extends MetaDataBlock {
public Portals(int id, String unlocalizedName, String[] subNames, Material material, StepSound step, float hardness) {
super(id, unlocalizedName, subNames, material, step, hardness);
setHardness(-1.0F);
setResistance(6000000.0F);
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) {
float f = 0.0625F;
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, f, 1.0F);
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
if ((entity.ridingEntity == null) && (entity.riddenByEntity == null) && ((entity instanceof EntityPlayerMP))) {
EntityPlayerMP player = (EntityPlayerMP)entity;
switch(world.getBlockMetadata((int)player.posX, (int)player.posY, (int)player.posZ)) {
case 0: if(world.provider.dimensionId != 0) { player.mcServer.getConfigurationManager().transferPlayerToDimension(player, 0, new CustomTeleporter(player.mcServer.worldServerForDimension(0))); } break;
case 1: if(world.provider.dimensionId != DimsList.MineDimID) { player.mcServer.getConfigurationManager().transferPlayerToDimension(player, DimsList.MineDimID, new CustomTeleporter(player.mcServer.worldServerForDimension(DimsList.MineDimID))); } break;
case 2: if(world.provider.dimensionId != DimsList.DungeonDimID) { player.mcServer.getConfigurationManager().transferPlayerToDimension(player, DimsList.DungeonDimID, new CustomTeleporter(player.mcServer.worldServerForDimension(DimsList.DungeonDimID))); } break;
}
}
}
}
Код:
public class MetaDataBlock extends MainBlock {
private Icon[] icons;
private String[] subNames;
public MetaDataBlock(int id, String unlocalizedName, String[] subNames, Material material, StepSound step, float hardness) {
super(id, unlocalizedName, MetaDataPortalsBlock.class, material, step, hardness);
icons = new Icon[subNames.length];
this.subNames = subNames;
}
@Override
public int damageDropped(int par1) {
return par1;
}
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister reg) {
for(int i = 0; i < subNames.length; i++) {
icons[i] = reg.registerIcon(ModInfo.MOD_ID + ":" + getUnlocalizedName().substring(13) + "_" + subNames[i]);
}
}
@SideOnly(Side.CLIENT)
public Icon getIcon(int id, int meta) {
return icons[meta];
}
@SideOnly(Side.CLIENT)
public void getSubBlocks(int id, CreativeTabs par2CreativeTabs, List par3List) {
for (int i = 0; i < subNames.length; i++) {
par3List.add(new ItemStack(id, 1, i));
}
}
public String[] getSubNames() {
return subNames;
}
}